mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -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,20 +358,28 @@ export class Jira implements INodeType {
|
||||||
async getCustomFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getCustomFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
const operation = this.getCurrentNodeParameter('operation') as string;
|
const operation = this.getCurrentNodeParameter('operation') as string;
|
||||||
let projectId;
|
let projectId: string;
|
||||||
|
let issueTypeId: string;
|
||||||
if (operation === 'create') {
|
if (operation === 'create') {
|
||||||
projectId = this.getCurrentNodeParameter('project');
|
projectId = this.getCurrentNodeParameter('project') as string;
|
||||||
|
issueTypeId = this.getCurrentNodeParameter('issueType') as string;
|
||||||
} else {
|
} else {
|
||||||
const issueKey = this.getCurrentNodeParameter('issueKey');
|
const issueKey = this.getCurrentNodeParameter('issueKey') as string;
|
||||||
const { fields: { project: { id } } } = await jiraSoftwareCloudApiRequest.call(this, `/api/2/issue/${issueKey}`, 'GET', {}, {});
|
const res = await jiraSoftwareCloudApiRequest.call(this, `/api/2/issue/${issueKey}`, 'GET', {}, {});
|
||||||
projectId = id;
|
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) {
|
const res = await jiraSoftwareCloudApiRequest.call(this, `/api/2/issue/createmeta?projectIds=${projectId}&issueTypeIds=${issueTypeId}&expand=projects.issuetypes.fields`, 'GET');
|
||||||
if (field.custom === true && field.scope && field.scope.project && field.scope.project.id === projectId) {
|
|
||||||
|
// 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({
|
returnData.push({
|
||||||
name: field.name,
|
name: field.name,
|
||||||
value: field.id,
|
value: field.key,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue