From 79a09c98a74beeff7aead636f0e3f0e07f78e42c Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Tue, 5 May 2020 22:56:24 +0200 Subject: [PATCH] :zap: Minor improvements to Jira-Node --- .../nodes-base/nodes/Jira/GenericFunctions.ts | 33 +++++++++++-------- .../nodes/Jira/JiraSoftwareCloud.node.ts | 22 ++++++------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/packages/nodes-base/nodes/Jira/GenericFunctions.ts b/packages/nodes-base/nodes/Jira/GenericFunctions.ts index e0a7d8871e..3ee49ac166 100644 --- a/packages/nodes-base/nodes/Jira/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Jira/GenericFunctions.ts @@ -1,4 +1,4 @@ -import { +import { OptionsWithUri, } from 'request'; @@ -9,30 +9,35 @@ import { ILoadOptionsFunctions, } from 'n8n-core'; -import { +import { IDataObject, ICredentialDataDecryptedObject, } from 'n8n-workflow'; export async function jiraSoftwareCloudApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise { // tslint:disable-line:no-any let data; let domain; - let jiraCloudCredentials: ICredentialDataDecryptedObject | undefined; - try { - jiraCloudCredentials = this.getCredentials('jiraSoftwareCloudApi'); - } catch (error) { - + + const jiraVersion = this.getNodeParameter('jiraVersion', 0) as string; + + let jiraCredentials: ICredentialDataDecryptedObject | undefined; + if (jiraVersion === 'server') { + jiraCredentials = this.getCredentials('jiraSoftwareServerApi'); + } else { + jiraCredentials = this.getCredentials('jiraSoftwareCloudApi'); } - const jiraServerCredentials = this.getCredentials('jiraSoftwareServerApi'); - if (jiraCloudCredentials === undefined && jiraServerCredentials === undefined) { + + if (jiraCredentials === undefined) { throw new Error('No credentials got returned!'); } - if (jiraCloudCredentials !== undefined) { - domain = jiraCloudCredentials!.domain; - data = Buffer.from(`${jiraCloudCredentials!.email}:${jiraCloudCredentials!.apiToken}`).toString('base64'); + + if (jiraVersion === 'server') { + domain = jiraCredentials!.domain; + data = Buffer.from(`${jiraCredentials!.email}:${jiraCredentials!.password}`).toString('base64'); } else { - domain = jiraServerCredentials!.domain; - data = Buffer.from(`${jiraServerCredentials!.email}:${jiraServerCredentials!.password}`).toString('base64'); + domain = jiraCredentials!.domain; + data = Buffer.from(`${jiraCredentials!.email}:${jiraCredentials!.apiToken}`).toString('base64'); } + const options: OptionsWithUri = { headers: { Authorization: `Basic ${data}`, diff --git a/packages/nodes-base/nodes/Jira/JiraSoftwareCloud.node.ts b/packages/nodes-base/nodes/Jira/JiraSoftwareCloud.node.ts index 5b64de4f95..d262ac0da9 100644 --- a/packages/nodes-base/nodes/Jira/JiraSoftwareCloud.node.ts +++ b/packages/nodes-base/nodes/Jira/JiraSoftwareCloud.node.ts @@ -141,11 +141,11 @@ export class JiraSoftwareCloud implements INodeType { const issueTypes = await jiraSoftwareCloudApiRequest.call(this, '/issuetype', 'GET'); const jiraVersion = this.getCurrentNodeParameter('jiraVersion') as string; - if (jiraVersion === "server") { + if (jiraVersion === 'server') { for (const issueType of issueTypes) { const issueTypeName = issueType.name; const issueTypeId = issueType.id; - + returnData.push({ name: issueTypeName, value: issueTypeId, @@ -156,7 +156,7 @@ export class JiraSoftwareCloud implements INodeType { if (issueType.scope.project.id === projectId) { const issueTypeName = issueType.name; const issueTypeId = issueType.id; - + returnData.push({ name: issueTypeName, value: issueTypeId, @@ -164,7 +164,7 @@ export class JiraSoftwareCloud implements INodeType { } } } - + return returnData; }, @@ -210,10 +210,10 @@ export class JiraSoftwareCloud implements INodeType { // select them easily async getUsers(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; - const jiraVersion = this.getCurrentNodeParameter("jiraVersion") as string; - if (jiraVersion === "server") { + const jiraVersion = this.getCurrentNodeParameter('jiraVersion') as string; + if (jiraVersion === 'server') { // the interface call must bring username - const users = await jiraSoftwareCloudApiRequest.call(this, "/user/search", "GET", {}, + const users = await jiraSoftwareCloudApiRequest.call(this, '/user/search', 'GET', {}, { username: "'", } @@ -221,7 +221,7 @@ export class JiraSoftwareCloud implements INodeType { for (const user of users) { const userName = user.displayName; const userId = user.name; - + returnData.push({ name: userName, value: userId, @@ -240,7 +240,7 @@ export class JiraSoftwareCloud implements INodeType { }); } } - + return returnData; }, @@ -324,7 +324,7 @@ export class JiraSoftwareCloud implements INodeType { }; } if (additionalFields.assignee) { - if (jiraVersion === "server") { + if (jiraVersion === 'server') { fields.assignee = { name: additionalFields.assignee as string, }; @@ -386,7 +386,7 @@ export class JiraSoftwareCloud implements INodeType { }; } if (updateFields.assignee) { - if (jiraVersion === "server") { + if (jiraVersion === 'server') { fields.assignee = { name: updateFields.assignee as string, };