From 9def6cd6ae4331bd098c9f7890989bedb352db19 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Fri, 29 Nov 2019 17:30:00 -0500 Subject: [PATCH] :sparkles: Issue resource done --- .../nodes-base/nodes/Jira/GenericFunctions.ts | 14 +- .../nodes-base/nodes/Jira/IssueDescription.ts | 786 +++++++++++++++++- .../nodes-base/nodes/Jira/IssueInterface.ts | 21 + .../nodes/Jira/JiraSoftwareCloud.node.ts | 249 +++++- 4 files changed, 1032 insertions(+), 38 deletions(-) diff --git a/packages/nodes-base/nodes/Jira/GenericFunctions.ts b/packages/nodes-base/nodes/Jira/GenericFunctions.ts index 61a6f4a008..b6c6b11674 100644 --- a/packages/nodes-base/nodes/Jira/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Jira/GenericFunctions.ts @@ -20,7 +20,6 @@ export async function jiraSoftwareCloudApiRequest(this: IHookFunctions | IExecut const data = Buffer.from(`${credentials!.email}:${credentials!.apiToken}`).toString(BINARY_ENCODING); const headerWithAuthentication = Object.assign({}, { Authorization: `Basic ${data}`, Accept: 'application/json', 'Content-Type': 'application/json' }); - const options: OptionsWithUri = { headers: headerWithAuthentication, method, @@ -33,7 +32,8 @@ export async function jiraSoftwareCloudApiRequest(this: IHookFunctions | IExecut try { return await this.helpers.request!(options); } catch (error) { - const errorMessage = error.response.body.message || error.response.body.Message; + const errorMessage = + error.response.body.message || error.response.body.Message; if (errorMessage !== undefined) { throw errorMessage; @@ -54,18 +54,18 @@ export async function jiraSoftwareCloudApiRequestAllItems(this: IHookFunctions | let responseData; - query.per_page = 60; + query.maxResults = 100; let uri: string | undefined; do { responseData = await jiraSoftwareCloudApiRequest.call(this, endpoint, method, body, query, uri); - uri = responseData.pages.next; + uri = responseData.nextPage; returnData.push.apply(returnData, responseData[propertyName]); } while ( - responseData.pages !== undefined && - responseData.pages.next !== undefined && - responseData.pages.next !== null + responseData.isLast !== false && + responseData.nextPage !== undefined && + responseData.nextPage !== null ); return returnData; diff --git a/packages/nodes-base/nodes/Jira/IssueDescription.ts b/packages/nodes-base/nodes/Jira/IssueDescription.ts index 13677f04b8..47d0a9f610 100644 --- a/packages/nodes-base/nodes/Jira/IssueDescription.ts +++ b/packages/nodes-base/nodes/Jira/IssueDescription.ts @@ -18,6 +18,36 @@ export const issueOpeations = [ value: 'create', description: 'Create a new issue', }, + { + name: 'Update', + value: 'update', + description: 'Update an issue', + }, + { + name: 'Get', + value: 'get', + description: 'Get an issue', + }, + { + name: 'Changelog', + value: 'changelog', + description: 'Get issue changelog', + }, + { + name: 'Notify', + value: 'notify', + description: 'Creates an email notification for an issue and adds it to the mail queue.', + }, + { + name: 'Transitions', + value: 'transitions', + description: `Returns either all transitions or a transition that can be performed by the user on an issue, based on the issue's status.`, + }, + { + name: 'Delete', + value: 'delete', + description: 'Delete an issue', + }, ], default: 'create', description: 'The operation to perform.', @@ -87,23 +117,6 @@ export const issueFields = [ default: '', description: 'Summary', }, - { - displayName: 'Has Parent Issue?', - name: 'hasParentIssue', - type: 'boolean', - displayOptions: { - show: { - resource: [ - 'issue', - ], - operation: [ - 'create', - ], - }, - }, - default: false, - description: 'Weather The Issue Has A Parent Issue ID/Key or Not', - }, { displayName: 'Parent Issue Key', name: 'parentIssueKey', @@ -117,9 +130,6 @@ export const issueFields = [ operation: [ 'create', ], - hasParentIssue: [ - true, - ], }, }, default: '', @@ -183,6 +193,742 @@ export const issueFields = [ required : false, description: 'Description', }, + { + displayName: 'Update History', + name: 'updateHistory', + type: 'boolean', + default: false, + required : false, + description: `Whether the project in which the issue is created is added to the user's Recently viewed project list, as shown under Projects in Jira.`, + }, ], }, + +/* -------------------------------------------------------------------------- */ +/* issue:update */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Issue Key', + name: 'issueKey', + type: 'string', + required: true, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'update', + ], + }, + }, + default: '', + description: 'Issue Key', + }, + { + displayName: 'Issue Type', + name: 'issueType', + type: 'options', + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'update' + ] + }, + }, + typeOptions: { + loadOptionsMethod: 'getIssueTypes', + }, + default: '', + description: 'Issue Types', + }, + { + displayName: 'Summary', + name: 'summary', + type: 'string', + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'update', + ], + }, + }, + default: '', + description: 'Summary', + }, + { + displayName: 'Parent Issue Key', + name: 'parentIssueKey', + type: 'string', + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'update', + ], + }, + }, + default: '', + description: 'Parent Issue Key', + }, + { + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', + default: {}, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'update', + ], + }, + }, + options: [ + { + displayName: 'Labels', + name: 'labels', + type: 'multiOptions', + typeOptions: { + loadOptionsMethod: 'getLabels', + }, + default: [], + required : false, + description: 'Labels', + }, + { + displayName: 'Priority', + name: 'priority', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getPriorities', + }, + default: [], + required : false, + description: 'Priority', + }, + { + displayName: 'Assignee', + name: 'assignee', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getUsers', + }, + default: [], + required : false, + description: 'Assignee', + }, + { + displayName: 'Description', + name: 'description', + type: 'string', + default: '', + required : false, + description: 'Description', + }, + ], + }, + +/* -------------------------------------------------------------------------- */ +/* issue:delete */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Issue Key', + name: 'issueKey', + type: 'string', + required: true, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'delete', + ], + }, + }, + default: '', + description: 'Issue Key', + }, + { + displayName: 'Delete Subtasks', + name: 'deleteSubtasks', + type: 'boolean', + required: true, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'delete', + ], + }, + }, + default: false, + description: 'Delete Subtasks', + }, + +/* -------------------------------------------------------------------------- */ +/* issue:get */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Issue Key', + name: 'issueKey', + type: 'string', + required: true, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'get', + ], + }, + }, + default: '', + description: 'Issue Key', + }, + { + displayName: 'Fields', + name: 'fields', + type: 'string', + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'get', + ], + }, + }, + default: '', + description: `A list of fields to return for the issue. This parameter accepts a comma-separated list. Use it to retrieve a subset of fields. Allowed values: + *all Returns all fields. + *navigable Returns navigable fields. + Any issue field, prefixed with a minus to exclude.` + }, + { + displayName: 'Fields By Key', + name: 'fieldsByKey', + type: 'boolean', + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'get', + ], + }, + }, + default: false, + description: `Indicates whether fields in fields are referenced by keys rather than IDs. This parameter is useful where fields have been added by a connect app and a field's key may differ from its ID.`, + }, + { + displayName: 'Expand', + name: 'expand', + type: 'string', + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'get', + ], + }, + }, + default: '', + description: `Use expand to include additional information about the issues in the response. This parameter accepts a comma-separated list. Expand options include: + renderedFields Returns field values rendered in HTML format. + names Returns the display name of each field. + schema Returns the schema describing a field type. + transitions Returns all possible transitions for the issue. + editmeta Returns information about how each field can be edited. + changelog Returns a list of recent updates to an issue, sorted by date, starting from the most recent. + versionedRepresentations Returns a JSON array for each version of a field's value, with the highest number representing the most recent version. Note: When included in the request, the fields parameter is ignored.` + }, + { + displayName: 'Properties', + name: 'properties', + type: 'string', + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'get', + ], + }, + }, + default: '', + description: `A list of issue properties to return for the issue. This parameter accepts a comma-separated list. Allowed values: + *all Returns all issue properties. + Any issue property key, prefixed with a minus to exclude. + Examples: + *all Returns all properties. + *all,-prop1 Returns all properties except prop1. + prop1,prop2 Returns prop1 and prop2 properties. + This parameter may be specified multiple times. For example, properties=prop1,prop2& properties=prop3.` + }, + { + displayName: 'Update History', + name: 'updateHistory', + type: 'boolean', + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'get', + ], + }, + }, + default: false, + description: `Whether the project in which the issue is created is added to the user's Recently viewed project list, as shown under Projects in Jira. This also populates the JQL issues search lastViewed field.`, + }, + +/* -------------------------------------------------------------------------- */ +/* issue:changelog */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Issue Key', + name: 'issueKey', + type: 'string', + required: true, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'changelog', + ], + }, + }, + default: '', + description: 'Issue Key', + }, + { + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'changelog', + ], + }, + }, + default: false, + description: 'If all results should be returned or only up to a given limit.', + }, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'changelog', + ], + returnAll: [ + false, + ], + }, + }, + typeOptions: { + minValue: 1, + maxValue: 100, + }, + default: 50, + description: 'How many results to return.', + }, + +/* -------------------------------------------------------------------------- */ +/* issue:notify */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Issue Key', + name: 'issueKey', + type: 'string', + required: true, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'notify', + ], + }, + }, + default: '', + description: 'Issue Key', + }, + { + displayName: 'Subject', + name: 'subject', + type: 'string', + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'notify', + ], + }, + }, + default: '', + description: 'The subject of the email notification for the issue. If this is not specified, then the subject is set to the issue key and summary.', + }, + { + displayName: 'Text Body', + name: 'textBody', + type: 'string', + typeOptions: { + alwaysOpenEditWindow: true, + }, + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'notify', + ], + }, + }, + default: '', + description: 'The subject of the email notification for the issue. If this is not specified, then the subject is set to the issue key and summary.', + }, + { + displayName: 'HTML Body', + name: 'htmlBody', + type: 'string', + typeOptions: { + alwaysOpenEditWindow: true, + }, + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'notify', + ], + }, + }, + default: '', + description: 'The HTML body of the email notification for the issue.', + }, + { + displayName: 'JSON Parameters', + name: 'jsonParameters', + type: 'boolean', + default: false, + description: '', + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'notify', + ], + }, + }, + }, + { + displayName: 'Notification Recipients', + name: 'notificationRecipientsUi', + type: 'fixedCollection', + placeholder: 'Add Recipients', + typeOptions: { + multipleValues: false, + }, + description: 'The recipients of the email notification for the issue.', + default: {}, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'notify', + ], + jsonParameters: [ + false, + ], + }, + }, + options: [ + { + name: 'notificationRecipientsValues', + displayName: 'Recipients', + values: [ + { + displayName: 'Reporter', + name: 'reporter', + type: 'boolean', + description: `Indicates whether the notification should be sent to the issue's reporter.`, + default: false, + }, + { + displayName: 'Assignee', + name: 'assignee', + type: 'boolean', + default: false, + description: `Indicates whether the notification should be sent to the issue's assignees.`, + }, + { + displayName: 'Watchers', + name: 'watchers', + type: 'boolean', + default: false, + description: `Indicates whether the notification should be sent to the issue's assignees.`, + }, + { + displayName: 'Voters', + name: 'voters', + type: 'boolean', + default: false, + description: `Indicates whether the notification should be sent to the issue's voters.`, + }, + { + displayName: 'Users', + name: 'users', + type: 'multiOptions', + typeOptions: { + loadOptionsMethod: 'getUsers', + }, + default: [], + description: `List of users to receive the notification.`, + }, + { + displayName: 'Groups', + name: 'groups', + type: 'multiOptions', + typeOptions: { + loadOptionsMethod: 'getGroups', + }, + default: [], + description: `List of groups to receive the notification.`, + }, + ] + + } + ] + }, + { + displayName: 'Notification Recipients', + name: 'notificationRecipientsJson', + type: 'json', + typeOptions: { + alwaysOpenEditWindow: true, + }, + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'notify', + ], + jsonParameters: [ + true, + ] + }, + }, + default: '', + description: 'The recipients of the email notification for the issue.', + }, + { + displayName: 'Notification Recipients Restrictions', + name: 'notificationRecipientsRestrictionsUi', + type: 'fixedCollection', + placeholder: 'Add Recipients Restriction', + typeOptions: { + multipleValues: false, + }, + description: 'Restricts the notifications to users with the specified permissions.', + default: {}, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'notify', + ], + jsonParameters: [ + false, + ], + }, + }, + options: [ + { + name: 'notificationRecipientsRestrictionsValues', + displayName: 'Recipients Restrictions', + values: [ + { + displayName: 'Users', + name: 'users', + type: 'multiOptions', + typeOptions: { + loadOptionsMethod: 'getUsers', + }, + default: [], + description: `List of users to receive the notification.`, + }, + { + displayName: 'Groups', + name: 'groups', + type: 'multiOptions', + typeOptions: { + loadOptionsMethod: 'getGroups', + }, + default: [], + description: `List of groups to receive the notification.`, + }, + ] + + } + ] + }, + { + displayName: 'Notification Recipients Restrictions', + name: 'notificationRecipientsRestrictionsJson', + type: 'json', + typeOptions: { + alwaysOpenEditWindow: true, + }, + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'notify', + ], + jsonParameters: [ + true, + ] + }, + }, + default: '', + description: 'Restricts the notifications to users with the specified permissions.', + }, + +/* -------------------------------------------------------------------------- */ +/* issue:transitions */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Issue Key', + name: 'issueKey', + type: 'string', + required: true, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'transitions', + ], + }, + }, + default: '', + description: 'Issue Key', + }, + { + displayName: 'Expand', + name: 'expand', + type: 'string', + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'transitions', + ], + }, + }, + default: '', + description: 'Use expand to include additional information about transitions in the response. This parameter accepts transitions.fields, which returns information about the fields in the transition screen for each transition. Fields hidden from the screen are not returned. Use this information to populate the fields and update fields in Transition issue.', + }, + { + displayName: 'Transition ID', + name: 'transitionId', + type: 'string', + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'transitions', + ], + }, + }, + default: '', + description: 'The ID of the transition.', + }, + { + displayName: 'Skip Remote Only Condition', + name: 'skipRemoteOnlyCondition', + type: 'boolean', + required: false, + displayOptions: { + show: { + resource: [ + 'issue', + ], + operation: [ + 'transitions', + ], + }, + }, + default: false, + description: 'Indicates whether transitions with the condition Hide From User Condition are included in the response.', + }, ] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Jira/IssueInterface.ts b/packages/nodes-base/nodes/Jira/IssueInterface.ts index b0c16d1eb0..88b24962ce 100644 --- a/packages/nodes-base/nodes/Jira/IssueInterface.ts +++ b/packages/nodes-base/nodes/Jira/IssueInterface.ts @@ -14,3 +14,24 @@ export interface IFields { export interface IIssue { fields?: IFields; } + +export interface INotify { + subject?: string; + textBody?: string; + htmlBody?: string; + to?: INotificationRecipients; + restrict?: NotificationRecipientsRestrictions; +} + +export interface INotificationRecipients { + reporter?: boolean; + assignee?: boolean; + watchers?: boolean; + voters?: boolean; + users?: IDataObject[]; + groups?: IDataObject[]; +} + +export interface NotificationRecipientsRestrictions { + groups?: IDataObject[]; +} diff --git a/packages/nodes-base/nodes/Jira/JiraSoftwareCloud.node.ts b/packages/nodes-base/nodes/Jira/JiraSoftwareCloud.node.ts index fe094c01bb..6591be60e3 100644 --- a/packages/nodes-base/nodes/Jira/JiraSoftwareCloud.node.ts +++ b/packages/nodes-base/nodes/Jira/JiraSoftwareCloud.node.ts @@ -21,6 +21,9 @@ import { import { IIssue, IFields, + INotify, + INotificationRecipients, + NotificationRecipientsRestrictions, } from './IssueInterface'; export class JiraSoftwareCloud implements INodeType { @@ -175,6 +178,28 @@ export class JiraSoftwareCloud implements INodeType { } return returnData; }, + + // Get all the groups to display them to user so that he can + // select them easily + async getGroups(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + let groups; + try { + groups = await jiraSoftwareCloudApiRequest.call(this, '/groups/picker', 'GET'); + } catch (err) { + throw new Error(`Jira Error: ${err}`); + } + for (const group of groups.groups) { + const groupName = group.name; + const groupId = group.name; + + returnData.push({ + name: groupName, + value: groupId, + }); + } + return returnData; + } } }; @@ -183,7 +208,7 @@ export class JiraSoftwareCloud implements INodeType { const returnData: IDataObject[] = []; const length = items.length as unknown as number; let responseData; - let qs: IDataObject = {}; + const qs: IDataObject = {}; for (let i = 0; i < length; i++) { const resource = this.getNodeParameter('resource', 0) as string; const operation = this.getNodeParameter('operation', 0) as string; @@ -192,8 +217,8 @@ export class JiraSoftwareCloud implements INodeType { const summary = this.getNodeParameter('summary', i) as string; const projectId = this.getNodeParameter('project', i) as string; const issueTypeId = this.getNodeParameter('issueType', i) as string; - const hasParentIssue = this.getNodeParameter('hasParentIssue', i) as boolean; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + const parentIssueKey = this.getNodeParameter('parentIssueKey', i) as string; const body: IIssue = {}; const fields: IFields = { summary, @@ -220,17 +245,24 @@ export class JiraSoftwareCloud implements INodeType { if (additionalFields.description) { fields.description = additionalFields.description as string; } - if (hasParentIssue) { - const parentIssueKey = this.getNodeParameter('parentIssueKey', i) as string; - if (!parentIssueKey && issueTypeId === 'sub-task') { - throw new Error('You must define a Parent Issue Key when Issue type is sub-task'); - - } else if (parentIssueKey && issueTypeId === 'sub-task') { - fields.parent = { - key: parentIssueKey, - }; + if (additionalFields.updateHistory) { + qs.updateHistory = additionalFields.updateHistory as boolean; + } + const issueTypes = await jiraSoftwareCloudApiRequest.call(this, '/issuetype', 'GET', body, qs); + const subtaskIssues = []; + for (const issueType of issueTypes) { + if (issueType.subtask) { + subtaskIssues.push(issueType.id); } } + if (!parentIssueKey && subtaskIssues.includes(issueTypeId)) { + throw new Error('You must define a Parent Issue Key when Issue type is sub-task'); + + } else if (parentIssueKey && subtaskIssues.includes(issueTypeId)) { + fields.parent = { + key: parentIssueKey.toUpperCase(), + }; + } body.fields = fields; try { responseData = await jiraSoftwareCloudApiRequest.call(this, '/issue', 'POST', body); @@ -238,6 +270,201 @@ export class JiraSoftwareCloud implements INodeType { throw new Error(`Jira Error: ${JSON.stringify(err)}`); } } + if (operation === 'update') { + const summary = this.getNodeParameter('summary', i) as string; + const issueTypeId = this.getNodeParameter('issueType', i) as string; + const issueKey = this.getNodeParameter('issueKey', i) as string; + const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + const parentIssueKey = this.getNodeParameter('parentIssueKey', i) as string; + const body: IIssue = {}; + const fields: IFields = { + summary, + issuetype: { + id: issueTypeId + } + }; + if (additionalFields.labels) { + fields.labels = additionalFields.labels as string[]; + } + if (additionalFields.priority) { + fields.priority = { + id: additionalFields.priority as string, + }; + } + if (additionalFields.assignee) { + fields.assignee = { + id: additionalFields.assignee as string, + }; + } + if (additionalFields.description) { + fields.description = additionalFields.description as string; + } + const issueTypes = await jiraSoftwareCloudApiRequest.call(this, '/issuetype', 'GET', body); + const subtaskIssues = []; + for (const issueType of issueTypes) { + if (issueType.subtask) { + subtaskIssues.push(issueType.id); + } + } + if (!parentIssueKey && subtaskIssues.includes(issueTypeId)) { + throw new Error('You must define a Parent Issue Key when Issue type is sub-task'); + + } else if (parentIssueKey && subtaskIssues.includes(issueTypeId)) { + fields.parent = { + key: parentIssueKey.toUpperCase(), + }; + } + body.fields = fields; + try { + responseData = await jiraSoftwareCloudApiRequest.call(this, `/issue/${issueKey}`, 'PUT', body); + } catch (err) { + throw new Error(`Jira Error: ${JSON.stringify(err)}`); + } + } + if (operation === 'get') { + const issueKey = this.getNodeParameter('issueKey', i) as string; + const fields = this.getNodeParameter('fields', i) as string; + const fieldsByKey = this.getNodeParameter('fieldsByKey', i) as boolean; + const expand = this.getNodeParameter('expand', i) as string; + const properties = this.getNodeParameter('properties', i) as string; + const updateHistory = this.getNodeParameter('updateHistory', i) as boolean; + qs.fields = fields; + qs.fieldsByKey = fieldsByKey; + qs.expand = expand; + qs.properties = properties; + qs.updateHistory = updateHistory; + try { + responseData = await jiraSoftwareCloudApiRequest.call(this, `/issue/${issueKey}`, 'GET', {}, qs); + } catch (err) { + throw new Error(`Jira Error: ${JSON.stringify(err)}`); + } + } + if (operation === 'changelog') { + const issueKey = this.getNodeParameter('issueKey', i) as string; + const returnAll = this.getNodeParameter('returnAll', i) as boolean; + try { + if (returnAll) { + responseData = await jiraSoftwareCloudApiRequestAllItems.call(this, 'values',`/issue/${issueKey}/changelog`, 'GET'); + } else { + qs.maxResults = this.getNodeParameter('limit', i) as number; + responseData = await jiraSoftwareCloudApiRequest.call(this, `/issue/${issueKey}/changelog`, 'GET', {}, qs); + responseData = responseData.values; + } + } catch (err) { + throw new Error(`Jira Error: ${JSON.stringify(err)}`); + } + } + if (operation === 'notify') { + const issueKey = this.getNodeParameter('issueKey', i) as string; + const textBody = this.getNodeParameter('textBody', i) as string; + const htmlBody = this.getNodeParameter('htmlBody', i) as string; + const jsonActive = this.getNodeParameter('jsonParameters', 0) as boolean; + const body: INotify = {}; + body.htmlBody = htmlBody; + body.textBody = textBody; + if (!jsonActive) { + const notificationRecipientsValues = (this.getNodeParameter('notificationRecipientsUi', i) as IDataObject).notificationRecipientsValues as IDataObject[]; + 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 + notificationRecipients.users = notificationRecipientsValues.users.map(user => { + return { + accountId: user + }; + }); + } + // @ts-ignore + if (notificationRecipientsValues.groups.length > 0) { + // @ts-ignore + notificationRecipients.groups = notificationRecipientsValues.groups.map(group => { + return { + name: group + }; + }); + } + } + body.to = notificationRecipients; + const notificationRecipientsRestrictionsValues = (this.getNodeParameter('notificationRecipientsRestrictionsUi', i) as IDataObject).notificationRecipientsRestrictionsValues as IDataObject[]; + const notificationRecipientsRestrictions: NotificationRecipientsRestrictions = {}; + if (notificationRecipientsRestrictionsValues) { + // @ts-ignore + if (notificationRecipientsRestrictionsValues.groups. length > 0) { + // @ts-ignore + notificationRecipientsRestrictions.groups = notificationRecipientsRestrictionsValues.groups.map(group => { + return { + name: group + }; + }); + } + } + body.restrict = notificationRecipientsRestrictions; + } else { + const notificationRecipientsJson = validateJSON(this.getNodeParameter('notificationRecipientsJson', i) as string); + if (notificationRecipientsJson) { + body.to = notificationRecipientsJson; + } + const notificationRecipientsRestrictionsJson = validateJSON(this.getNodeParameter('notificationRecipientsRestrictionsJson', i) as string); + if (notificationRecipientsRestrictionsJson) { + body.restrict = notificationRecipientsRestrictionsJson; + } + } + try { + responseData = await jiraSoftwareCloudApiRequest.call(this, `/issue/${issueKey}/notify`, 'POST', body, qs); + } catch (err) { + throw new Error(`Jira Error: ${JSON.stringify(err)}`); + } + } + if (operation === 'transitions') { + const issueKey = this.getNodeParameter('issueKey', i) as string; + const transitionId = this.getNodeParameter('transitionId', i) as string; + const expand = this.getNodeParameter('expand', i) as string; + if (transitionId) { + qs.transitionId = transitionId; + } + if (expand) { + qs.expand = expand; + } + qs.skipRemoteOnlyCondition = this.getNodeParameter('skipRemoteOnlyCondition', i) as boolean; + + try { + responseData = await jiraSoftwareCloudApiRequest.call(this, `/issue/${issueKey}/transitions`, 'GET', {}, qs); + responseData = responseData.transitions; + } catch (err) { + throw new Error(`Jira Error: ${JSON.stringify(err)}`); + } + } + if (operation === 'delete') { + const issueKey = this.getNodeParameter('issueKey', i) as string; + const deleteSubtasks = this.getNodeParameter('deleteSubtasks', i) as boolean; + qs.deleteSubtasks = deleteSubtasks; + try { + responseData = await jiraSoftwareCloudApiRequest.call(this, `/issue/${issueKey}`, 'DELETE', {}, qs); + } catch (err) { + throw new Error(`Jira Error: ${JSON.stringify(err)}`); + } + } } if (Array.isArray(responseData)) { returnData.push.apply(returnData, responseData as IDataObject[]);