2022-08-17 08:50:24 -07:00
|
|
|
import { mergeWith } from 'lodash';
|
2022-07-04 02:43:37 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { IExecuteFunctions } from 'n8n-core';
|
2020-04-23 22:59:19 -07:00
|
|
|
|
2019-11-26 12:38:38 -08:00
|
|
|
import {
|
2021-01-29 11:08:27 -08:00
|
|
|
IBinaryKeyData,
|
2019-11-26 12:38:38 -08:00
|
|
|
IDataObject,
|
|
|
|
ILoadOptionsFunctions,
|
2020-04-23 22:59:19 -07:00
|
|
|
INodeExecutionData,
|
2019-11-26 12:38:38 -08:00
|
|
|
INodePropertyOptions,
|
2020-04-23 22:59:19 -07:00
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
2021-04-16 09:33:36 -07:00
|
|
|
NodeOperationError,
|
2019-11-26 12:38:38 -08:00
|
|
|
} from 'n8n-workflow';
|
2020-04-23 22:59:19 -07:00
|
|
|
|
2019-11-26 12:38:38 -08:00
|
|
|
import {
|
2019-11-27 22:10:41 -08:00
|
|
|
jiraSoftwareCloudApiRequest,
|
|
|
|
jiraSoftwareCloudApiRequestAllItems,
|
2022-03-27 02:49:47 -07:00
|
|
|
simplifyIssueOutput,
|
2019-11-26 12:38:38 -08:00
|
|
|
validateJSON,
|
|
|
|
} from './GenericFunctions';
|
2020-04-23 22:59:19 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { issueAttachmentFields, issueAttachmentOperations } from './IssueAttachmentDescription';
|
2021-01-29 11:08:27 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { issueCommentFields, issueCommentOperations } from './IssueCommentDescription';
|
2020-12-29 02:33:13 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { issueFields, issueOperations } from './IssueDescription';
|
2020-04-23 22:59:19 -07:00
|
|
|
|
2019-11-27 22:10:41 -08:00
|
|
|
import {
|
|
|
|
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,
|
2021-01-29 11:08:27 -08:00
|
|
|
} from './IssueInterface';
|
2019-11-26 12:38:38 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { userFields, userOperations } from './UserDescription';
|
2021-02-21 02:00:27 -08:00
|
|
|
|
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',
|
2021-01-29 11:08:27 -08:00
|
|
|
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: [
|
|
|
|
{
|
2019-11-27 22:10:41 -08:00
|
|
|
name: 'jiraSoftwareCloudApi',
|
2019-11-26 12:38:38 -08:00
|
|
|
required: true,
|
2020-02-02 07:01:56 -08:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
jiraVersion: ['cloud'],
|
2020-02-02 07:01:56 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'jiraSoftwareServerApi',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
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',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2019-11-26 12:38:38 -08:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Issue',
|
|
|
|
value: 'issue',
|
2022-08-17 08:50:24 -07:00
|
|
|
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
|
|
|
},
|
2021-01-29 11:08:27 -08:00
|
|
|
{
|
|
|
|
name: 'Issue Attachment',
|
|
|
|
value: 'issueAttachment',
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'Add, remove, and get an attachment from an issue',
|
2021-01-29 11:08:27 -08:00
|
|
|
},
|
2020-12-29 02:33:13 -08:00
|
|
|
{
|
|
|
|
name: 'Issue Comment',
|
|
|
|
value: 'issueComment',
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'Get, create, update, and delete a comment from an issue',
|
2020-12-29 02:33:13 -08:00
|
|
|
},
|
2021-02-21 02:00:27 -08:00
|
|
|
{
|
|
|
|
name: 'User',
|
|
|
|
value: 'user',
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'Get, create and delete a user',
|
2021-02-21 02:00:27 -08:00
|
|
|
},
|
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,
|
2021-01-29 11:08:27 -08:00
|
|
|
...issueAttachmentOperations,
|
|
|
|
...issueAttachmentFields,
|
2020-12-29 02:33:13 -08:00
|
|
|
...issueCommentOperations,
|
|
|
|
...issueCommentFields,
|
2021-02-21 02:00:27 -08:00
|
|
|
...userOperations,
|
|
|
|
...userFields,
|
2019-11-26 12:38:38 -08:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2019-11-27 14:42:28 -08:00
|
|
|
methods = {
|
|
|
|
loadOptions: {
|
|
|
|
// Get all the projects to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getProjects(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2020-05-04 10:35:02 -07:00
|
|
|
const jiraVersion = this.getCurrentNodeParameter('jiraVersion') as string;
|
2020-11-09 22:43:39 -08:00
|
|
|
let endpoint = '';
|
|
|
|
let projects;
|
2020-05-04 10:35:02 -07:00
|
|
|
|
|
|
|
if (jiraVersion === 'server') {
|
2020-07-25 01:22:02 -07:00
|
|
|
endpoint = '/api/2/project';
|
2020-11-09 22:43:39 -08:00
|
|
|
projects = await jiraSoftwareCloudApiRequest.call(this, endpoint, 'GET');
|
|
|
|
} else {
|
|
|
|
endpoint = '/api/2/project/search';
|
2022-08-17 08:50:24 -07:00
|
|
|
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
|
|
|
|
|
|
|
returnData.sort((a, b) => {
|
2022-08-17 08:50:24 -07:00
|
|
|
if (a.name < b.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.name > b.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
2020-11-09 22:49:43 -08:00
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
2019-11-27 14:42:28 -08:00
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Get all the issue types to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getIssueTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
2020-04-23 22:59:19 -07:00
|
|
|
const projectId = this.getCurrentNodeParameter('project');
|
2019-11-27 14:42:28 -08:00
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2022-08-17 08:50:24 -07:00
|
|
|
const { issueTypes } = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/2/project/${projectId}`,
|
|
|
|
'GET',
|
|
|
|
);
|
2021-04-09 23:05:21 -07:00
|
|
|
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) => {
|
2022-08-17 08:50:24 -07:00
|
|
|
if (a.name < b.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.name > b.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
2020-11-09 22:49:43 -08:00
|
|
|
return 0;
|
|
|
|
});
|
2019-11-27 14:42:28 -08:00
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
|
|
|
|
// 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[] = [];
|
2020-04-23 22:59:19 -07:00
|
|
|
|
2020-07-25 01:22:02 -07:00
|
|
|
const labels = await jiraSoftwareCloudApiRequest.call(this, '/api/2/label', 'GET');
|
2020-04-23 22:59:19 -07:00
|
|
|
|
2019-11-27 14:42:28 -08:00
|
|
|
for (const label of labels.values) {
|
|
|
|
const labelName = label;
|
|
|
|
const labelId = label;
|
|
|
|
|
|
|
|
returnData.push({
|
|
|
|
name: labelName,
|
|
|
|
value: labelId,
|
|
|
|
});
|
|
|
|
}
|
2020-11-09 22:49:43 -08:00
|
|
|
|
|
|
|
returnData.sort((a, b) => {
|
2022-08-17 08:50:24 -07:00
|
|
|
if (a.name < b.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.name > b.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
2020-11-09 22:49:43 -08:00
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
2019-11-27 14:42:28 -08:00
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Get all the priorities to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getPriorities(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2020-04-23 22:59:19 -07:00
|
|
|
|
2020-07-25 01:22:02 -07:00
|
|
|
const priorities = await jiraSoftwareCloudApiRequest.call(this, '/api/2/priority', 'GET');
|
2020-04-23 22:59:19 -07:00
|
|
|
|
2019-11-27 14:42:28 -08:00
|
|
|
for (const priority of priorities) {
|
|
|
|
const priorityName = priority.name;
|
|
|
|
const priorityId = priority.id;
|
|
|
|
|
|
|
|
returnData.push({
|
|
|
|
name: priorityName,
|
|
|
|
value: priorityId,
|
|
|
|
});
|
|
|
|
}
|
2020-11-09 22:49:43 -08:00
|
|
|
|
|
|
|
returnData.sort((a, b) => {
|
2022-08-17 08:50:24 -07:00
|
|
|
if (a.name < b.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.name > b.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
2020-11-09 22:49:43 -08:00
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
2019-11-27 14:42:28 -08:00
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Get all the users to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
2020-05-05 13:56:24 -07:00
|
|
|
const jiraVersion = this.getCurrentNodeParameter('jiraVersion') as string;
|
2022-03-27 02:49:47 -07:00
|
|
|
const query: IDataObject = {};
|
|
|
|
let endpoint = '/api/2/users/search';
|
2020-05-05 13:56:24 -07:00
|
|
|
|
2022-03-27 02:49:47 -07:00
|
|
|
if (jiraVersion === 'server') {
|
|
|
|
endpoint = '/api/2/user/search';
|
2022-08-17 08:50:24 -07:00
|
|
|
query.username = "'";
|
2022-03-27 02:49:47 -07:00
|
|
|
}
|
2020-04-23 22:59:19 -07:00
|
|
|
|
2022-03-27 02:49:47 -07:00
|
|
|
const users = await jiraSoftwareCloudApiRequest.call(this, endpoint, 'GET', {}, query);
|
2019-11-27 14:42:28 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
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;
|
|
|
|
});
|
2019-11-27 14:42:28 -08:00
|
|
|
},
|
2019-11-29 14:30:00 -08:00
|
|
|
|
|
|
|
// 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[] = [];
|
2020-04-23 22:59:19 -07:00
|
|
|
|
2020-07-25 01:22:02 -07:00
|
|
|
const groups = await jiraSoftwareCloudApiRequest.call(this, '/api/2/groups/picker', 'GET');
|
2020-04-23 22:59:19 -07:00
|
|
|
|
2019-11-29 14:30:00 -08:00
|
|
|
for (const group of groups.groups) {
|
|
|
|
const groupName = group.name;
|
|
|
|
const groupId = group.name;
|
|
|
|
|
|
|
|
returnData.push({
|
|
|
|
name: groupName,
|
|
|
|
value: groupId,
|
|
|
|
});
|
|
|
|
}
|
2020-11-09 22:49:43 -08:00
|
|
|
|
|
|
|
returnData.sort((a, b) => {
|
2022-08-17 08:50:24 -07:00
|
|
|
if (a.name < b.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.name > b.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
2020-11-09 22:49:43 -08:00
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
2019-11-29 14:30:00 -08:00
|
|
|
return returnData;
|
2020-04-24 00:50:56 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// Get all the groups to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getTransitions(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
|
|
|
|
const issueKey = this.getCurrentNodeParameter('issueKey');
|
2022-08-17 08:50:24 -07:00
|
|
|
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) => {
|
2022-08-17 08:50:24 -07:00
|
|
|
if (a.name < b.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.name > b.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
2020-11-09 22:49:43 -08:00
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
2020-04-24 00:50:56 -07:00
|
|
|
return returnData;
|
|
|
|
},
|
2021-01-29 11:08:27 -08:00
|
|
|
|
|
|
|
// Get all the custom fields to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getCustomFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const operation = this.getCurrentNodeParameter('operation') as string;
|
2021-06-13 08:30:05 -07:00
|
|
|
let projectId: string;
|
|
|
|
let issueTypeId: string;
|
2021-01-29 11:08:27 -08:00
|
|
|
if (operation === 'create') {
|
2021-06-13 08:30:05 -07:00
|
|
|
projectId = this.getCurrentNodeParameter('project') as string;
|
|
|
|
issueTypeId = this.getCurrentNodeParameter('issueType') as string;
|
2021-01-29 11:08:27 -08:00
|
|
|
} else {
|
2021-06-13 08:30:05 -07:00
|
|
|
const issueKey = this.getCurrentNodeParameter('issueKey') as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
const res = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/2/issue/${issueKey}`,
|
|
|
|
'GET',
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
);
|
2021-06-13 08:30:05 -07:00
|
|
|
projectId = res.fields.project.id;
|
|
|
|
issueTypeId = res.fields.issuetype.id;
|
2021-01-29 11:08:27 -08:00
|
|
|
}
|
2021-06-13 08:30:05 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const res = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/2/issue/createmeta?projectIds=${projectId}&issueTypeIds=${issueTypeId}&expand=projects.issuetypes.fields`,
|
|
|
|
'GET',
|
|
|
|
);
|
|
|
|
|
|
|
|
const fields = res.projects
|
2022-12-02 06:25:21 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
.find((o: any) => o.id === projectId)
|
2022-12-02 06:25:21 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
.issuetypes.find((o: any) => o.id === issueTypeId).fields;
|
2021-06-13 08:30:05 -07:00
|
|
|
for (const key of Object.keys(fields)) {
|
|
|
|
const field = fields[key];
|
|
|
|
if (field.schema && Object.keys(field.schema).includes('customId')) {
|
2022-03-27 02:49:47 -07:00
|
|
|
returnData.push({
|
|
|
|
name: field.name,
|
|
|
|
value: field.key || field.fieldId,
|
|
|
|
});
|
2021-01-29 11:08:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2021-11-19 06:46:48 -08:00
|
|
|
|
|
|
|
// 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');
|
2022-08-17 08:50:24 -07:00
|
|
|
const { values: components } = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/2/project/${project}/component`,
|
|
|
|
'GET',
|
|
|
|
);
|
2021-11-19 06:46:48 -08:00
|
|
|
|
|
|
|
for (const component of components) {
|
|
|
|
returnData.push({
|
|
|
|
name: component.name,
|
|
|
|
value: component.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
returnData.sort((a, b) => {
|
2022-08-17 08:50:24 -07:00
|
|
|
if (a.name < b.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.name > b.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
2021-11-19 06:46:48 -08:00
|
|
|
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();
|
2022-08-30 08:55:33 -07:00
|
|
|
const returnData: INodeExecutionData[] = [];
|
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
|
|
|
|
2022-12-02 03:53:59 -08:00
|
|
|
const resource = this.getNodeParameter('resource', 0);
|
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2020-05-01 20:08:39 -07:00
|
|
|
const jiraVersion = this.getNodeParameter('jiraVersion', 0) as string;
|
|
|
|
|
2021-01-29 11:08:27 -08:00
|
|
|
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) as string;
|
|
|
|
const issueTypeId = this.getNodeParameter('issueType', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2019-11-27 22:10:41 -08:00
|
|
|
const body: IIssue = {};
|
|
|
|
const fields: IFields = {
|
|
|
|
summary,
|
|
|
|
project: {
|
|
|
|
id: projectId,
|
|
|
|
},
|
|
|
|
issuetype: {
|
|
|
|
id: issueTypeId,
|
|
|
|
},
|
2019-11-27 14:42:28 -08:00
|
|
|
};
|
|
|
|
if (additionalFields.labels) {
|
2019-11-27 22:10:41 -08:00
|
|
|
fields.labels = additionalFields.labels as string[];
|
2019-11-27 14:42:28 -08:00
|
|
|
}
|
2020-05-04 21:07:19 -07:00
|
|
|
if (additionalFields.serverLabels) {
|
|
|
|
fields.labels = additionalFields.serverLabels as string[];
|
|
|
|
}
|
2019-11-27 14:42:28 -08:00
|
|
|
if (additionalFields.priority) {
|
2019-11-27 22:10:41 -08:00
|
|
|
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') {
|
2020-05-01 20:08:39 -07:00
|
|
|
fields.assignee = {
|
|
|
|
name: additionalFields.assignee as string,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
fields.assignee = {
|
|
|
|
id: additionalFields.assignee as string,
|
|
|
|
};
|
|
|
|
}
|
2019-11-27 14:42:28 -08:00
|
|
|
}
|
2021-04-02 06:31:25 -07:00
|
|
|
if (additionalFields.reporter) {
|
2021-12-11 08:47:35 -08:00
|
|
|
if (jiraVersion === 'server') {
|
|
|
|
fields.reporter = {
|
|
|
|
name: additionalFields.reporter as string,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
fields.reporter = {
|
|
|
|
id: additionalFields.reporter as string,
|
|
|
|
};
|
|
|
|
}
|
2021-04-02 06:31:25 -07:00
|
|
|
}
|
2019-11-27 22:10:41 -08:00
|
|
|
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;
|
|
|
|
}
|
2021-11-19 06:46:48 -08:00
|
|
|
if (additionalFields.componentIds) {
|
2022-08-17 08:50:24 -07:00
|
|
|
fields.components = (additionalFields.componentIds as string[]).map((id) => ({ id }));
|
2021-11-19 06:46:48 -08:00
|
|
|
}
|
2021-01-29 11:08:27 -08:00
|
|
|
if (additionalFields.customFieldsUi) {
|
2022-08-17 08:50:24 -07:00
|
|
|
const customFields = (additionalFields.customFieldsUi as IDataObject)
|
|
|
|
.customFieldsValues as IDataObject[];
|
2021-01-29 11:08:27 -08:00
|
|
|
if (customFields) {
|
2022-08-17 08:50:24 -07:00
|
|
|
const data = customFields.reduce(
|
|
|
|
(obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }),
|
|
|
|
{},
|
|
|
|
);
|
2021-01-29 11:08:27 -08:00
|
|
|
Object.assign(fields, data);
|
|
|
|
}
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2022-08-17 08:50:24 -07: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
|
|
|
};
|
|
|
|
}
|
2019-11-27 22:10:41 -08:00
|
|
|
body.fields = fields;
|
2020-07-25 01:22:02 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(this, '/api/2/issue', 'POST', body);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2019-11-27 14:42:28 -08:00
|
|
|
}
|
2021-01-29 11:08:27 -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;
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
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[];
|
|
|
|
}
|
2020-05-04 21:07:19 -07:00
|
|
|
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') {
|
2020-05-01 20:08:39 -07:00
|
|
|
fields.assignee = {
|
|
|
|
name: updateFields.assignee as string,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
fields.assignee = {
|
|
|
|
id: updateFields.assignee as string,
|
|
|
|
};
|
|
|
|
}
|
2019-11-29 14:30:00 -08:00
|
|
|
}
|
2021-04-02 06:31:25 -07:00
|
|
|
if (updateFields.reporter) {
|
2021-12-11 08:47:35 -08:00
|
|
|
if (jiraVersion === 'server') {
|
|
|
|
fields.reporter = {
|
|
|
|
name: updateFields.reporter as string,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
fields.reporter = {
|
|
|
|
id: updateFields.reporter as string,
|
|
|
|
};
|
|
|
|
}
|
2021-04-02 06:31:25 -07:00
|
|
|
}
|
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
|
|
|
}
|
2021-01-29 11:08:27 -08:00
|
|
|
if (updateFields.customFieldsUi) {
|
2022-08-17 08:50:24 -07:00
|
|
|
const customFields = (updateFields.customFieldsUi as IDataObject)
|
|
|
|
.customFieldsValues as IDataObject[];
|
2021-01-29 11:08:27 -08:00
|
|
|
if (customFields) {
|
2022-08-17 08:50:24 -07:00
|
|
|
const data = customFields.reduce(
|
|
|
|
(obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }),
|
|
|
|
{},
|
|
|
|
);
|
2021-01-29 11:08:27 -08:00
|
|
|
Object.assign(fields, data);
|
|
|
|
}
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
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) {
|
2022-08-17 08:50:24 -07:00
|
|
|
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
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/2/issue/${issueKey}`,
|
|
|
|
'PUT',
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ success: true }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2019-11-29 14:30:00 -08:00
|
|
|
}
|
2021-01-29 11:08:27 -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;
|
2022-03-27 02:49:47 -07:00
|
|
|
const simplifyOutput = this.getNodeParameter('simplifyOutput', i) as boolean;
|
2022-11-18 07:29:44 -08:00
|
|
|
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;
|
|
|
|
}
|
2022-03-27 02:49:47 -07:00
|
|
|
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;
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/2/issue/${issueKey}`,
|
|
|
|
'GET',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2022-03-27 02:49:47 -07:00
|
|
|
|
|
|
|
if (simplifyOutput) {
|
2022-07-04 02:43:37 -07:00
|
|
|
// Use rendered fields if requested and available
|
|
|
|
qs.expand = qs.expand || '';
|
|
|
|
if (
|
|
|
|
(qs.expand as string).toLowerCase().indexOf('renderedfields') !== -1 &&
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData.renderedFields &&
|
|
|
|
Object.keys(responseData.renderedFields).length
|
2022-07-04 02:43:37 -07:00
|
|
|
) {
|
|
|
|
responseData.fields = mergeWith(
|
|
|
|
responseData.fields,
|
|
|
|
responseData.renderedFields,
|
2022-08-17 08:50:24 -07:00
|
|
|
(a, b) => (b === null ? a : b),
|
|
|
|
);
|
2022-07-04 02:43:37 -07:00
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(simplifyIssueOutput(responseData)),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2022-03-27 02:49:47 -07:00
|
|
|
} else {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2022-03-27 02:49:47 -07:00
|
|
|
}
|
2019-11-29 14:30:00 -08:00
|
|
|
}
|
2021-01-29 11:08:27 -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++) {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2020-02-02 07:01:56 -08:00
|
|
|
const body: IDataObject = {};
|
|
|
|
if (options.fields) {
|
2022-12-02 12:54:28 -08:00
|
|
|
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) {
|
2021-10-19 15:37:30 -07:00
|
|
|
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) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'issues',
|
|
|
|
`/api/2/search`,
|
|
|
|
'POST',
|
|
|
|
body,
|
|
|
|
);
|
2020-02-02 07:01:56 -08:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
const limit = this.getNodeParameter('limit', i);
|
2020-02-02 07:01:56 -08:00
|
|
|
body.maxResults = limit;
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/2/search`,
|
|
|
|
'POST',
|
|
|
|
body,
|
|
|
|
);
|
2020-02-02 07:01:56 -08:00
|
|
|
responseData = responseData.issues;
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2020-02-02 07:01:56 -08:00
|
|
|
}
|
2021-01-29 11:08:27 -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;
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2020-04-23 22:59:19 -07:00
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'values',
|
|
|
|
`/api/2/issue/${issueKey}/changelog`,
|
|
|
|
'GET',
|
|
|
|
);
|
2020-04-23 22:59:19 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.maxResults = this.getNodeParameter('limit', i);
|
2022-08-17 08:50:24 -07:00
|
|
|
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
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2019-11-29 14:30:00 -08:00
|
|
|
}
|
2021-01-29 11:08:27 -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;
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2022-12-02 12:54:28 -08:00
|
|
|
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) {
|
2022-08-17 08:50:24 -07:00
|
|
|
const notificationRecipientsValues = (
|
|
|
|
this.getNodeParameter('notificationRecipientsUi', i) as IDataObject
|
|
|
|
).notificationRecipientsValues as IDataObject[];
|
2019-11-29 14:30:00 -08:00
|
|
|
const notificationRecipients: INotificationRecipients = {};
|
|
|
|
if (notificationRecipientsValues) {
|
|
|
|
// @ts-ignore
|
|
|
|
if (notificationRecipientsValues.reporter) {
|
|
|
|
// @ts-ignore
|
|
|
|
notificationRecipients.reporter = notificationRecipientsValues.reporter as boolean;
|
|
|
|
}
|
|
|
|
// @ts-ignore
|
|
|
|
if (notificationRecipientsValues.assignee) {
|
|
|
|
// @ts-ignore
|
|
|
|
notificationRecipients.assignee = notificationRecipientsValues.assignee as boolean;
|
|
|
|
}
|
|
|
|
// @ts-ignore
|
|
|
|
if (notificationRecipientsValues.assignee) {
|
|
|
|
// @ts-ignore
|
|
|
|
notificationRecipients.watchers = notificationRecipientsValues.watchers as boolean;
|
|
|
|
}
|
|
|
|
// @ts-ignore
|
|
|
|
if (notificationRecipientsValues.voters) {
|
|
|
|
// @ts-ignore
|
|
|
|
notificationRecipients.watchers = notificationRecipientsValues.voters as boolean;
|
|
|
|
}
|
|
|
|
// @ts-ignore
|
|
|
|
if (notificationRecipientsValues.users.length > 0) {
|
|
|
|
// @ts-ignore
|
2022-08-17 08:50:24 -07:00
|
|
|
notificationRecipients.users = notificationRecipientsValues.users.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
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// @ts-ignore
|
|
|
|
if (notificationRecipientsValues.groups.length > 0) {
|
|
|
|
// @ts-ignore
|
2022-08-17 08:50:24 -07:00
|
|
|
notificationRecipients.groups = notificationRecipientsValues.groups.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;
|
2022-08-17 08:50:24 -07:00
|
|
|
const notificationRecipientsRestrictionsValues = (
|
|
|
|
this.getNodeParameter('notificationRecipientsRestrictionsUi', i) as IDataObject
|
|
|
|
).notificationRecipientsRestrictionsValues as IDataObject[];
|
2019-11-29 14:30:00 -08:00
|
|
|
const notificationRecipientsRestrictions: NotificationRecipientsRestrictions = {};
|
|
|
|
if (notificationRecipientsRestrictionsValues) {
|
|
|
|
// @ts-ignore
|
2021-01-29 11:08:27 -08:00
|
|
|
if (notificationRecipientsRestrictionsValues.groups.length > 0) {
|
2022-08-17 08:50:24 -07:00
|
|
|
notificationRecipientsRestrictions.groups =
|
|
|
|
// @ts-ignore
|
|
|
|
notificationRecipientsRestrictionsValues.groups.map((group) => {
|
|
|
|
return {
|
|
|
|
name: group,
|
|
|
|
};
|
|
|
|
});
|
2019-11-29 14:30:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
body.restrict = notificationRecipientsRestrictions;
|
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
const notificationRecipientsJson = validateJSON(
|
|
|
|
this.getNodeParameter('notificationRecipientsJson', i) as string,
|
|
|
|
);
|
2019-11-29 14:30:00 -08:00
|
|
|
if (notificationRecipientsJson) {
|
|
|
|
body.to = notificationRecipientsJson;
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
const notificationRecipientsRestrictionsJson = validateJSON(
|
|
|
|
this.getNodeParameter('notificationRecipientsRestrictionsJson', i) as string,
|
|
|
|
);
|
2019-11-29 14:30:00 -08:00
|
|
|
if (notificationRecipientsRestrictionsJson) {
|
|
|
|
body.restrict = notificationRecipientsRestrictionsJson;
|
|
|
|
}
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/2/issue/${issueKey}/notify`,
|
|
|
|
'POST',
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2019-11-29 14:30:00 -08:00
|
|
|
}
|
2021-01-29 11:08:27 -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;
|
2022-11-18 07:29:44 -08:00
|
|
|
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
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/2/issue/${issueKey}/transitions`,
|
|
|
|
'GET',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2020-04-23 22:59:19 -07:00
|
|
|
responseData = responseData.transitions;
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2019-11-29 14:30:00 -08:00
|
|
|
}
|
2021-01-29 11:08:27 -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;
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/2/issue/${issueKey}`,
|
|
|
|
'DELETE',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2021-01-29 11:08:27 -08:00
|
|
|
}
|
|
|
|
if (resource === 'issueAttachment') {
|
2022-08-17 08:50:24 -07:00
|
|
|
const apiVersion = jiraVersion === 'server' ? '2' : ('3' as string);
|
2021-06-08 20:26:27 -07:00
|
|
|
|
2021-01-29 11:08:27 -08:00
|
|
|
//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) as string;
|
|
|
|
const issueKey = this.getNodeParameter('issueKey', i) as string;
|
|
|
|
|
|
|
|
if (items[i].binary === undefined) {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
|
|
|
|
itemIndex: i,
|
|
|
|
});
|
2021-01-29 11:08:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const item = items[i].binary as IBinaryKeyData;
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
const binaryData = item[binaryPropertyName];
|
2021-08-20 09:08:40 -07:00
|
|
|
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
2021-01-29 11:08:27 -08:00
|
|
|
|
|
|
|
if (binaryData === undefined) {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`No binary data property "${binaryPropertyName}" does not exists on item!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-01-29 11:08:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
2021-06-08 20:26:27 -07:00
|
|
|
`/api/${apiVersion}/issue/${issueKey}/attachments`,
|
2021-01-29 11:08:27 -08:00
|
|
|
'POST',
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
undefined,
|
|
|
|
{
|
|
|
|
formData: {
|
|
|
|
file: {
|
2021-08-20 09:08:40 -07:00
|
|
|
value: binaryDataBuffer,
|
2021-01-29 11:08:27 -08:00
|
|
|
options: {
|
|
|
|
filename: binaryData.fileName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-01-29 11:08:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//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;
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/${apiVersion}/attachment/${attachmentId}`,
|
|
|
|
'DELETE',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ success: true }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-01-29 11:08:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-attachment-id-get
|
|
|
|
if (operation === 'get') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const download = this.getNodeParameter('download', 0);
|
2021-01-29 11:08:27 -08:00
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
const attachmentId = this.getNodeParameter('attachmentId', i) as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/${apiVersion}/attachment/${attachmentId}`,
|
|
|
|
'GET',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-01-29 11:08:27 -08:00
|
|
|
}
|
|
|
|
if (download) {
|
2022-12-02 03:53:59 -08:00
|
|
|
const binaryPropertyName = this.getNodeParameter('binaryProperty', 0);
|
2021-01-29 11:08:27 -08:00
|
|
|
for (const [index, attachment] of returnData.entries()) {
|
2022-12-02 12:54:28 -08:00
|
|
|
returnData[index].binary = {};
|
2022-08-17 08:50:24 -07:00
|
|
|
|
|
|
|
const buffer = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
'',
|
|
|
|
'GET',
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
// @ts-ignore
|
2022-12-02 12:54:28 -08:00
|
|
|
attachment?.json.content,
|
2022-08-17 08:50:24 -07:00
|
|
|
{ json: false, encoding: null },
|
|
|
|
);
|
2021-01-29 11:08:27 -08:00
|
|
|
//@ts-ignore
|
2022-12-02 12:54:28 -08:00
|
|
|
returnData[index].binary[binaryPropertyName] = await this.helpers.prepareBinaryData(
|
2022-08-17 08:50:24 -07:00
|
|
|
buffer,
|
|
|
|
// @ts-ignore
|
|
|
|
attachment.json.filename,
|
|
|
|
// @ts-ignore
|
|
|
|
attachment.json.mimeType,
|
|
|
|
);
|
2021-01-29 11:08:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (operation === 'getAll') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const download = this.getNodeParameter('download', 0);
|
2021-01-29 11:08:27 -08:00
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
const issueKey = this.getNodeParameter('issueKey', i) as string;
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-08-17 08:50:24 -07:00
|
|
|
const {
|
|
|
|
fields: { attachment },
|
|
|
|
} = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/2/issue/${issueKey}`,
|
|
|
|
'GET',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2021-01-29 11:08:27 -08:00
|
|
|
responseData = attachment;
|
2022-12-02 12:54:28 -08:00
|
|
|
if (!returnAll) {
|
2022-11-18 06:26:22 -08:00
|
|
|
const limit = this.getNodeParameter('limit', i);
|
2021-01-29 11:08:27 -08:00
|
|
|
responseData = responseData.slice(0, limit);
|
|
|
|
}
|
|
|
|
responseData = responseData.map((data: IDataObject) => ({ json: data }));
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-01-29 11:08:27 -08:00
|
|
|
}
|
|
|
|
if (download) {
|
2022-12-02 03:53:59 -08:00
|
|
|
const binaryPropertyName = this.getNodeParameter('binaryProperty', 0);
|
2021-01-29 11:08:27 -08:00
|
|
|
for (const [index, attachment] of returnData.entries()) {
|
2022-12-02 12:54:28 -08:00
|
|
|
returnData[index].binary = {};
|
2021-01-29 11:08:27 -08:00
|
|
|
//@ts-ignore
|
2022-08-17 08:50:24 -07:00
|
|
|
const buffer = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
'',
|
|
|
|
'GET',
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
// @ts-ignore
|
|
|
|
attachment.json.content,
|
|
|
|
{ json: false, encoding: null },
|
|
|
|
);
|
2021-01-29 11:08:27 -08:00
|
|
|
//@ts-ignore
|
2022-12-02 12:54:28 -08:00
|
|
|
returnData[index].binary[binaryPropertyName] = await this.helpers.prepareBinaryData(
|
2022-08-17 08:50:24 -07:00
|
|
|
buffer,
|
|
|
|
// @ts-ignore
|
|
|
|
attachment.json.filename,
|
|
|
|
// @ts-ignore
|
|
|
|
attachment.json.mimeType,
|
|
|
|
);
|
2021-01-29 11:08:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resource === 'issueComment') {
|
2022-08-17 08:50:24 -07:00
|
|
|
const apiVersion = jiraVersion === 'server' ? '2' : ('3' as string);
|
2021-06-08 20:26:27 -07:00
|
|
|
|
2021-01-29 11:08:27 -08:00
|
|
|
//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++) {
|
2022-12-02 12:54:28 -08:00
|
|
|
const jsonParameters = this.getNodeParameter('jsonParameters', 0);
|
2020-12-29 02:33:13 -08:00
|
|
|
const issueKey = this.getNodeParameter('issueKey', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2020-12-29 02:33:13 -08:00
|
|
|
const body: IDataObject = {};
|
|
|
|
if (options.expand) {
|
|
|
|
qs.expand = options.expand as string;
|
|
|
|
delete options.expand;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.assign(body, options);
|
2022-12-02 12:54:28 -08:00
|
|
|
if (!jsonParameters) {
|
2020-12-29 02:33:13 -08:00
|
|
|
const comment = this.getNodeParameter('comment', i) as string;
|
2021-06-08 20:26:27 -07:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2020-12-29 02:33:13 -08:00
|
|
|
} else {
|
|
|
|
const commentJson = this.getNodeParameter('commentJson', i) as string;
|
|
|
|
const json = validateJSON(commentJson);
|
|
|
|
if (json === '') {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(this.getNode(), 'Document Format must be a valid JSON', {
|
|
|
|
itemIndex: i,
|
|
|
|
});
|
2020-12-29 02:33:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Object.assign(body, { body: json });
|
|
|
|
}
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/${apiVersion}/issue/${issueKey}/comment`,
|
|
|
|
'POST',
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2020-12-29 02:33:13 -08:00
|
|
|
}
|
2021-01-29 11:08:27 -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++) {
|
2020-12-29 02:33:13 -08:00
|
|
|
const issueKey = this.getNodeParameter('issueKey', i) as string;
|
|
|
|
const commentId = this.getNodeParameter('commentId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2020-12-29 02:33:13 -08:00
|
|
|
Object.assign(qs, options);
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/${apiVersion}/issue/${issueKey}/comment/${commentId}`,
|
|
|
|
'GET',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2020-12-29 02:33:13 -08:00
|
|
|
}
|
2021-01-29 11:08:27 -08:00
|
|
|
}
|
|
|
|
//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++) {
|
2020-12-29 02:33:13 -08:00
|
|
|
const issueKey = this.getNodeParameter('issueKey', i) as string;
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2020-12-29 02:33:13 -08:00
|
|
|
const body: IDataObject = {};
|
|
|
|
Object.assign(qs, options);
|
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'comments',
|
|
|
|
`/api/${apiVersion}/issue/${issueKey}/comment`,
|
|
|
|
'GET',
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-12-29 02:33:13 -08:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
const limit = this.getNodeParameter('limit', i);
|
2020-12-29 02:33:13 -08:00
|
|
|
body.maxResults = limit;
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/${apiVersion}/issue/${issueKey}/comment`,
|
|
|
|
'GET',
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-12-29 02:33:13 -08:00
|
|
|
responseData = responseData.comments;
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2020-12-29 02:33:13 -08:00
|
|
|
}
|
2021-01-29 11:08:27 -08:00
|
|
|
}
|
|
|
|
//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++) {
|
2020-12-29 02:33:13 -08:00
|
|
|
const issueKey = this.getNodeParameter('issueKey', i) as string;
|
|
|
|
const commentId = this.getNodeParameter('commentId', i) as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/${apiVersion}/issue/${issueKey}/comment/${commentId}`,
|
|
|
|
'DELETE',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ success: true }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2020-12-29 02:33:13 -08:00
|
|
|
}
|
2021-01-29 11:08:27 -08:00
|
|
|
}
|
|
|
|
//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++) {
|
2020-12-29 02:33:13 -08:00
|
|
|
const issueKey = this.getNodeParameter('issueKey', i) as string;
|
|
|
|
const commentId = this.getNodeParameter('commentId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2022-12-02 12:54:28 -08:00
|
|
|
const jsonParameters = this.getNodeParameter('jsonParameters', 0);
|
2020-12-29 02:33:13 -08:00
|
|
|
const body: IDataObject = {};
|
|
|
|
if (options.expand) {
|
|
|
|
qs.expand = options.expand as string;
|
|
|
|
delete options.expand;
|
|
|
|
}
|
|
|
|
Object.assign(qs, options);
|
2022-12-02 12:54:28 -08:00
|
|
|
if (!jsonParameters) {
|
2020-12-29 02:33:13 -08:00
|
|
|
const comment = this.getNodeParameter('comment', i) as string;
|
2021-06-08 20:26:27 -07:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2020-12-29 02:33:13 -08:00
|
|
|
} else {
|
|
|
|
const commentJson = this.getNodeParameter('commentJson', i) as string;
|
|
|
|
const json = validateJSON(commentJson);
|
|
|
|
if (json === '') {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(this.getNode(), 'Document Format must be a valid JSON', {
|
|
|
|
itemIndex: i,
|
|
|
|
});
|
2020-12-29 02:33:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Object.assign(body, { body: json });
|
|
|
|
}
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/${apiVersion}/issue/${issueKey}/comment/${commentId}`,
|
|
|
|
'PUT',
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2020-12-29 02:33:13 -08:00
|
|
|
}
|
|
|
|
}
|
2019-11-27 14:42:28 -08:00
|
|
|
}
|
2021-01-29 11:08:27 -08:00
|
|
|
|
2021-02-21 02:00:27 -08:00
|
|
|
if (resource === 'user') {
|
2022-08-17 08:50:24 -07:00
|
|
|
const apiVersion = jiraVersion === 'server' ? '2' : ('3' as string);
|
2021-06-08 20:26:27 -07:00
|
|
|
|
2021-02-21 02:00:27 -08:00
|
|
|
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),
|
|
|
|
};
|
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-02-21 02:00:27 -08:00
|
|
|
|
|
|
|
Object.assign(body, additionalFields);
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/${apiVersion}/user`,
|
|
|
|
'POST',
|
|
|
|
body,
|
|
|
|
{},
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-02-21 02:00:27 -08:00
|
|
|
}
|
|
|
|
} 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);
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/${apiVersion}/user`,
|
|
|
|
'DELETE',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ success: true }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-02-21 02:00:27 -08:00
|
|
|
}
|
|
|
|
} 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(',');
|
|
|
|
}
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await jiraSoftwareCloudApiRequest.call(
|
|
|
|
this,
|
|
|
|
`/api/${apiVersion}/user`,
|
|
|
|
'GET',
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-02-21 02:00:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-30 08:55:33 -07:00
|
|
|
return this.prepareOutputData(returnData);
|
2019-11-26 12:38:38 -08:00
|
|
|
}
|
2021-02-21 02:00:27 -08:00
|
|
|
}
|