mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
feat(Jira Node): Use Jira rendered fields with simplify option (#3323)
* 💄 Use Jira rendered fields with simplify * 🐛 Merge the renderedField results with fields * ⚡ improvements * ⚡ Improvements Co-authored-by: Michael Kret <michael.k@radency.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
parent
59f2e8e7d5
commit
07b6cffdba
|
@ -1,4 +1,6 @@
|
||||||
import {
|
import {
|
||||||
|
IAuthenticateGeneric,
|
||||||
|
ICredentialTestRequest,
|
||||||
ICredentialType,
|
ICredentialType,
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
@ -29,4 +31,19 @@ export class JiraSoftwareCloudApi implements ICredentialType {
|
||||||
placeholder: 'https://example.atlassian.net',
|
placeholder: 'https://example.atlassian.net',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
authenticate: IAuthenticateGeneric = {
|
||||||
|
type: 'generic',
|
||||||
|
properties: {
|
||||||
|
auth:{
|
||||||
|
username: '={{$credentials.email}}',
|
||||||
|
password: '={{$credentials.apiToken}}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
test: ICredentialTestRequest = {
|
||||||
|
request: {
|
||||||
|
baseURL: '={{$credentials?.domain}}',
|
||||||
|
url: '/rest/api/2/project',
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import {
|
import {
|
||||||
|
IAuthenticateGeneric,
|
||||||
|
ICredentialTestRequest,
|
||||||
ICredentialType,
|
ICredentialType,
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
@ -32,4 +34,19 @@ export class JiraSoftwareServerApi implements ICredentialType {
|
||||||
placeholder: 'https://example.com',
|
placeholder: 'https://example.com',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
authenticate: IAuthenticateGeneric = {
|
||||||
|
type: 'generic',
|
||||||
|
properties: {
|
||||||
|
auth:{
|
||||||
|
username: '={{$credentials.email}}',
|
||||||
|
password: '={{$credentials.password}}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
test: ICredentialTestRequest = {
|
||||||
|
request: {
|
||||||
|
baseURL: '={{$credentials?.domain}}',
|
||||||
|
url: '/rest/api/2/project',
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,28 +18,22 @@ import {
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export async function jiraSoftwareCloudApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
export async function jiraSoftwareCloudApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||||
let data; let domain;
|
|
||||||
|
|
||||||
const jiraVersion = this.getNodeParameter('jiraVersion', 0) as string;
|
const jiraVersion = this.getNodeParameter('jiraVersion', 0) as string;
|
||||||
|
|
||||||
let jiraCredentials: ICredentialDataDecryptedObject;
|
let domain = '';
|
||||||
if (jiraVersion === 'server') {
|
let credentialType: string;
|
||||||
jiraCredentials = await this.getCredentials('jiraSoftwareServerApi');
|
|
||||||
} else {
|
|
||||||
jiraCredentials = await this.getCredentials('jiraSoftwareCloudApi');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jiraVersion === 'server') {
|
if (jiraVersion === 'server') {
|
||||||
domain = jiraCredentials!.domain;
|
domain = (await this.getCredentials('jiraSoftwareServerApi')).domain as string;
|
||||||
data = Buffer.from(`${jiraCredentials!.email}:${jiraCredentials!.password}`).toString('base64');
|
credentialType = 'jiraSoftwareServerApi';
|
||||||
} else {
|
} else {
|
||||||
domain = jiraCredentials!.domain;
|
domain = (await this.getCredentials('jiraSoftwareCloudApi')).domain as string;
|
||||||
data = Buffer.from(`${jiraCredentials!.email}:${jiraCredentials!.apiToken}`).toString('base64');
|
credentialType = 'jiraSoftwareCloudApi';
|
||||||
}
|
}
|
||||||
|
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Basic ${data}`,
|
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-Atlassian-Token': 'no-check',
|
'X-Atlassian-Token': 'no-check',
|
||||||
|
@ -64,7 +58,7 @@ export async function jiraSoftwareCloudApiRequest(this: IHookFunctions | IExecut
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request!(options);
|
return await this.helpers.requestWithAuthentication.call(this, credentialType, options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
import {
|
import {
|
||||||
OptionsWithUri,
|
mergeWith,
|
||||||
} from 'request';
|
} from 'lodash';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
|
@ -9,16 +10,12 @@ import {
|
||||||
import {
|
import {
|
||||||
IBinaryData,
|
IBinaryData,
|
||||||
IBinaryKeyData,
|
IBinaryKeyData,
|
||||||
ICredentialsDecrypted,
|
|
||||||
ICredentialTestFunctions,
|
|
||||||
IDataObject,
|
IDataObject,
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
INodeCredentialTestResult,
|
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodePropertyOptions,
|
INodePropertyOptions,
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
JsonObject,
|
|
||||||
NodeOperationError,
|
NodeOperationError,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
@ -82,7 +79,6 @@ export class Jira implements INodeType {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
testedBy: 'jiraSoftwareApiTest',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'jiraSoftwareServerApi',
|
name: 'jiraSoftwareServerApi',
|
||||||
|
@ -94,7 +90,6 @@ export class Jira implements INodeType {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
testedBy: 'jiraSoftwareApiTest',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
|
@ -155,40 +150,6 @@ export class Jira implements INodeType {
|
||||||
};
|
};
|
||||||
|
|
||||||
methods = {
|
methods = {
|
||||||
credentialTest: {
|
|
||||||
async jiraSoftwareApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise<INodeCredentialTestResult> {
|
|
||||||
const credentials = credential.data;
|
|
||||||
const data = Buffer.from(`${credentials!.email}:${credentials!.password || credentials!.apiToken}`).toString('base64');
|
|
||||||
|
|
||||||
const options: OptionsWithUri = {
|
|
||||||
headers: {
|
|
||||||
Authorization: `Basic ${data}`,
|
|
||||||
Accept: 'application/json',
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-Atlassian-Token': 'no-check',
|
|
||||||
},
|
|
||||||
method: 'GET',
|
|
||||||
uri: `${credentials!.domain}/rest/api/2/project`,
|
|
||||||
qs: {
|
|
||||||
recent: 0,
|
|
||||||
},
|
|
||||||
json: true,
|
|
||||||
timeout: 5000,
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
await this.helpers.request!(options);
|
|
||||||
} catch (err) {
|
|
||||||
return {
|
|
||||||
status: 'Error',
|
|
||||||
message: `Connection details not valid: ${(err as JsonObject).message}`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
status: 'OK',
|
|
||||||
message: 'Authentication successful!',
|
|
||||||
};
|
|
||||||
},
|
|
||||||
},
|
|
||||||
loadOptions: {
|
loadOptions: {
|
||||||
// Get all the projects to display them to user so that he can
|
// Get all the projects to display them to user so that he can
|
||||||
// select them easily
|
// select them easily
|
||||||
|
@ -651,6 +612,17 @@ export class Jira implements INodeType {
|
||||||
responseData = await jiraSoftwareCloudApiRequest.call(this, `/api/2/issue/${issueKey}`, 'GET', {}, qs);
|
responseData = await jiraSoftwareCloudApiRequest.call(this, `/api/2/issue/${issueKey}`, 'GET', {}, qs);
|
||||||
|
|
||||||
if (simplifyOutput) {
|
if (simplifyOutput) {
|
||||||
|
// Use rendered fields if requested and available
|
||||||
|
qs.expand = qs.expand || '';
|
||||||
|
if (
|
||||||
|
(qs.expand as string).toLowerCase().indexOf('renderedfields') !== -1 &&
|
||||||
|
responseData.renderedFields && Object.keys(responseData.renderedFields).length
|
||||||
|
) {
|
||||||
|
responseData.fields = mergeWith(
|
||||||
|
responseData.fields,
|
||||||
|
responseData.renderedFields,
|
||||||
|
(a,b) => b === null ? a : b);
|
||||||
|
}
|
||||||
returnData.push(simplifyIssueOutput(responseData));
|
returnData.push(simplifyIssueOutput(responseData));
|
||||||
} else {
|
} else {
|
||||||
returnData.push(responseData);
|
returnData.push(responseData);
|
||||||
|
|
Loading…
Reference in a new issue