mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 08:34:07 -08:00
d6239d5bfb
* Update Compression node * Update Crypto node * Update DateTime node * Update EditImage node * Update EmailSend node * Update ExecuteWorkflow node * Update FTP node * Update Function node * Update FunctionItem node * Update ExecuteCommand node * Update OpenWeatherMap node * Update ReadBinaryFile node * Update ReadPdf node * Update RssFeedRead node & add URL validation * Update SpreadsheetFile node * Update Switch node * Update WriteBinaryFile node * Update Xml node * Update ActiveCampaign node * Update Airtable node * Update ApiTemplateIo node * Update Asana node * Update AwsLambda node * Update AwsSns node * Update AwsComprehend node * Update AwsRekognition node * Update AwsS3 node * Fix Error item * Update AwsSes node * Update AwsSqs node * Update Amqp node * Update Bitly node * Update Box node * Update Brandfetch node * Update CircleCi node * Update Clearbit node * Update ClickUp node * Update Cockpit node * Update CoinGecko node * Update Contentful node * Update ConvertKit node * Update Cortex node * Update CustomerIo node * Update DeepL node * Update Demio node * Update Disqus node * Update Drift node * Update Dropbox node * Update GetResponse node * Refactor & Update Ghost node * Update Github node * Update Gitlab node * Update GoogleAnalytics node * Update GoogleBooks node * Update GoogleCalendar node * Update GoogleDrive node * Update Gmail node * Update GoogleSheets node * Update GoogleSlides node * Update GoogleTasks node * Update Gotify node * Update GraphQL node * Update HackerNews node * Update Harvest node * Update HtmlExtract node * Update Hubspot node * Update Hunter node * Update Intercom node * Update Kafka node * Refactor & update Line node * Update LinkedIn node * Update Mailchimp node * Update Mandrill node * Update Matrix node * Update Mautic node * Update Medium node * Update MessageBird node * Update Mindee node * Update Mocean node * Update MondayCom node * Update MicrosoftExcel node * Update MicrosoftOneDrive node * Update MicrosoftOutlook node * Update Affinity node * Update Chargebee node * Update Discourse node * Update Freshdesk node * Update YouTube node * Update InvoiceNinja node * Update MailerLite node * Update Mailgun node * Update Mailjet node * Update Mattermost node * Update Nasa node * Update NextCloud node * Update OpenThesaurus node * Update Orbit node * Update PagerDuty node * Update PayPal node * Update Peekalink node * Update Phantombuster node * Update PostHog node * Update ProfitWell node * Refactor & Update Pushbullet node * Update QuickBooks node * Update Raindrop node * Update Reddit node * Update Rocketchat node * Update S3 node * Update Salesforce node * Update SendGrid node * Update SentryIo node * Update Shopify node * Update Signl4 node * Update Slack node * Update Spontit node * Update Spotify node * Update Storyblok node * Refactor & Update Strapi node * Refactor & Update Strava node * Update Taiga node * Refactor & update Tapfiliate node * Update Telegram node * Update TheHive node * Update Todoist node * Update TravisCi node * Update Trello node * Update Twilio node * Update Twist node * Update Twitter node * Update Uplead node * Update UProc node * Update Vero node * Update Webflow node * Update Wekan node * Update Wordpress node * Update Xero node * Update Yourls node * Update Zendesk node * Update ZohoCrm node * Refactor & Update Zoom node * Update Zulip node * Update Clockify node * Update MongoDb node * Update MySql node * Update MicrosoftTeams node * Update Stackby node * Refactor Discourse node * Support corner-case in Github node update * Support corner-case in Gitlab node update * Refactor & Update GoogleContacts node * Refactor Mindee node * Update Coda node * Lint fixes * Update Beeminder node * Update Google Firebase RealtimeDatabase node * Update HelpScout node * Update Mailcheck node * Update Paddle node * Update Pipedrive node * Update Pushover node * Update Segment node * Refactor & Update Vonage node * Added new conditions to warnings on execute batch cmd * Added keep only properties flag * Fixed code for keep only props * Added dependencies for image editing Co-authored-by: dali <servfrdali@yahoo.fr>
553 lines
17 KiB
TypeScript
553 lines
17 KiB
TypeScript
import {
|
|
IExecuteFunctions,
|
|
} from 'n8n-core';
|
|
|
|
import {
|
|
IDataObject,
|
|
ILoadOptionsFunctions,
|
|
INodeExecutionData,
|
|
INodePropertyOptions,
|
|
INodeType,
|
|
INodeTypeDescription,
|
|
} from 'n8n-workflow';
|
|
|
|
import {
|
|
getVersionForUpdate,
|
|
handleListing,
|
|
taigaApiRequest,
|
|
throwOnEmptyUpdate,
|
|
toOptions,
|
|
} from './GenericFunctions';
|
|
|
|
import {
|
|
epicFields,
|
|
epicOperations,
|
|
issueFields,
|
|
issueOperations,
|
|
taskFields,
|
|
taskOperations,
|
|
userStoryFields,
|
|
userStoryOperations,
|
|
} from './descriptions';
|
|
|
|
export class Taiga implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
displayName: 'Taiga',
|
|
name: 'taiga',
|
|
icon: 'file:taiga.svg',
|
|
group: ['transform'],
|
|
version: 1,
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
description: 'Consume Taiga API',
|
|
defaults: {
|
|
name: 'Taiga',
|
|
color: '#772244',
|
|
},
|
|
inputs: ['main'],
|
|
outputs: ['main'],
|
|
credentials: [
|
|
{
|
|
name: 'taigaApi',
|
|
required: true,
|
|
},
|
|
],
|
|
properties: [
|
|
{
|
|
displayName: 'Resource',
|
|
name: 'resource',
|
|
type: 'options',
|
|
options: [
|
|
{
|
|
name: 'Epic',
|
|
value: 'epic',
|
|
},
|
|
{
|
|
name: 'Issue',
|
|
value: 'issue',
|
|
},
|
|
{
|
|
name: 'Task',
|
|
value: 'task',
|
|
},
|
|
{
|
|
name: 'User Story',
|
|
value: 'userStory',
|
|
},
|
|
],
|
|
default: 'issue',
|
|
},
|
|
...epicOperations,
|
|
...epicFields,
|
|
...issueOperations,
|
|
...issueFields,
|
|
...taskOperations,
|
|
...taskFields,
|
|
...userStoryOperations,
|
|
...userStoryFields,
|
|
],
|
|
};
|
|
|
|
methods = {
|
|
loadOptions: {
|
|
async getEpics(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
const project = this.getCurrentNodeParameter('projectId') as string;
|
|
const epics = await taigaApiRequest.call(this, 'GET', '/epics', {}, { project }) as LoadedEpic[];
|
|
|
|
return epics.map(({ subject, id }) => ({ name: subject, value: id }));
|
|
},
|
|
|
|
async getMilestones(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
const project = this.getCurrentNodeParameter('projectId') as string;
|
|
const milestones = await taigaApiRequest.call(this, 'GET', '/milestones', {}, { project }) as LoadedResource[];
|
|
|
|
return toOptions(milestones);
|
|
},
|
|
|
|
async getPriorities(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
const project = this.getCurrentNodeParameter('projectId') as string;
|
|
const priorities = await taigaApiRequest.call(this, 'GET', '/priorities', {}, { project }) as LoadedResource[];
|
|
|
|
return toOptions(priorities);
|
|
},
|
|
|
|
async getProjects(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
const { id } = await taigaApiRequest.call(this, 'GET', '/users/me') as { id: string };
|
|
const projects = await taigaApiRequest.call(this, 'GET', '/projects', {}, { member: id }) as LoadedResource[];
|
|
|
|
return toOptions(projects);
|
|
},
|
|
|
|
async getRoles(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
const project = this.getCurrentNodeParameter('projectId') as string;
|
|
const roles = await taigaApiRequest.call(this, 'GET', '/roles', {}, { project }) as LoadedResource[];
|
|
|
|
return toOptions(roles);
|
|
},
|
|
|
|
async getSeverities(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
const project = this.getCurrentNodeParameter('projectId') as string;
|
|
const severities = await taigaApiRequest.call(this, 'GET', '/severities', {}, { project }) as LoadedResource[];
|
|
|
|
return toOptions(severities);
|
|
},
|
|
|
|
async getTags(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
const project = this.getCurrentNodeParameter('projectId') as string;
|
|
const tags = await taigaApiRequest.call(this, 'GET', `/projects/${project}/tags_colors`) as LoadedTags;
|
|
|
|
return Object.keys(tags).map(tag => ({ name: tag, value: tag }));
|
|
},
|
|
|
|
async getTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
const project = this.getCurrentNodeParameter('projectId') as string;
|
|
const types = await taigaApiRequest.call(this, 'GET', '/issue-types', {}, { project }) as LoadedResource[];
|
|
|
|
return toOptions(types);
|
|
},
|
|
|
|
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
const project = this.getCurrentNodeParameter('projectId') as string;
|
|
const users = await taigaApiRequest.call(this, 'GET', '/users', {}, { project }) as LoadedUser[];
|
|
|
|
return users.map(({ full_name_display, id }) => ({ name: full_name_display, value: id }));
|
|
},
|
|
|
|
async getUserStories(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
const project = this.getCurrentNodeParameter('projectId') as string;
|
|
const userStories = await taigaApiRequest.call(this, 'GET', '/userstories', {}, { project }) as LoadedUserStory[];
|
|
|
|
return userStories.map(({ subject, id }) => ({ name: subject, value: id }));
|
|
},
|
|
|
|
// statuses
|
|
|
|
async getIssueStatuses(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
const project = this.getCurrentNodeParameter('projectId') as string;
|
|
const statuses = await taigaApiRequest.call(this, 'GET', '/issue-statuses', {}, { project }) as LoadedResource[];
|
|
|
|
return toOptions(statuses);
|
|
},
|
|
|
|
async getTaskStatuses(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
const project = this.getCurrentNodeParameter('projectId') as string;
|
|
const statuses = await taigaApiRequest.call(this, 'GET', '/task-statuses', {}, { project }) as LoadedResource[];
|
|
|
|
return toOptions(statuses);
|
|
},
|
|
|
|
async getUserStoryStatuses(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
const project = this.getCurrentNodeParameter('projectId') as string;
|
|
const statuses = await taigaApiRequest.call(this, 'GET', '/userstory-statuses', {}, { project }) as LoadedResource[];
|
|
|
|
return toOptions(statuses);
|
|
},
|
|
},
|
|
};
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
const items = this.getInputData();
|
|
const returnData: IDataObject[] = [];
|
|
|
|
const resource = this.getNodeParameter('resource', 0) as Resource;
|
|
const operation = this.getNodeParameter('operation', 0) as Operation;
|
|
|
|
let responseData;
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
try {
|
|
|
|
if (resource === 'epic') {
|
|
|
|
// **********************************************************************
|
|
// epic
|
|
// **********************************************************************
|
|
|
|
if (operation === 'create') {
|
|
|
|
// ----------------------------------------
|
|
// epic: create
|
|
// ----------------------------------------
|
|
|
|
const body = {
|
|
project: this.getNodeParameter('projectId', i),
|
|
subject: this.getNodeParameter('subject', i),
|
|
} as IDataObject;
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
|
|
if (Object.keys(additionalFields).length) {
|
|
Object.assign(body, additionalFields);
|
|
}
|
|
|
|
responseData = await taigaApiRequest.call(this, 'POST', '/epics', body);
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------------
|
|
// epic: delete
|
|
// ----------------------------------------
|
|
|
|
const epicId = this.getNodeParameter('epicId', i);
|
|
|
|
responseData = await taigaApiRequest.call(this, 'DELETE', `/epics/${epicId}`);
|
|
responseData = { success: true };
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
// ----------------------------------------
|
|
// epic: get
|
|
// ----------------------------------------
|
|
|
|
const epicId = this.getNodeParameter('epicId', i);
|
|
|
|
responseData = await taigaApiRequest.call(this, 'GET', `/epics/${epicId}`);
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------------
|
|
// epic: getAll
|
|
// ----------------------------------------
|
|
|
|
const qs = {} as IDataObject;
|
|
const filters = this.getNodeParameter('filters', i) as IDataObject;
|
|
|
|
if (Object.keys(filters).length) {
|
|
Object.assign(qs, filters);
|
|
}
|
|
|
|
responseData = await handleListing.call(this, 'GET', '/epics', {}, qs, i);
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------------
|
|
// epic: update
|
|
// ----------------------------------------
|
|
|
|
const body = {} as IDataObject;
|
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
|
|
if (Object.keys(updateFields).length) {
|
|
Object.assign(body, updateFields);
|
|
} else {
|
|
throwOnEmptyUpdate.call(this, resource);
|
|
}
|
|
|
|
const epicId = this.getNodeParameter('epicId', i);
|
|
body.version = await getVersionForUpdate.call(this, `/epics/${epicId}`);
|
|
|
|
responseData = await taigaApiRequest.call(this, 'PATCH', `/epics/${epicId}`, body);
|
|
|
|
}
|
|
|
|
} else if (resource === 'issue') {
|
|
|
|
// **********************************************************************
|
|
// issue
|
|
// **********************************************************************
|
|
|
|
if (operation === 'create') {
|
|
|
|
// ----------------------------------------
|
|
// issue: create
|
|
// ----------------------------------------
|
|
|
|
const body = {
|
|
project: this.getNodeParameter('projectId', i),
|
|
subject: this.getNodeParameter('subject', i),
|
|
} as IDataObject;
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
|
|
if (Object.keys(additionalFields).length) {
|
|
Object.assign(body, additionalFields);
|
|
}
|
|
|
|
responseData = await taigaApiRequest.call(this, 'POST', '/issues', body);
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------------
|
|
// issue: delete
|
|
// ----------------------------------------
|
|
|
|
const issueId = this.getNodeParameter('issueId', i);
|
|
|
|
responseData = await taigaApiRequest.call(this, 'DELETE', `/issues/${issueId}`);
|
|
responseData = { success: true };
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
// ----------------------------------------
|
|
// issue: get
|
|
// ----------------------------------------
|
|
|
|
const issueId = this.getNodeParameter('issueId', i);
|
|
|
|
responseData = await taigaApiRequest.call(this, 'GET', `/issues/${issueId}`);
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------------
|
|
// issue: getAll
|
|
// ----------------------------------------
|
|
|
|
const qs = {} as IDataObject;
|
|
const filters = this.getNodeParameter('filters', i) as IDataObject;
|
|
|
|
if (Object.keys(filters).length) {
|
|
Object.assign(qs, filters);
|
|
}
|
|
|
|
responseData = await handleListing.call(this, 'GET', '/issues', {}, qs, i);
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------------
|
|
// issue: update
|
|
// ----------------------------------------
|
|
|
|
const body = {} as IDataObject;
|
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
|
|
if (Object.keys(updateFields).length) {
|
|
Object.assign(body, updateFields);
|
|
} else {
|
|
throwOnEmptyUpdate.call(this, resource);
|
|
}
|
|
|
|
const issueId = this.getNodeParameter('issueId', i);
|
|
body.version = await getVersionForUpdate.call(this, `/issues/${issueId}`);
|
|
|
|
responseData = await taigaApiRequest.call(this, 'PATCH', `/issues/${issueId}`, body);
|
|
|
|
}
|
|
|
|
} else if (resource === 'task') {
|
|
|
|
// **********************************************************************
|
|
// task
|
|
// **********************************************************************
|
|
|
|
if (operation === 'create') {
|
|
|
|
// ----------------------------------------
|
|
// task: create
|
|
// ----------------------------------------
|
|
|
|
const body = {
|
|
project: this.getNodeParameter('projectId', i),
|
|
subject: this.getNodeParameter('subject', i),
|
|
} as IDataObject;
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
|
|
if (Object.keys(additionalFields).length) {
|
|
Object.assign(body, additionalFields);
|
|
}
|
|
|
|
responseData = await taigaApiRequest.call(this, 'POST', '/tasks', body);
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------------
|
|
// task: delete
|
|
// ----------------------------------------
|
|
|
|
const taskId = this.getNodeParameter('taskId', i);
|
|
|
|
responseData = await taigaApiRequest.call(this, 'DELETE', `/tasks/${taskId}`);
|
|
responseData = { success: true };
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
// ----------------------------------------
|
|
// task: get
|
|
// ----------------------------------------
|
|
|
|
const taskId = this.getNodeParameter('taskId', i);
|
|
|
|
responseData = await taigaApiRequest.call(this, 'GET', `/tasks/${taskId}`);
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------------
|
|
// task: getAll
|
|
// ----------------------------------------
|
|
|
|
const qs = {} as IDataObject;
|
|
const filters = this.getNodeParameter('filters', i) as IDataObject;
|
|
|
|
if (Object.keys(filters).length) {
|
|
Object.assign(qs, filters);
|
|
}
|
|
|
|
responseData = await handleListing.call(this, 'GET', '/tasks', {}, qs, i);
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------------
|
|
// task: update
|
|
// ----------------------------------------
|
|
|
|
const body = {} as IDataObject;
|
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
|
|
if (Object.keys(updateFields).length) {
|
|
Object.assign(body, updateFields);
|
|
} else {
|
|
throwOnEmptyUpdate.call(this, resource);
|
|
}
|
|
|
|
const taskId = this.getNodeParameter('taskId', i);
|
|
body.version = await getVersionForUpdate.call(this, `/tasks/${taskId}`);
|
|
|
|
responseData = await taigaApiRequest.call(this, 'PATCH', `/tasks/${taskId}`, body);
|
|
|
|
}
|
|
|
|
} else if (resource === 'userStory') {
|
|
|
|
// **********************************************************************
|
|
// userStory
|
|
// **********************************************************************
|
|
|
|
if (operation === 'create') {
|
|
|
|
// ----------------------------------------
|
|
// userStory: create
|
|
// ----------------------------------------
|
|
|
|
const body = {
|
|
project: this.getNodeParameter('projectId', i),
|
|
subject: this.getNodeParameter('subject', i),
|
|
} as IDataObject;
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
|
|
if (Object.keys(additionalFields).length) {
|
|
Object.assign(body, additionalFields);
|
|
}
|
|
|
|
responseData = await taigaApiRequest.call(this, 'POST', '/userstories', body);
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------------
|
|
// userStory: delete
|
|
// ----------------------------------------
|
|
|
|
const userStoryId = this.getNodeParameter('userStoryId', i);
|
|
|
|
const endpoint = `/userstories/${userStoryId}`;
|
|
responseData = await taigaApiRequest.call(this, 'DELETE', endpoint);
|
|
responseData = { success: true };
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
// ----------------------------------------
|
|
// userStory: get
|
|
// ----------------------------------------
|
|
|
|
const userStoryId = this.getNodeParameter('userStoryId', i);
|
|
|
|
const endpoint = `/userstories/${userStoryId}`;
|
|
responseData = await taigaApiRequest.call(this, 'GET', endpoint);
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------------
|
|
// userStory: getAll
|
|
// ----------------------------------------
|
|
|
|
const qs = {} as IDataObject;
|
|
const filters = this.getNodeParameter('filters', i) as IDataObject;
|
|
|
|
if (Object.keys(filters).length) {
|
|
Object.assign(qs, filters);
|
|
}
|
|
|
|
responseData = await handleListing.call(this, 'GET', '/userstories', {}, qs, i);
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------------
|
|
// userStory: update
|
|
// ----------------------------------------
|
|
|
|
const body = {} as IDataObject;
|
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
|
|
if (Object.keys(updateFields).length) {
|
|
Object.assign(body, updateFields);
|
|
} else {
|
|
throwOnEmptyUpdate.call(this, resource);
|
|
}
|
|
|
|
const userStoryId = this.getNodeParameter('userStoryId', i);
|
|
body.version = await getVersionForUpdate.call(this, `/userstories/${userStoryId}`);
|
|
|
|
responseData = await taigaApiRequest.call(this, 'PATCH', `/userstories/${userStoryId}`, body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
if (this.continueOnFail()) {
|
|
returnData.push({ error: error.message });
|
|
continue;
|
|
}
|
|
|
|
throw error;
|
|
}
|
|
|
|
Array.isArray(responseData)
|
|
? returnData.push(...responseData)
|
|
: returnData.push(responseData);
|
|
|
|
}
|
|
|
|
return [this.helpers.returnJsonArray(returnData)];
|
|
}
|
|
} |