n8n/packages/nodes-base/nodes/Jira/Jira.node.ts

1516 lines
44 KiB
TypeScript
Raw Normal View History

import { mergeWith } from 'lodash';
import type { IExecuteFunctions } from 'n8n-core';
2020-04-23 22:59:19 -07:00
import type {
IBinaryKeyData,
2019-11-26 12:38:38 -08:00
IDataObject,
ILoadOptionsFunctions,
2020-04-23 22:59:19 -07:00
INodeExecutionData,
INodeListSearchItems,
INodeListSearchResult,
2019-11-26 12:38:38 -08:00
INodePropertyOptions,
2020-04-23 22:59:19 -07:00
INodeType,
INodeTypeDescription,
2019-11-26 12:38:38 -08:00
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
2020-04-23 22:59:19 -07:00
2019-11-26 12:38:38 -08:00
import {
filterSortSearchListItems,
jiraSoftwareCloudApiRequest,
jiraSoftwareCloudApiRequestAllItems,
simplifyIssueOutput,
2019-11-26 12:38:38 -08:00
validateJSON,
} from './GenericFunctions';
2020-04-23 22:59:19 -07:00
import { issueAttachmentFields, issueAttachmentOperations } from './IssueAttachmentDescription';
import { issueCommentFields, issueCommentOperations } from './IssueCommentDescription';
import { issueFields, issueOperations } from './IssueDescription';
2020-04-23 22:59:19 -07:00
import type {
IFields,
2020-04-23 22:59:19 -07:00
IIssue,
2019-11-29 14:30:00 -08:00
INotificationRecipients,
2020-04-23 22:59:19 -07:00
INotify,
2019-11-29 14:30:00 -08:00
NotificationRecipientsRestrictions,
} from './IssueInterface';
2019-11-26 12:38:38 -08:00
import { userFields, userOperations } from './UserDescription';
2020-05-12 06:08:19 -07:00
export class Jira implements INodeType {
2019-11-26 12:38:38 -08:00
description: INodeTypeDescription = {
2020-02-01 15:15:56 -08:00
displayName: 'Jira Software',
2020-05-12 06:08:19 -07:00
name: 'jira',
icon: 'file:jira.svg',
2019-11-26 12:38:38 -08:00
group: ['output'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
2020-02-01 15:15:56 -08:00
description: 'Consume Jira Software API',
2019-11-26 12:38:38 -08:00
defaults: {
feat(editor): Node creator actions (#4696) * WIP: Node Actions List UI * WIP: Recommended Actions and preseting of fields * WIP: Resource category * :art: Moved actions categorisation to the server * :label: Add missing INodeAction type * :sparkles: Improve SSR categorisation, fix adding of mixed actions * :recycle: Refactor CategorizedItems to composition api, style fixes * WIP: Adding multiple nodes * :recycle: Refactor rest of the NodeCreator component to composition API, conver globalLinkActions to composable * :sparkles: Allow actions dragging, fix search and refactor passing of actions to categorized items * :lipstick: Fix node actions title * Migrate to the pinia store, add posthog feature and various fixes * :bug: Fix filtering of trigger actions when not merged * fix: N8N-5439 — Do not use simple node item when at NodeHelperPanel root * :bug: Design review fixes * :bug: Fix disabling of merged actions * Fix trigger root filtering * :sparkles: Allow for custom node actions parser, introduce hubspot parser * :bug: Fix initial node params validation, fix position of second added node * :bug: Introduce operations category, removed canvas node names overrride, fix API actions display and prevent dragging of action nodes * :sparkles: Prevent NDV auto-open feature flag * :bug: Inject recommened action for trigger nodes without actions * Refactored NodeCreatorNode to Storybook, change filtering of merged nodes for the trigger helper panel, minor fixes * Improve rendering of app nodes and animation * Cleanup, any only enable accordion transition on triggerhelperpanel * Hide node creator scrollbars in Firefox * Minor styles fixes * Do not copy the array in rendering method * Removed unused props * Fix memory leak * Fix categorisation of regular nodes with a single resource * Implement telemetry calls for node actions * Move categorization to FE * Fix client side actions categorisation * Skip custom action show * Only load tooltip for NodeIcon if necessary * Fix lodash startCase import * Remove lodash.startcase * Cleanup * Fix node creator autofocus on "tab" * Prevent posthog getFeatureFlag from crashing * Debugging preview env search issues * Remove logs * Make sure the pre-filled params are update not overwritten * Get rid of transition in itemiterator * WIP: Rough version of NodeActions keyboard navigation, replace nodeCreator composable with Pinia store module * Rewrite to add support for ActionItem to ItemIterator and make CategorizedItems accept items props * Fix category item counter & cleanup * Add APIHint to actions search no-result, clean up NodeCreatorNode * Improve node actions no results message * Remove logging, fix filtering of recommended placeholder category * Remove unused NodeActions component and node merging feature falg * Do not show regular nodes without actions * Make sure to add manual trigger when adding http node via actions hint * Fixed api hint footer line height * Prevent pointer-events od NodeIcon img and remove "this" from template * Address PR points * Fix e2e specs * Make sure canvas ia loaded * Make sure canvas ia loaded before opening nodeCreator in e2e spec * Fix flaky workflows tags e2e getter * Imrpove node creator click outside UX, add manual node to regular nodes added from trigger panel * Add manual trigger node if dragging regular from trigger panel
2022-12-09 01:56:36 -08:00
name: 'Jira Software',
2019-11-26 12:38:38 -08:00
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'jiraSoftwareCloudApi',
2019-11-26 12:38:38 -08:00
required: true,
2020-02-02 07:01:56 -08:00
displayOptions: {
show: {
jiraVersion: ['cloud'],
2020-02-02 07:01:56 -08:00
},
},
},
{
name: 'jiraSoftwareServerApi',
required: true,
displayOptions: {
show: {
jiraVersion: ['server'],
2020-02-02 07:01:56 -08:00
},
},
2020-02-01 15:15:56 -08:00
},
2019-11-26 12:38:38 -08:00
],
properties: [
2020-02-02 07:01:56 -08:00
{
displayName: 'Jira Version',
name: 'jiraVersion',
type: 'options',
options: [
{
name: 'Cloud',
value: 'cloud',
},
{
name: 'Server (Self Hosted)',
value: 'server',
},
],
default: 'cloud',
},
2019-11-26 12:38:38 -08:00
{
displayName: 'Resource',
name: 'resource',
type: 'options',
refactor: Apply more nodelinting rules (#3324) * :pencil2: Alphabetize lint rules * :fire: Remove duplicates * :zap: Update `lintfix` script * :shirt: Apply `node-param-operation-without-no-data-expression` (#3329) * :shirt: Apply `node-param-operation-without-no-data-expression` * :shirt: Add exceptions * :shirt: Apply `node-param-description-weak` (#3328) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-value-duplicate` (#3331) * :shirt: Apply `node-param-description-miscased-json` (#3337) * :shirt: Apply `node-param-display-name-excess-inner-whitespace` (#3335) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-type-options-missing-from-limit` (#3336) * Rule workig as intended * :pencil2: Uncomment rules Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-name-duplicate` (#3338) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-description-wrong-for-simplify` (#3334) * :zap: fix * :zap: exceptions * :zap: changed rule ignoring from file to line * :shirt: Apply `node-param-resource-without-no-data-expression` (#3339) * :shirt: Apply `node-param-display-name-untrimmed` (#3341) * :shirt: Apply `node-param-display-name-miscased-id` (#3340) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-resource-with-plural-option` (#3342) * :shirt: Apply `node-param-description-wrong-for-upsert` (#3333) * :zap: fix * :zap: replaced record with contact in description * :zap: fix Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-description-identical-to-name` (#3343) * :shirt: Apply `node-param-option-name-containing-star` (#3347) * :shirt: Apply `node-param-display-name-wrong-for-update-fields` (#3348) * :shirt: Apply `node-param-option-name-wrong-for-get-all` (#3345) * :zap: fix * :zap: exceptions * :shirt: Apply node-param-display-name-wrong-for-simplify (#3344) * Rule working as intended * Uncomented other rules * :shirt: Undo and add exceptions Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :zap: Alphabetize lint rules * :zap: Restore `lintfix` script Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: agobrech <45268029+agobrech@users.noreply.github.com>
2022-05-20 14:47:24 -07:00
noDataExpression: true,
2019-11-26 12:38:38 -08:00
options: [
{
name: 'Issue',
value: 'issue',
description:
'Creates an issue or, where the option to create subtasks is enabled in Jira, a subtask',
2019-11-26 12:38:38 -08:00
},
{
name: 'Issue Attachment',
value: 'issueAttachment',
description: 'Add, remove, and get an attachment from an issue',
},
{
name: 'Issue Comment',
value: 'issueComment',
description: 'Get, create, update, and delete a comment from an issue',
},
{
name: 'User',
value: 'user',
description: 'Get, create and delete a user',
},
2019-11-26 12:38:38 -08:00
],
default: 'issue',
},
2020-02-01 15:15:56 -08:00
...issueOperations,
2019-11-27 14:42:28 -08:00
...issueFields,
...issueAttachmentOperations,
...issueAttachmentFields,
...issueCommentOperations,
...issueCommentFields,
...userOperations,
...userFields,
2019-11-26 12:38:38 -08:00
],
};
2019-11-27 14:42:28 -08:00
methods = {
listSearch: {
2019-11-27 14:42:28 -08:00
// Get all the projects to display them to user so that he can
// select them easily
async getProjects(
this: ILoadOptionsFunctions,
filter?: string,
): Promise<INodeListSearchResult> {
const returnData: INodeListSearchItems[] = [];
const jiraVersion = this.getCurrentNodeParameter('jiraVersion') as string;
let endpoint = '';
let projects;
if (jiraVersion === 'server') {
endpoint = '/api/2/project';
projects = await jiraSoftwareCloudApiRequest.call(this, endpoint, 'GET');
} else {
endpoint = '/api/2/project/search';
projects = await jiraSoftwareCloudApiRequestAllItems.call(
this,
'values',
endpoint,
'GET',
);
2020-02-01 15:15:56 -08:00
}
2020-04-23 22:59:19 -07:00
2020-02-01 15:15:56 -08:00
if (projects.values && Array.isArray(projects.values)) {
projects = projects.values;
}
for (const project of projects) {
2019-11-27 14:42:28 -08:00
const projectName = project.name;
const projectId = project.id;
returnData.push({
name: projectName,
value: projectId,
});
}
2020-11-09 22:49:43 -08:00
return { results: filterSortSearchListItems(returnData, filter) };
2019-11-27 14:42:28 -08:00
},
// Get all the issue types to display them to user so that he can
// select them easily
async getIssueTypes(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
const projectId = this.getCurrentNodeParameter('project', { extractValue: true });
const returnData: INodeListSearchItems[] = [];
const { issueTypes } = await jiraSoftwareCloudApiRequest.call(
this,
`/api/2/project/${projectId}`,
'GET',
);
for (const issueType of issueTypes) {
const issueTypeName = issueType.name;
const issueTypeId = issueType.id;
returnData.push({
name: issueTypeName,
value: issueTypeId,
});
2019-11-27 14:42:28 -08:00
}
2020-05-05 13:56:24 -07:00
2020-11-09 22:49:43 -08:00
returnData.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
2020-11-09 22:49:43 -08:00
return 0;
});
return { results: returnData };
2019-11-27 14:42:28 -08:00
},
// Get all the users to display them to user so that he can
// select them easily
async getUsers(this: ILoadOptionsFunctions, filter?: string): Promise<INodeListSearchResult> {
2020-05-05 13:56:24 -07:00
const jiraVersion = this.getCurrentNodeParameter('jiraVersion') as string;
const query: IDataObject = {};
let endpoint = '/api/2/users/search';
2020-05-05 13:56:24 -07:00
if (jiraVersion === 'server') {
endpoint = '/api/2/user/search';
query.username = "'";
}
2020-04-23 22:59:19 -07:00
const users = await jiraSoftwareCloudApiRequest.call(this, endpoint, 'GET', {}, query);
const returnData: INodeListSearchItems[] = users.reduce(
(activeUsers: INodeListSearchItems[], user: IDataObject) => {
if (user.active) {
activeUsers.push({
name: user.displayName as string,
value: (user.accountId ?? user.name) as string,
});
}
return activeUsers;
},
[],
);
return { results: filterSortSearchListItems(returnData, filter) };
2019-11-27 14:42:28 -08:00
},
2019-11-29 14:30:00 -08:00
// Get all the priorities to display them to user so that he can
2019-11-29 14:30:00 -08:00
// select them easily
async getPriorities(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
const returnData: INodeListSearchItems[] = [];
2020-04-23 22:59:19 -07:00
const priorities = await jiraSoftwareCloudApiRequest.call(this, '/api/2/priority', 'GET');
2020-04-23 22:59:19 -07:00
for (const priority of priorities) {
const priorityName = priority.name;
const priorityId = priority.id;
2019-11-29 14:30:00 -08:00
returnData.push({
name: priorityName,
value: priorityId,
2019-11-29 14:30:00 -08:00
});
}
2020-11-09 22:49:43 -08:00
returnData.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
2020-11-09 22:49:43 -08:00
return 0;
});
return { results: returnData };
2020-04-24 00:50:56 -07:00
},
// Get all the transitions (status) to display them to user so that he can
2020-04-24 00:50:56 -07:00
// select them easily
async getTransitions(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
const returnData: INodeListSearchItems[] = [];
2020-04-24 00:50:56 -07:00
const issueKey = this.getCurrentNodeParameter('issueKey');
const transitions = await jiraSoftwareCloudApiRequest.call(
this,
`/api/2/issue/${issueKey}/transitions`,
'GET',
);
2020-04-24 00:50:56 -07:00
for (const transition of transitions.transitions) {
returnData.push({
name: transition.name,
value: transition.id,
});
}
2020-11-09 22:49:43 -08:00
returnData.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
2020-11-09 22:49:43 -08:00
return 0;
});
return { results: returnData };
2020-04-24 00:50:56 -07:00
},
// Get all the custom fields to display them to user so that he can
// select them easily
async getCustomFields(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
const returnData: INodeListSearchItems[] = [];
const operation = this.getCurrentNodeParameter('operation') as string;
let projectId: string;
let issueTypeId: string;
if (operation === 'create') {
projectId = this.getCurrentNodeParameter('project', { extractValue: true }) as string;
issueTypeId = this.getCurrentNodeParameter('issueType', { extractValue: true }) as string;
} else {
const issueKey = this.getCurrentNodeParameter('issueKey') as string;
const res = await jiraSoftwareCloudApiRequest.call(
this,
`/api/2/issue/${issueKey}`,
'GET',
{},
{},
);
projectId = res.fields.project.id;
issueTypeId = res.fields.issuetype.id;
}
const res = await jiraSoftwareCloudApiRequest.call(
this,
`/api/2/issue/createmeta?projectIds=${projectId}&issueTypeIds=${issueTypeId}&expand=projects.issuetypes.fields`,
'GET',
);
const fields = res.projects
.find((o: any) => o.id === projectId)
.issuetypes.find((o: any) => o.id === issueTypeId).fields;
for (const key of Object.keys(fields)) {
const field = fields[key];
if (field.schema && Object.keys(field.schema).includes('customId')) {
returnData.push({
name: field.name,
value: field.key || field.fieldId,
});
}
}
return { results: returnData };
},
},
loadOptions: {
// Get all the labels to display them to user so that he can
// select them easily
async getLabels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const labels = await jiraSoftwareCloudApiRequest.call(this, '/api/2/label', 'GET');
for (const label of labels.values) {
const labelName = label;
const labelId = label;
returnData.push({
name: labelName,
value: labelId,
});
}
returnData.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
return returnData;
},
// Get all the users to display them to user so that he can
// select them easily
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const jiraVersion = this.getCurrentNodeParameter('jiraVersion') as string;
const query: IDataObject = {};
let endpoint = '/api/2/users/search';
if (jiraVersion === 'server') {
endpoint = '/api/2/user/search';
query.username = "'";
}
const users = await jiraSoftwareCloudApiRequest.call(this, endpoint, 'GET', {}, query);
return users
.reduce((activeUsers: INodePropertyOptions[], user: IDataObject) => {
if (user.active) {
activeUsers.push({
name: user.displayName as string,
value: (user.accountId || user.name) as string,
});
}
return activeUsers;
}, [])
.sort((a: INodePropertyOptions, b: INodePropertyOptions) => {
return a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1;
});
},
// Get all the groups to display them to user so that he can
// select them easily
async getGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const groups = await jiraSoftwareCloudApiRequest.call(this, '/api/2/groups/picker', 'GET');
for (const group of groups.groups) {
const groupName = group.name;
const groupId = group.name;
returnData.push({
name: groupName,
value: groupId,
});
}
returnData.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
return returnData;
},
// Get all the components to display them to user so that he can
// select them easily
async getProjectComponents(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const project = this.getCurrentNodeParameter('project', { extractValue: true });
const { values: components } = await jiraSoftwareCloudApiRequest.call(
this,
`/api/2/project/${project}/component`,
'GET',
);
for (const component of components) {
returnData.push({
name: component.name,
value: component.id,
});
}
returnData.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
return returnData;
},
2020-10-22 06:46:03 -07:00
},
2019-11-27 14:42:28 -08:00
};
2019-11-26 12:38:38 -08:00
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
2019-11-27 14:42:28 -08:00
const items = this.getInputData();
const returnData: INodeExecutionData[] = [];
refactor: Apply `eslint-plugin-n8n-nodes-base` autofixable rules (#3174) * :zap: Initial setup * :shirt: Update `.eslintignore` * :shirt: Autofix node-param-default-missing (#3173) * :fire: Remove duplicate key * :shirt: Add exceptions * :package: Update package-lock.json * :shirt: Apply `node-class-description-inputs-wrong-trigger-node` (#3176) * :shirt: Apply `node-class-description-inputs-wrong-regular-node` (#3177) * :shirt: Apply `node-class-description-outputs-wrong` (#3178) * :shirt: Apply `node-execute-block-double-assertion-for-items` (#3179) * :shirt: Apply `node-param-default-wrong-for-collection` (#3180) * :shirt: Apply node-param-default-wrong-for-boolean (#3181) * Autofixed default missing * Autofixed booleans, worked well * :zap: Fix params * :rewind: Undo exempted autofixes * :package: Update package-lock.json * :shirt: Apply node-class-description-missing-subtitle (#3182) * :zap: Fix missing comma * :shirt: Apply `node-param-default-wrong-for-fixed-collection` (#3184) * :shirt: Add exception for `node-class-description-missing-subtitle` * :shirt: Apply `node-param-default-wrong-for-multi-options` (#3185) * :shirt: Apply `node-param-collection-type-unsorted-items` (#3186) * Missing coma * :shirt: Apply `node-param-default-wrong-for-simplify` (#3187) * :shirt: Apply `node-param-description-comma-separated-hyphen` (#3190) * :shirt: Apply `node-param-description-empty-string` (#3189) * :shirt: Apply `node-param-description-excess-inner-whitespace` (#3191) * Rule looks good * Add whitespace rule in eslint config * :zao: fix * :shirt: Apply `node-param-description-identical-to-display-name` (#3193) * :shirt: Apply `node-param-description-missing-for-ignore-ssl-issues` (#3195) * :rewind: Revert ":zao: fix" This reverts commit ef8a76f3dfedffd1bdccf3178af8a8d90cf5a55c. * :shirt: Apply `node-param-description-missing-for-simplify` (#3196) * :shirt: Apply `node-param-description-missing-final-period` (#3194) * Rule working as intended * Add rule to eslint * :shirt: Apply node-param-description-missing-for-return-all (#3197) * :zap: Restore `lintfix` command Co-authored-by: agobrech <45268029+agobrech@users.noreply.github.com> Co-authored-by: Omar Ajoue <krynble@gmail.com> Co-authored-by: agobrech <ael.gobrecht@gmail.com> Co-authored-by: Michael Kret <michael.k@radency.com>
2022-04-22 09:29:51 -07:00
const length = items.length;
2019-11-27 14:42:28 -08:00
let responseData;
2019-11-29 14:30:00 -08:00
const qs: IDataObject = {};
2019-12-02 13:40:24 -08:00
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
const jiraVersion = this.getNodeParameter('jiraVersion', 0) as string;
if (resource === 'issue') {
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-post
if (operation === 'create') {
for (let i = 0; i < length; i++) {
2019-11-27 14:42:28 -08:00
const summary = this.getNodeParameter('summary', i) as string;
const projectId = this.getNodeParameter('project', i, '', {
extractValue: true,
}) as string;
const issueTypeId = this.getNodeParameter('issueType', i, '', {
extractValue: true,
}) as string;
const additionalFields = this.getNodeParameter('additionalFields', i);
const assignee = this.getNodeParameter('additionalFields.assignee', i, '', {
extractValue: true,
});
if (assignee) additionalFields.assignee = assignee;
const reporter = this.getNodeParameter('additionalFields.reporter', i, '', {
extractValue: true,
});
if (reporter) additionalFields.reporter = reporter;
const priority = this.getNodeParameter('additionalFields.priority', i, '', {
extractValue: true,
});
if (priority) additionalFields.priority = priority;
const body: IIssue = {};
const fields: IFields = {
summary,
project: {
id: projectId,
},
issuetype: {
id: issueTypeId,
},
2019-11-27 14:42:28 -08:00
};
if (additionalFields.labels) {
fields.labels = additionalFields.labels as string[];
2019-11-27 14:42:28 -08:00
}
if (additionalFields.serverLabels) {
fields.labels = additionalFields.serverLabels as string[];
}
2019-11-27 14:42:28 -08:00
if (additionalFields.priority) {
fields.priority = {
2019-11-27 14:42:28 -08:00
id: additionalFields.priority as string,
};
}
if (additionalFields.assignee) {
2020-05-05 13:56:24 -07:00
if (jiraVersion === 'server') {
fields.assignee = {
name: additionalFields.assignee as string,
};
} else {
fields.assignee = {
id: additionalFields.assignee as string,
};
}
2019-11-27 14:42:28 -08:00
}
if (additionalFields.reporter) {
if (jiraVersion === 'server') {
fields.reporter = {
name: additionalFields.reporter as string,
};
} else {
fields.reporter = {
id: additionalFields.reporter as string,
};
}
}
if (additionalFields.description) {
fields.description = additionalFields.description as string;
}
2019-11-29 14:30:00 -08:00
if (additionalFields.updateHistory) {
qs.updateHistory = additionalFields.updateHistory as boolean;
}
if (additionalFields.componentIds) {
fields.components = (additionalFields.componentIds as string[]).map((id) => ({ id }));
}
if (additionalFields.customFieldsUi) {
const customFields = (additionalFields.customFieldsUi as IDataObject)
.customFieldsValues as IDataObject[];
if (customFields) {
// resolve resource locator fieldId value
customFields.forEach((cf) => {
if (typeof cf.fieldId !== 'string') {
cf.fieldId = ((cf.fieldId as IDataObject).value as string).trim();
}
});
const data = customFields.reduce(
(obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }),
{},
);
Object.assign(fields, data);
}
}
const issueTypes = await jiraSoftwareCloudApiRequest.call(
this,
'/api/2/issuetype',
'GET',
body,
qs,
);
2019-11-29 14:30:00 -08:00
const subtaskIssues = [];
for (const issueType of issueTypes) {
if (issueType.subtask) {
subtaskIssues.push(issueType.id);
2019-11-27 14:42:28 -08:00
}
}
if (!additionalFields.parentIssueKey && subtaskIssues.includes(issueTypeId)) {
throw new NodeOperationError(
this.getNode(),
'You must define a Parent Issue Key when Issue type is sub-task',
{ itemIndex: i },
);
} else if (additionalFields.parentIssueKey && subtaskIssues.includes(issueTypeId)) {
2019-11-29 14:30:00 -08:00
fields.parent = {
2019-12-01 13:47:53 -08:00
key: (additionalFields.parentIssueKey as string).toUpperCase(),
2019-11-29 14:30:00 -08:00
};
}
body.fields = fields;
responseData = await jiraSoftwareCloudApiRequest.call(this, '/api/2/issue', 'POST', body);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
2019-11-27 14:42:28 -08:00
}
}
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-put
if (operation === 'update') {
for (let i = 0; i < length; i++) {
2019-11-29 14:30:00 -08:00
const issueKey = this.getNodeParameter('issueKey', i) as string;
const updateFields = this.getNodeParameter('updateFields', i);
const assignee = this.getNodeParameter('updateFields.assignee', i, '', {
extractValue: true,
});
if (assignee) updateFields.assignee = assignee;
const reporter = this.getNodeParameter('updateFields.reporter', i, '', {
extractValue: true,
});
if (reporter) updateFields.reporter = reporter;
const priority = this.getNodeParameter('updateFields.priority', i, '', {
extractValue: true,
});
if (priority) updateFields.priority = priority;
const statusId = this.getNodeParameter('updateFields.statusId', i, '', {
extractValue: true,
});
if (statusId) updateFields.statusId = statusId;
2019-11-29 14:30:00 -08:00
const body: IIssue = {};
2019-12-01 13:47:53 -08:00
const fields: IFields = {};
if (updateFields.summary) {
fields.summary = updateFields.summary as string;
2019-11-29 14:30:00 -08:00
}
2019-12-01 13:47:53 -08:00
if (updateFields.issueType) {
fields.issuetype = {
id: updateFields.issueType as string,
};
}
if (updateFields.labels) {
fields.labels = updateFields.labels as string[];
}
if (updateFields.serverLabels) {
fields.labels = updateFields.serverLabels as string[];
}
2019-12-01 13:47:53 -08:00
if (updateFields.priority) {
2019-11-29 14:30:00 -08:00
fields.priority = {
2019-12-01 13:47:53 -08:00
id: updateFields.priority as string,
2019-11-29 14:30:00 -08:00
};
}
2019-12-01 13:47:53 -08:00
if (updateFields.assignee) {
2020-05-05 13:56:24 -07:00
if (jiraVersion === 'server') {
fields.assignee = {
name: updateFields.assignee as string,
};
} else {
fields.assignee = {
id: updateFields.assignee as string,
};
}
2019-11-29 14:30:00 -08:00
}
if (updateFields.reporter) {
if (jiraVersion === 'server') {
fields.reporter = {
name: updateFields.reporter as string,
};
} else {
fields.reporter = {
id: updateFields.reporter as string,
};
}
}
2019-12-01 13:47:53 -08:00
if (updateFields.description) {
fields.description = updateFields.description as string;
2019-11-29 14:30:00 -08:00
}
if (updateFields.customFieldsUi) {
const customFields = (updateFields.customFieldsUi as IDataObject)
.customFieldsValues as IDataObject[];
if (customFields) {
// resolve resource locator fieldId value
customFields.forEach((cf) => {
if (typeof cf.fieldId !== 'string') {
cf.fieldId = ((cf.fieldId as IDataObject).value as string).trim();
}
});
const data = customFields.reduce(
(obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }),
{},
);
Object.assign(fields, data);
}
}
const issueTypes = await jiraSoftwareCloudApiRequest.call(
this,
'/api/2/issuetype',
'GET',
body,
);
2019-11-29 14:30:00 -08:00
const subtaskIssues = [];
for (const issueType of issueTypes) {
if (issueType.subtask) {
subtaskIssues.push(issueType.id);
}
}
if (!updateFields.parentIssueKey && subtaskIssues.includes(updateFields.issueType)) {
throw new NodeOperationError(
this.getNode(),
'You must define a Parent Issue Key when Issue type is sub-task',
{ itemIndex: i },
);
} else if (
updateFields.parentIssueKey &&
subtaskIssues.includes(updateFields.issueType)
) {
2019-11-29 14:30:00 -08:00
fields.parent = {
2019-12-01 13:47:53 -08:00
key: (updateFields.parentIssueKey as string).toUpperCase(),
2019-11-29 14:30:00 -08:00
};
}
body.fields = fields;
2020-04-23 22:59:19 -07:00
if (updateFields.statusId) {
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/2/issue/${issueKey}/transitions`,
'POST',
{ transition: { id: updateFields.statusId } },
);
2019-11-29 14:30:00 -08:00
}
2020-04-23 22:59:19 -07:00
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/2/issue/${issueKey}`,
'PUT',
body,
);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray({ success: true }),
{ itemData: { item: i } },
);
returnData.push(...executionData);
2019-11-29 14:30:00 -08:00
}
}
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-get
if (operation === 'get') {
for (let i = 0; i < length; i++) {
2019-11-29 14:30:00 -08:00
const issueKey = this.getNodeParameter('issueKey', i) as string;
const simplifyOutput = this.getNodeParameter('simplifyOutput', i) as boolean;
const additionalFields = this.getNodeParameter('additionalFields', i);
2019-12-01 13:47:53 -08:00
if (additionalFields.fields) {
qs.fields = additionalFields.fields as string;
}
if (additionalFields.fieldsByKey) {
qs.fieldsByKey = additionalFields.fieldsByKey as boolean;
}
if (additionalFields.expand) {
qs.expand = additionalFields.expand as string;
}
if (simplifyOutput) {
qs.expand = `${qs.expand || ''},names`;
}
2019-12-01 13:47:53 -08:00
if (additionalFields.properties) {
qs.properties = additionalFields.properties as string;
}
if (additionalFields.updateHistory) {
qs.updateHistory = additionalFields.updateHistory as string;
}
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/2/issue/${issueKey}`,
'GET',
{},
qs,
);
if (simplifyOutput) {
// Use rendered fields if requested and available
qs.expand = qs.expand || '';
if (
(qs.expand as string).toLowerCase().indexOf('renderedfields') !== -1 &&
responseData.renderedFields &&
Object.keys(responseData.renderedFields).length
) {
responseData.fields = mergeWith(
responseData.fields,
responseData.renderedFields,
(a, b) => (b === null ? a : b),
);
}
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(simplifyIssueOutput(responseData)),
{ itemData: { item: i } },
);
returnData.push(...executionData);
} else {
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
}
2019-11-29 14:30:00 -08:00
}
}
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-search-post
if (operation === 'getAll') {
for (let i = 0; i < length; i++) {
const returnAll = this.getNodeParameter('returnAll', i);
const options = this.getNodeParameter('options', i);
2020-02-02 07:01:56 -08:00
const body: IDataObject = {};
if (options.fields) {
body.fields = (options.fields as string).split(',');
2020-02-02 07:01:56 -08:00
}
if (options.jql) {
body.jql = options.jql as string;
}
if (options.expand) {
if (typeof options.expand === 'string') {
body.expand = options.expand.split(',');
} else {
body.expand = options.expand;
}
2020-02-02 07:01:56 -08:00
}
if (returnAll) {
responseData = await jiraSoftwareCloudApiRequestAllItems.call(
this,
'issues',
'/api/2/search',
'POST',
body,
);
2020-02-02 07:01:56 -08:00
} else {
const limit = this.getNodeParameter('limit', i);
2020-02-02 07:01:56 -08:00
body.maxResults = limit;
responseData = await jiraSoftwareCloudApiRequest.call(
this,
'/api/2/search',
'POST',
body,
);
2020-02-02 07:01:56 -08:00
responseData = responseData.issues;
}
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
2020-02-02 07:01:56 -08:00
}
}
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-changelog-get
if (operation === 'changelog') {
for (let i = 0; i < length; i++) {
2019-11-29 14:30:00 -08:00
const issueKey = this.getNodeParameter('issueKey', i) as string;
const returnAll = this.getNodeParameter('returnAll', i);
2020-04-23 22:59:19 -07:00
if (returnAll) {
responseData = await jiraSoftwareCloudApiRequestAllItems.call(
this,
'values',
`/api/2/issue/${issueKey}/changelog`,
'GET',
);
2020-04-23 22:59:19 -07:00
} else {
qs.maxResults = this.getNodeParameter('limit', i);
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/2/issue/${issueKey}/changelog`,
'GET',
{},
qs,
);
2020-04-23 22:59:19 -07:00
responseData = responseData.values;
2019-11-29 14:30:00 -08:00
}
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
2019-11-29 14:30:00 -08:00
}
}
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-notify-post
if (operation === 'notify') {
for (let i = 0; i < length; i++) {
2019-11-29 14:30:00 -08:00
const issueKey = this.getNodeParameter('issueKey', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i);
const jsonActive = this.getNodeParameter('jsonParameters', 0);
2019-11-29 14:30:00 -08:00
const body: INotify = {};
2019-12-01 13:47:53 -08:00
if (additionalFields.textBody) {
body.textBody = additionalFields.textBody as string;
}
if (additionalFields.htmlBody) {
body.htmlBody = additionalFields.htmlBody as string;
}
2019-11-29 14:30:00 -08:00
if (!jsonActive) {
const notificationRecipientsValues = (
this.getNodeParameter('notificationRecipientsUi', i) as IDataObject
).notificationRecipientsValues as IDataObject;
2019-11-29 14:30:00 -08:00
const notificationRecipients: INotificationRecipients = {};
if (notificationRecipientsValues) {
if (notificationRecipientsValues.reporter) {
notificationRecipients.reporter = notificationRecipientsValues.reporter as boolean;
}
2019-11-29 14:30:00 -08:00
if (notificationRecipientsValues.assignee) {
notificationRecipients.assignee = notificationRecipientsValues.assignee as boolean;
}
2019-11-29 14:30:00 -08:00
if (notificationRecipientsValues.assignee) {
notificationRecipients.watchers = notificationRecipientsValues.watchers as boolean;
}
2019-11-29 14:30:00 -08:00
if (notificationRecipientsValues.voters) {
notificationRecipients.watchers = notificationRecipientsValues.voters as boolean;
}
if (((notificationRecipientsValues.users as IDataObject[]) || []).length > 0) {
notificationRecipients.users = (
notificationRecipientsValues.users as IDataObject[]
).map((user) => {
2019-11-29 14:30:00 -08:00
return {
2020-10-22 06:46:03 -07:00
accountId: user,
2019-11-29 14:30:00 -08:00
};
});
}
if (((notificationRecipientsValues.groups as IDataObject[]) || []).length > 0) {
notificationRecipients.groups = (
notificationRecipientsValues.groups as IDataObject[]
).map((group) => {
2019-11-29 14:30:00 -08:00
return {
2020-10-22 06:46:03 -07:00
name: group,
2019-11-29 14:30:00 -08:00
};
});
}
}
body.to = notificationRecipients;
const notificationRecipientsRestrictionsValues = (
this.getNodeParameter('notificationRecipientsRestrictionsUi', i) as IDataObject
).notificationRecipientsRestrictionsValues as IDataObject;
2019-11-29 14:30:00 -08:00
const notificationRecipientsRestrictions: NotificationRecipientsRestrictions = {};
if (notificationRecipientsRestrictionsValues) {
if (
((notificationRecipientsRestrictionsValues.groups as IDataObject[]) || []).length >
0
) {
notificationRecipientsRestrictions.groups = (
notificationRecipientsRestrictionsValues.groups as IDataObject[]
).map((group) => {
return {
name: group,
};
});
2019-11-29 14:30:00 -08:00
}
}
body.restrict = notificationRecipientsRestrictions;
} else {
const notificationRecipientsJson = validateJSON(
this.getNodeParameter('notificationRecipientsJson', i) as string,
);
2019-11-29 14:30:00 -08:00
if (notificationRecipientsJson) {
body.to = notificationRecipientsJson;
}
const notificationRecipientsRestrictionsJson = validateJSON(
this.getNodeParameter('notificationRecipientsRestrictionsJson', i) as string,
);
2019-11-29 14:30:00 -08:00
if (notificationRecipientsRestrictionsJson) {
body.restrict = notificationRecipientsRestrictionsJson;
}
}
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/2/issue/${issueKey}/notify`,
'POST',
body,
qs,
);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
2019-11-29 14:30:00 -08:00
}
}
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-transitions-get
if (operation === 'transitions') {
for (let i = 0; i < length; i++) {
2019-11-29 14:30:00 -08:00
const issueKey = this.getNodeParameter('issueKey', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i);
2019-12-01 13:47:53 -08:00
if (additionalFields.transitionId) {
qs.transitionId = additionalFields.transitionId as string;
2019-11-29 14:30:00 -08:00
}
2019-12-01 13:47:53 -08:00
if (additionalFields.expand) {
qs.expand = additionalFields.expand as string;
}
if (additionalFields.skipRemoteOnlyCondition) {
qs.skipRemoteOnlyCondition = additionalFields.skipRemoteOnlyCondition as boolean;
2019-11-29 14:30:00 -08:00
}
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/2/issue/${issueKey}/transitions`,
'GET',
{},
qs,
);
2020-04-23 22:59:19 -07:00
responseData = responseData.transitions;
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
2019-11-29 14:30:00 -08:00
}
}
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-delete
if (operation === 'delete') {
for (let i = 0; i < length; i++) {
2019-11-29 14:30:00 -08:00
const issueKey = this.getNodeParameter('issueKey', i) as string;
const deleteSubtasks = this.getNodeParameter('deleteSubtasks', i) as boolean;
qs.deleteSubtasks = deleteSubtasks;
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/2/issue/${issueKey}`,
'DELETE',
{},
qs,
);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray({ success: true }),
{ itemData: { item: i } },
);
returnData.push(...executionData);
2019-11-29 14:30:00 -08:00
}
2019-11-27 14:42:28 -08:00
}
}
if (resource === 'issueAttachment') {
const apiVersion = jiraVersion === 'server' ? '2' : ('3' as string);
//https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post
if (operation === 'add') {
for (let i = 0; i < length; i++) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const issueKey = this.getNodeParameter('issueKey', i) as string;
if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const item = items[i].binary as IBinaryKeyData;
const binaryData = item[binaryPropertyName];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/${apiVersion}/issue/${issueKey}/attachments`,
'POST',
{},
{},
undefined,
{
formData: {
file: {
value: binaryDataBuffer,
options: {
filename: binaryData.fileName,
},
},
},
},
);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
}
}
//https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-attachment-id-delete
if (operation === 'remove') {
for (let i = 0; i < length; i++) {
const attachmentId = this.getNodeParameter('attachmentId', i) as string;
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/${apiVersion}/attachment/${attachmentId}`,
'DELETE',
{},
qs,
);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray({ success: true }),
{ itemData: { item: i } },
);
returnData.push(...executionData);
}
}
//https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-attachment-id-get
if (operation === 'get') {
const download = this.getNodeParameter('download', 0);
for (let i = 0; i < length; i++) {
const attachmentId = this.getNodeParameter('attachmentId', i) as string;
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/${apiVersion}/attachment/${attachmentId}`,
'GET',
{},
qs,
);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
}
if (download) {
const binaryPropertyName = this.getNodeParameter('binaryProperty', 0);
for (const [index, attachment] of returnData.entries()) {
returnData[index].binary = {};
const buffer = await jiraSoftwareCloudApiRequest.call(
this,
'',
'GET',
{},
{},
attachment?.json.content as string,
{ json: false, encoding: null },
);
(returnData[index].binary as IBinaryKeyData)[binaryPropertyName] =
await this.helpers.prepareBinaryData(
buffer,
attachment.json.filename as string,
attachment.json.mimeType as string,
);
}
}
}
if (operation === 'getAll') {
const download = this.getNodeParameter('download', 0);
for (let i = 0; i < length; i++) {
const issueKey = this.getNodeParameter('issueKey', i) as string;
const returnAll = this.getNodeParameter('returnAll', i);
const {
fields: { attachment },
} = await jiraSoftwareCloudApiRequest.call(
this,
`/api/2/issue/${issueKey}`,
'GET',
{},
qs,
);
responseData = attachment;
if (!returnAll) {
const limit = this.getNodeParameter('limit', i);
responseData = responseData.slice(0, limit);
}
responseData = responseData.map((data: IDataObject) => ({ json: data }));
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
}
if (download) {
const binaryPropertyName = this.getNodeParameter('binaryProperty', 0);
for (const [index, attachment] of returnData.entries()) {
returnData[index].binary = {};
const buffer = await jiraSoftwareCloudApiRequest.call(
this,
'',
'GET',
{},
{},
attachment.json.content as string,
{ json: false, encoding: null },
);
(returnData[index].binary as IBinaryKeyData)[binaryPropertyName] =
await this.helpers.prepareBinaryData(
buffer,
attachment.json.filename as string,
attachment.json.mimeType as string,
);
}
}
}
}
if (resource === 'issueComment') {
const apiVersion = jiraVersion === 'server' ? '2' : ('3' as string);
//https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-comments/#api-rest-api-3-issue-issueidorkey-comment-post
if (operation === 'add') {
for (let i = 0; i < length; i++) {
const jsonParameters = this.getNodeParameter('jsonParameters', 0);
const issueKey = this.getNodeParameter('issueKey', i) as string;
const options = this.getNodeParameter('options', i);
const body: IDataObject = {};
if (options.expand) {
qs.expand = options.expand as string;
delete options.expand;
}
Object.assign(body, options);
if (!jsonParameters) {
const comment = this.getNodeParameter('comment', i) as string;
if (jiraVersion === 'server') {
Object.assign(body, { body: comment });
} else {
Object.assign(body, {
body: {
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: comment,
},
],
},
],
},
});
}
} else {
const commentJson = this.getNodeParameter('commentJson', i) as string;
const json = validateJSON(commentJson);
if (json === '') {
throw new NodeOperationError(this.getNode(), 'Document Format must be a valid JSON', {
itemIndex: i,
});
}
Object.assign(body, { body: json });
}
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/${apiVersion}/issue/${issueKey}/comment`,
'POST',
body,
qs,
);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
}
}
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-get
if (operation === 'get') {
for (let i = 0; i < length; i++) {
const issueKey = this.getNodeParameter('issueKey', i) as string;
const commentId = this.getNodeParameter('commentId', i) as string;
const options = this.getNodeParameter('options', i);
Object.assign(qs, options);
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/${apiVersion}/issue/${issueKey}/comment/${commentId}`,
'GET',
{},
qs,
);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
}
}
//https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-comments/#api-rest-api-3-issue-issueidorkey-comment-get
if (operation === 'getAll') {
for (let i = 0; i < length; i++) {
const issueKey = this.getNodeParameter('issueKey', i) as string;
const returnAll = this.getNodeParameter('returnAll', i);
const options = this.getNodeParameter('options', i);
const body: IDataObject = {};
Object.assign(qs, options);
if (returnAll) {
responseData = await jiraSoftwareCloudApiRequestAllItems.call(
this,
'comments',
`/api/${apiVersion}/issue/${issueKey}/comment`,
'GET',
body,
qs,
);
} else {
const limit = this.getNodeParameter('limit', i);
body.maxResults = limit;
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/${apiVersion}/issue/${issueKey}/comment`,
'GET',
body,
qs,
);
responseData = responseData.comments;
}
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
}
}
//https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-comments/#api-rest-api-3-issue-issueidorkey-comment-id-delete
if (operation === 'remove') {
for (let i = 0; i < length; i++) {
const issueKey = this.getNodeParameter('issueKey', i) as string;
const commentId = this.getNodeParameter('commentId', i) as string;
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/${apiVersion}/issue/${issueKey}/comment/${commentId}`,
'DELETE',
{},
qs,
);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray({ success: true }),
{ itemData: { item: i } },
);
returnData.push(...executionData);
}
}
//https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-comments/#api-rest-api-3-issue-issueidorkey-comment-id-put
if (operation === 'update') {
for (let i = 0; i < length; i++) {
const issueKey = this.getNodeParameter('issueKey', i) as string;
const commentId = this.getNodeParameter('commentId', i) as string;
const options = this.getNodeParameter('options', i);
const jsonParameters = this.getNodeParameter('jsonParameters', 0);
const body: IDataObject = {};
if (options.expand) {
qs.expand = options.expand as string;
delete options.expand;
}
Object.assign(qs, options);
if (!jsonParameters) {
const comment = this.getNodeParameter('comment', i) as string;
if (jiraVersion === 'server') {
Object.assign(body, { body: comment });
} else {
Object.assign(body, {
body: {
type: 'doc',
version: 1,
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: comment,
},
],
},
],
},
});
}
} else {
const commentJson = this.getNodeParameter('commentJson', i) as string;
const json = validateJSON(commentJson);
if (json === '') {
throw new NodeOperationError(this.getNode(), 'Document Format must be a valid JSON', {
itemIndex: i,
});
}
Object.assign(body, { body: json });
}
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/${apiVersion}/issue/${issueKey}/comment/${commentId}`,
'PUT',
body,
qs,
);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
}
}
2019-11-27 14:42:28 -08:00
}
if (resource === 'user') {
const apiVersion = jiraVersion === 'server' ? '2' : ('3' as string);
if (operation === 'create') {
// https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-users/#api-rest-api-3-user-post
for (let i = 0; i < length; i++) {
const body = {
name: this.getNodeParameter('username', i),
emailAddress: this.getNodeParameter('emailAddress', i),
displayName: this.getNodeParameter('displayName', i),
};
const additionalFields = this.getNodeParameter('additionalFields', i);
Object.assign(body, additionalFields);
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/${apiVersion}/user`,
'POST',
body,
{},
);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
}
} else if (operation === 'delete') {
// https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-users/#api-rest-api-3-user-delete
for (let i = 0; i < length; i++) {
qs.accountId = this.getNodeParameter('accountId', i);
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/${apiVersion}/user`,
'DELETE',
{},
qs,
);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray({ success: true }),
{ itemData: { item: i } },
);
returnData.push(...executionData);
}
} else if (operation === 'get') {
// https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-users/#api-rest-api-3-user-get
for (let i = 0; i < length; i++) {
qs.accountId = this.getNodeParameter('accountId', i);
const { expand } = this.getNodeParameter('additionalFields', i) as { expand: string[] };
if (expand) {
qs.expand = expand.join(',');
}
responseData = await jiraSoftwareCloudApiRequest.call(
this,
`/api/${apiVersion}/user`,
'GET',
{},
qs,
);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData),
{ itemData: { item: i } },
);
returnData.push(...executionData);
}
}
}
return this.prepareOutputData(returnData);
2019-11-26 12:38:38 -08:00
}
}