:sparkles Add Event Filter in Taiga trigger node (#2011)

*  Filter events by action and type

*  Small change

*  Improvements

*  Minor improvements

Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Iván Ovejero 2021-07-22 08:10:26 +02:00 committed by GitHub
parent cc56b28538
commit 073e5e24cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 97 additions and 12 deletions

View file

@ -63,6 +63,70 @@ export class TaigaTrigger implements INodeType {
description: 'Project ID', description: 'Project ID',
required: true, required: true,
}, },
{
displayName: 'Resources',
name: 'resources',
type: 'multiOptions',
required: true,
default: [
'all',
],
options: [
{
name: 'All',
value: 'all',
},
{
name: 'Issue',
value: 'issue',
},
{
name: 'Milestone (Sprint)',
value: 'milestone',
},
{
name: 'Task',
value: 'task',
},
{
name: 'User Story',
value: 'userstory',
},
{
name: 'Wikipage',
value: 'wikipage',
},
],
description: 'Resources to listen to',
},
{
displayName: 'Operations',
name: 'operations',
type: 'multiOptions',
required: true,
default: [
'all',
],
description: 'Operations to listen to',
options: [
{
name: 'All',
value: 'all',
},
{
name: 'Create',
value: 'create',
},
{
name: 'Delete',
value: 'delete',
},
{
name: 'Update',
value: 'change',
},
],
},
], ],
}; };
@ -125,7 +189,7 @@ export class TaigaTrigger implements INodeType {
const body: IDataObject = { const body: IDataObject = {
name: `n8n-webhook:${webhookUrl}`, name: `n8n-webhook:${webhookUrl}`,
url: webhookUrl, url: webhookUrl,
key, //can't validate the secret, see: https://github.com/taigaio/taiga-back/issues/1031 key,
project: projectId, project: projectId,
}; };
const { id } = await taigaApiRequest.call(this, 'POST', '/webhooks', body); const { id } = await taigaApiRequest.call(this, 'POST', '/webhooks', body);
@ -150,25 +214,34 @@ export class TaigaTrigger implements INodeType {
}; };
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> { async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
//const webhookData = this.getWorkflowStaticData('node'); const body = this.getRequestObject().body as WebhookPayload;
const req = this.getRequestObject();
const bodyData = req.body;
//const headerData = this.getHeaderData();
const operations = this.getNodeParameter('operations', []) as Operations[];
const resources = this.getNodeParameter('resources', []) as Resources[];
// TODO if (!operations.includes('all') && !operations.includes(body.action)) {
// Validate signature return {};
}
if (!resources.includes('all') && !resources.includes(body.type)) {
return {};
}
// TODO: Signature does not match payload hash
// https://github.com/taigaio/taiga-back/issues/1031 // https://github.com/taigaio/taiga-back/issues/1031
// const webhookData = this.getWorkflowStaticData('node');
// const headerData = this.getHeaderData();
// // @ts-ignore // // @ts-ignore
// const requestSignature: string = headerData['x-taiga-webhook-signature']; // const requestSignature = headerData['x-taiga-webhook-signature'];
// console.log(requestSignature);
// if (requestSignature === undefined) { // if (requestSignature === undefined) {
// return {}; // return {};
// } // }
// //@ts-ignore // const computedSignature = createHmac('sha1', webhookData.key as string).update(JSON.stringify(body)).digest('hex');
// const computedSignature = createHmac('sha1', webhookData.key as string).update(JSON.stringify(bodyData)).digest('hex');
// if (requestSignature !== computedSignature) { // if (requestSignature !== computedSignature) {
// return {}; // return {};
@ -176,7 +249,7 @@ export class TaigaTrigger implements INodeType {
return { return {
workflowData: [ workflowData: [
this.helpers.returnJsonArray(bodyData), this.helpers.returnJsonArray(body),
], ],
}; };
} }

View file

@ -22,3 +22,15 @@ type LoadedEpic = LoadedUserStory;
type LoadedTags = { type LoadedTags = {
[tagName: string]: string | null; // hex color [tagName: string]: string | null; // hex color
} }
type Operations = 'all' | 'create' | 'delete' | 'change';
type Resources = 'all' | 'issue' | 'milestone' | 'task' | 'userstory' | 'wikipage';
type WebhookPayload = {
action: Operations;
type: Resources;
by: Record<string, string | number>;
date: string;
data: Record<string, string | number | object | string[]>;
}