mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
⚡ Improve jira issue field lookup (#1877)
* Improved/fixed collecting of custom fields based on project and issue type. * ⚡ Improvements to #1610 * 👕 Fix linter issue Co-authored-by: jemos <jean.mousinho@gmail.com>
This commit is contained in:
parent
77483f991d
commit
4b0d3b56cb
|
@ -358,21 +358,29 @@ export class Jira implements INodeType {
|
|||
async getCustomFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const operation = this.getCurrentNodeParameter('operation') as string;
|
||||
let projectId;
|
||||
let projectId: string;
|
||||
let issueTypeId: string;
|
||||
if (operation === 'create') {
|
||||
projectId = this.getCurrentNodeParameter('project');
|
||||
projectId = this.getCurrentNodeParameter('project') as string;
|
||||
issueTypeId = this.getCurrentNodeParameter('issueType') as string;
|
||||
} else {
|
||||
const issueKey = this.getCurrentNodeParameter('issueKey');
|
||||
const { fields: { project: { id } } } = await jiraSoftwareCloudApiRequest.call(this, `/api/2/issue/${issueKey}`, 'GET', {}, {});
|
||||
projectId = id;
|
||||
const issueKey = this.getCurrentNodeParameter('issueKey') as string;
|
||||
const res = await jiraSoftwareCloudApiRequest.call(this, `/api/2/issue/${issueKey}`, 'GET', {}, {});
|
||||
projectId = res.fields.project.id;
|
||||
issueTypeId = res.fields.issuetype.id;
|
||||
}
|
||||
const fields = await jiraSoftwareCloudApiRequest.call(this, `/api/2/field`, 'GET');
|
||||
for (const field of fields) {
|
||||
if (field.custom === true && field.scope && field.scope.project && field.scope.project.id === projectId) {
|
||||
returnData.push({
|
||||
name: field.name,
|
||||
value: field.id,
|
||||
});
|
||||
|
||||
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)) {
|
||||
const field = fields[key];
|
||||
if (field.schema && Object.keys(field.schema).includes('customId')) {
|
||||
returnData.push({
|
||||
name: field.name,
|
||||
value: field.key,
|
||||
});
|
||||
}
|
||||
}
|
||||
return returnData;
|
||||
|
|
Loading…
Reference in a new issue