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: '', default: '',
}, },
{ {
displayName: 'APP Password', displayName: 'App Password',
name: 'appPassword', name: 'appPassword',
type: 'string' as NodePropertyTypes, type: 'string' as NodePropertyTypes,
default: '', default: '',

View file

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

View file

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