Some minor improvements

This commit is contained in:
Jan Oberhauser 2020-01-06 12:33:22 -06:00
parent 914483387d
commit b1237c756b
3 changed files with 25 additions and 26 deletions

View file

@ -14,7 +14,7 @@ export class BitbucketApi implements ICredentialType {
default: '',
},
{
displayName: 'APP Password',
displayName: 'App Password',
name: 'appPassword',
type: 'string' as NodePropertyTypes,
default: '',

View file

@ -4,12 +4,12 @@ import {
} from 'n8n-core';
import {
INodeTypeDescription,
INodeType,
IWebhookResponseData,
ILoadOptionsFunctions,
INodePropertyOptions,
IDataObject,
ILoadOptionsFunctions,
INodeType,
INodeTypeDescription,
INodePropertyOptions,
IWebhookResponseData,
} from 'n8n-workflow';
import {
@ -27,7 +27,7 @@ export class BitbucketTrigger implements INodeType {
description: 'Handle Bitbucket events via webhooks',
defaults: {
name: 'Bitbucket Trigger',
color: '#559922',
color: '#0052cc',
},
inputs: [],
outputs: ['main'],
@ -66,7 +66,7 @@ export class BitbucketTrigger implements INodeType {
},
],
default: 'user',
description: '',
description: 'The resource to operate on.',
},
{
displayName: 'Events',
@ -85,7 +85,7 @@ export class BitbucketTrigger implements INodeType {
options: [],
required: true,
default: [],
description: '',
description: 'The events to listen to.',
},
{
displayName: 'Team',
@ -103,7 +103,7 @@ export class BitbucketTrigger implements INodeType {
},
required: true,
default: '',
description: '',
description: 'The team of which to listen to the events.',
},
{
displayName: 'Events',
@ -122,7 +122,7 @@ export class BitbucketTrigger implements INodeType {
options: [],
required: true,
default: [],
description: '',
description: 'The events to listen to.',
},
{
displayName: 'Repository',
@ -140,7 +140,7 @@ export class BitbucketTrigger implements INodeType {
},
required: true,
default: '',
description: '',
description: 'The repository of which to listen to the events.',
},
{
displayName: 'Events',
@ -159,7 +159,7 @@ export class BitbucketTrigger implements INodeType {
options: [],
required: true,
default: [],
description: '',
description: 'The events to listen to.',
},
],
@ -260,7 +260,7 @@ export class BitbucketTrigger implements INodeType {
webhookMethods = {
default: {
async checkExists(this: IHookFunctions): Promise<boolean> {
let endpoint: string = '';
let endpoint = '';
const credentials = this.getCredentials('bitbucketApi');
const resource = this.getNodeParameter('resource', 0) as string;
const webhookData = this.getWorkflowStaticData('node');
@ -287,7 +287,7 @@ export class BitbucketTrigger implements INodeType {
},
async create(this: IHookFunctions): Promise<boolean> {
let responseData;
let endpoint: string = '';
let endpoint = '';
const webhookUrl = this.getNodeWebhookUrl('default');
const webhookData = this.getWorkflowStaticData('node');
const events = this.getNodeParameter('events') as string[];
@ -306,7 +306,7 @@ export class BitbucketTrigger implements INodeType {
endpoint = `/repositories/${credentials!.username}/${repository}/hooks`;
}
const body: IDataObject = {
description: 'N8N webhook',
description: 'n8n webhook',
url: webhookUrl,
active: true,
events,
@ -316,7 +316,7 @@ export class BitbucketTrigger implements INodeType {
return true;
},
async delete(this: IHookFunctions): Promise<boolean> {
let endpoint: string = '';
let endpoint = '';
const webhookData = this.getWorkflowStaticData('node');
const credentials = this.getCredentials('bitbucketApi');
const resource = this.getNodeParameter('resource', 0) as string;

View file

@ -1,9 +1,9 @@
import { OptionsWithUri } from 'request';
import {
IExecuteFunctions,
IExecuteSingleFunctions,
IHookFunctions,
ILoadOptionsFunctions,
IExecuteSingleFunctions,
} from 'n8n-core';
import { IDataObject } from 'n8n-workflow';
@ -12,12 +12,15 @@ export async function bitbucketApiRequest(this: IHookFunctions | IExecuteFunctio
if (credentials === undefined) {
throw new Error('No credentials got returned!');
}
const userpass = `${credentials.username}:${credentials.appPassword}`
let options: OptionsWithUri = {
method,
auth: {
user: credentials.username as string,
password: credentials.appPassword as string,
},
qs,
body,
uri: uri ||`https://${userpass}@api.bitbucket.org/2.0${resource}`,
uri: uri ||`https://api.bitbucket.org/2.0${resource}`,
json: true
};
options = Object.assign({}, options, option);
@ -28,11 +31,7 @@ export async function bitbucketApiRequest(this: IHookFunctions | IExecuteFunctio
try {
return await this.helpers.request!(options);
} catch (err) {
let errorMessage = '';
if (err.error && err.error.message) {
errorMessage = err.error.message;
}
throw new Error(errorMessage);
throw new Error('Bitbucket Error: ' + err.message);
}
}
@ -50,7 +49,7 @@ export async function bitbucketApiRequestAllItems(this: IHookFunctions | IExecut
do {
responseData = await bitbucketApiRequest.call(this, method, resource, body, query, uri);
uri = responseData.next
uri = responseData.next;
returnData.push.apply(returnData, responseData[propertyName]);
} while (
responseData.next !== undefined