From ff0fcfc511f0d990a200ec5cc6ce775bc73ee8a6 Mon Sep 17 00:00:00 2001 From: pemontto Date: Wed, 20 Oct 2021 15:24:54 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20custom=20fields=20for?= =?UTF-8?q?=20Jira=20Server?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/nodes-base/nodes/Jira/Jira.node.ts | 49 ++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/Jira/Jira.node.ts b/packages/nodes-base/nodes/Jira/Jira.node.ts index 5dcd27e984..2123703ad6 100644 --- a/packages/nodes-base/nodes/Jira/Jira.node.ts +++ b/packages/nodes-base/nodes/Jira/Jira.node.ts @@ -1,3 +1,7 @@ +import { + OptionsWithUri, +} from 'request'; + import { IExecuteFunctions, } from 'n8n-core'; @@ -5,12 +9,15 @@ import { import { IBinaryData, IBinaryKeyData, + ICredentialsDecrypted, + ICredentialTestFunctions, IDataObject, ILoadOptionsFunctions, INodeExecutionData, INodePropertyOptions, INodeType, INodeTypeDescription, + NodeCredentialTestResult, NodeOperationError, } from 'n8n-workflow'; @@ -74,6 +81,7 @@ export class Jira implements INodeType { ], }, }, + testedBy: 'jiraSoftwareApiTest', }, { name: 'jiraSoftwareServerApi', @@ -85,6 +93,7 @@ export class Jira implements INodeType { ], }, }, + testedBy: 'jiraSoftwareApiTest', }, ], properties: [ @@ -145,6 +154,44 @@ export class Jira implements INodeType { }; methods = { + credentialTest: { + async jiraSoftwareApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise { + let data; let domain; + const credentials = credential.data; + domain = credentials!.domain; + data = Buffer.from(`${credentials!.email}:${credentials!.password || credentials!.apiToken}`).toString('base64'); + + const endpoint = '/api/2/project'; + + const options: OptionsWithUri = { + headers: { + Authorization: `Basic ${data}`, + Accept: 'application/json', + 'Content-Type': 'application/json', + 'X-Atlassian-Token': 'no-check', + }, + method: 'GET', + uri: `${domain}/rest${endpoint}`, + qs: { + recent: 0, + }, + json: true, + timeout: 5000, + }; + try { + const response = await this.helpers.request!(options); + } catch (err) { + return { + status: 'Error', + message: `Connection details not valid; ${err.message}`, + }; + } + return { + status: 'OK', + message: 'Authentication successful!', + }; + }, + }, loadOptions: { // Get all the projects to display them to user so that he can // select them easily @@ -370,7 +417,7 @@ export class Jira implements INodeType { } const res = await jiraSoftwareCloudApiRequest.call(this, `/api/2/issue/createmeta?projectIds=${projectId}&issueTypeIds=${issueTypeId}&expand=projects.issuetypes.fields`, 'GET'); - + // tslint:disable-next-line: no-any const fields = res.projects.find((o: any) => o.id === projectId).issuetypes.find((o: any) => o.id === issueTypeId).fields; for (const key of Object.keys(fields)) { From 1d8e800620f5c57eb47dfb7501ad2402f101d604 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Wed, 20 Oct 2021 22:24:03 -0500 Subject: [PATCH 2/2] :zap: Simplify --- packages/nodes-base/nodes/Jira/Jira.node.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/nodes-base/nodes/Jira/Jira.node.ts b/packages/nodes-base/nodes/Jira/Jira.node.ts index 7a489368b1..3cd0509566 100644 --- a/packages/nodes-base/nodes/Jira/Jira.node.ts +++ b/packages/nodes-base/nodes/Jira/Jira.node.ts @@ -156,12 +156,8 @@ export class Jira implements INodeType { methods = { credentialTest: { async jiraSoftwareApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise { - let data; let domain; const credentials = credential.data; - domain = credentials!.domain; - data = Buffer.from(`${credentials!.email}:${credentials!.password || credentials!.apiToken}`).toString('base64'); - - const endpoint = '/api/2/project'; + const data = Buffer.from(`${credentials!.email}:${credentials!.password || credentials!.apiToken}`).toString('base64'); const options: OptionsWithUri = { headers: { @@ -171,7 +167,7 @@ export class Jira implements INodeType { 'X-Atlassian-Token': 'no-check', }, method: 'GET', - uri: `${domain}/rest${endpoint}`, + uri: `${credentials!.domain}/rest/api/2/project`, qs: { recent: 0, }, @@ -179,7 +175,7 @@ export class Jira implements INodeType { timeout: 5000, }; try { - const response = await this.helpers.request!(options); + await this.helpers.request!(options); } catch (err) { return { status: 'Error',