From f8869f85e85d8491dc593940b1c6eb8080c20f27 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Fri, 24 Apr 2020 09:50:56 +0200 Subject: [PATCH] :zap: Small improvements to Jira-Node --- .../nodes-base/nodes/Jira/GenericFunctions.ts | 18 +++++++-- .../nodes-base/nodes/Jira/IssueDescription.ts | 5 ++- .../nodes/Jira/JiraSoftwareCloud.node.ts | 37 ++++++++++++------- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/packages/nodes-base/nodes/Jira/GenericFunctions.ts b/packages/nodes-base/nodes/Jira/GenericFunctions.ts index 133578fd50..3f2e6dd82a 100644 --- a/packages/nodes-base/nodes/Jira/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Jira/GenericFunctions.ts @@ -43,11 +43,21 @@ 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.error || error.response.body.errors; - if (errorMessage !== undefined) { - throw new Error(errorMessage); + let errorMessage = error.message; + + if (error.response.body) { + if (error.response.body.errorMessages && error.response.body.errorMessages.length) { + errorMessage = JSON.stringify(error.response.body.errorMessages); + } else { + errorMessage = error.response.body.message || error.response.body.error || error.response.body.errors || error.message; + } } - throw error; + + if (typeof errorMessage !== 'string') { + errorMessage = JSON.stringify(errorMessage); + } + + throw new Error(`Jira error response [${error.statusCode}]: ${errorMessage}`); } } diff --git a/packages/nodes-base/nodes/Jira/IssueDescription.ts b/packages/nodes-base/nodes/Jira/IssueDescription.ts index 74708b088f..5f3c18c9d6 100644 --- a/packages/nodes-base/nodes/Jira/IssueDescription.ts +++ b/packages/nodes-base/nodes/Jira/IssueDescription.ts @@ -312,7 +312,10 @@ export const issueFields = [ { displayName: 'Status ID', name: 'statusId', - type: 'string', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getTransitions', + }, required: false, default: '', description: 'The ID of the issue status.', diff --git a/packages/nodes-base/nodes/Jira/JiraSoftwareCloud.node.ts b/packages/nodes-base/nodes/Jira/JiraSoftwareCloud.node.ts index 3388acaeeb..7335d24b6b 100644 --- a/packages/nodes-base/nodes/Jira/JiraSoftwareCloud.node.ts +++ b/packages/nodes-base/nodes/Jira/JiraSoftwareCloud.node.ts @@ -112,12 +112,11 @@ export class JiraSoftwareCloud implements INodeType { async getProjects(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; const jiraCloudCredentials = this.getCredentials('jiraSoftwareCloudApi'); - let projects; let endpoint = '/project/search'; if (jiraCloudCredentials === undefined) { endpoint = '/project'; } - projects = await jiraSoftwareCloudApiRequest.call(this, endpoint, 'GET'); + let projects = await jiraSoftwareCloudApiRequest.call(this, endpoint, 'GET'); if (projects.values && Array.isArray(projects.values)) { projects = projects.values; @@ -138,9 +137,8 @@ export class JiraSoftwareCloud implements INodeType { async getIssueTypes(this: ILoadOptionsFunctions): Promise { const projectId = this.getCurrentNodeParameter('project'); const returnData: INodePropertyOptions[] = []; - let issueTypes; - issueTypes = await jiraSoftwareCloudApiRequest.call(this, '/issuetype', 'GET'); + const issueTypes = await jiraSoftwareCloudApiRequest.call(this, '/issuetype', 'GET'); for (const issueType of issueTypes) { if (issueType.scope.project.id === projectId) { @@ -160,9 +158,8 @@ export class JiraSoftwareCloud implements INodeType { // select them easily async getLabels(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; - let labels; - labels = await jiraSoftwareCloudApiRequest.call(this, '/label', 'GET'); + const labels = await jiraSoftwareCloudApiRequest.call(this, '/label', 'GET'); for (const label of labels.values) { const labelName = label; @@ -180,9 +177,8 @@ export class JiraSoftwareCloud implements INodeType { // select them easily async getPriorities(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; - let priorities; - priorities = await jiraSoftwareCloudApiRequest.call(this, '/priority', 'GET'); + const priorities = await jiraSoftwareCloudApiRequest.call(this, '/priority', 'GET'); for (const priority of priorities) { const priorityName = priority.name; @@ -200,9 +196,8 @@ export class JiraSoftwareCloud implements INodeType { // select them easily async getUsers(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; - let users; - users = await jiraSoftwareCloudApiRequest.call(this, '/users/search', 'GET'); + const users = await jiraSoftwareCloudApiRequest.call(this, '/users/search', 'GET'); for (const user of users) { const userName = user.displayName; @@ -220,9 +215,8 @@ export class JiraSoftwareCloud implements INodeType { // select them easily async getGroups(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; - let groups; - groups = await jiraSoftwareCloudApiRequest.call(this, '/groups/picker', 'GET'); + const groups = await jiraSoftwareCloudApiRequest.call(this, '/groups/picker', 'GET'); for (const group of groups.groups) { const groupName = group.name; @@ -234,7 +228,24 @@ export class JiraSoftwareCloud implements INodeType { }); } return returnData; - } + }, + + // Get all the groups to display them to user so that he can + // select them easily + async getTransitions(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + + const issueKey = this.getCurrentNodeParameter('issueKey'); + const transitions = await jiraSoftwareCloudApiRequest.call(this, `/issue/${issueKey}/transitions`, 'GET'); + + for (const transition of transitions.transitions) { + returnData.push({ + name: transition.name, + value: transition.id, + }); + } + return returnData; + }, } };