mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Small improvements to Jira-Node
This commit is contained in:
parent
57d296d30a
commit
f8869f85e8
|
@ -43,11 +43,21 @@ export async function jiraSoftwareCloudApiRequest(this: IHookFunctions | IExecut
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request!(options);
|
return await this.helpers.request!(options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage = error.response.body.message || error.response.body.error || error.response.body.errors;
|
let errorMessage = error.message;
|
||||||
if (errorMessage !== undefined) {
|
|
||||||
throw new Error(errorMessage);
|
if (error.response.body) {
|
||||||
|
if (error.response.body.errorMessages && error.response.body.errorMessages.length) {
|
||||||
|
errorMessage = JSON.stringify(error.response.body.errorMessages);
|
||||||
|
} else {
|
||||||
|
errorMessage = error.response.body.message || error.response.body.error || error.response.body.errors || error.message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw error;
|
|
||||||
|
if (typeof errorMessage !== 'string') {
|
||||||
|
errorMessage = JSON.stringify(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Jira error response [${error.statusCode}]: ${errorMessage}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -312,7 +312,10 @@ export const issueFields = [
|
||||||
{
|
{
|
||||||
displayName: 'Status ID',
|
displayName: 'Status ID',
|
||||||
name: 'statusId',
|
name: 'statusId',
|
||||||
type: 'string',
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getTransitions',
|
||||||
|
},
|
||||||
required: false,
|
required: false,
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The ID of the issue status.',
|
description: 'The ID of the issue status.',
|
||||||
|
|
|
@ -112,12 +112,11 @@ export class JiraSoftwareCloud implements INodeType {
|
||||||
async getProjects(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getProjects(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
const jiraCloudCredentials = this.getCredentials('jiraSoftwareCloudApi');
|
const jiraCloudCredentials = this.getCredentials('jiraSoftwareCloudApi');
|
||||||
let projects;
|
|
||||||
let endpoint = '/project/search';
|
let endpoint = '/project/search';
|
||||||
if (jiraCloudCredentials === undefined) {
|
if (jiraCloudCredentials === undefined) {
|
||||||
endpoint = '/project';
|
endpoint = '/project';
|
||||||
}
|
}
|
||||||
projects = await jiraSoftwareCloudApiRequest.call(this, endpoint, 'GET');
|
let projects = await jiraSoftwareCloudApiRequest.call(this, endpoint, 'GET');
|
||||||
|
|
||||||
if (projects.values && Array.isArray(projects.values)) {
|
if (projects.values && Array.isArray(projects.values)) {
|
||||||
projects = projects.values;
|
projects = projects.values;
|
||||||
|
@ -138,9 +137,8 @@ export class JiraSoftwareCloud implements INodeType {
|
||||||
async getIssueTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getIssueTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const projectId = this.getCurrentNodeParameter('project');
|
const projectId = this.getCurrentNodeParameter('project');
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
let issueTypes;
|
|
||||||
|
|
||||||
issueTypes = await jiraSoftwareCloudApiRequest.call(this, '/issuetype', 'GET');
|
const issueTypes = await jiraSoftwareCloudApiRequest.call(this, '/issuetype', 'GET');
|
||||||
|
|
||||||
for (const issueType of issueTypes) {
|
for (const issueType of issueTypes) {
|
||||||
if (issueType.scope.project.id === projectId) {
|
if (issueType.scope.project.id === projectId) {
|
||||||
|
@ -160,9 +158,8 @@ export class JiraSoftwareCloud implements INodeType {
|
||||||
// select them easily
|
// select them easily
|
||||||
async getLabels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getLabels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
let labels;
|
|
||||||
|
|
||||||
labels = await jiraSoftwareCloudApiRequest.call(this, '/label', 'GET');
|
const labels = await jiraSoftwareCloudApiRequest.call(this, '/label', 'GET');
|
||||||
|
|
||||||
for (const label of labels.values) {
|
for (const label of labels.values) {
|
||||||
const labelName = label;
|
const labelName = label;
|
||||||
|
@ -180,9 +177,8 @@ export class JiraSoftwareCloud implements INodeType {
|
||||||
// select them easily
|
// select them easily
|
||||||
async getPriorities(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getPriorities(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
let priorities;
|
|
||||||
|
|
||||||
priorities = await jiraSoftwareCloudApiRequest.call(this, '/priority', 'GET');
|
const priorities = await jiraSoftwareCloudApiRequest.call(this, '/priority', 'GET');
|
||||||
|
|
||||||
for (const priority of priorities) {
|
for (const priority of priorities) {
|
||||||
const priorityName = priority.name;
|
const priorityName = priority.name;
|
||||||
|
@ -200,9 +196,8 @@ export class JiraSoftwareCloud implements INodeType {
|
||||||
// select them easily
|
// select them easily
|
||||||
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
let users;
|
|
||||||
|
|
||||||
users = await jiraSoftwareCloudApiRequest.call(this, '/users/search', 'GET');
|
const users = await jiraSoftwareCloudApiRequest.call(this, '/users/search', 'GET');
|
||||||
|
|
||||||
for (const user of users) {
|
for (const user of users) {
|
||||||
const userName = user.displayName;
|
const userName = user.displayName;
|
||||||
|
@ -220,9 +215,8 @@ export class JiraSoftwareCloud implements INodeType {
|
||||||
// select them easily
|
// select them easily
|
||||||
async getGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
let groups;
|
|
||||||
|
|
||||||
groups = await jiraSoftwareCloudApiRequest.call(this, '/groups/picker', 'GET');
|
const groups = await jiraSoftwareCloudApiRequest.call(this, '/groups/picker', 'GET');
|
||||||
|
|
||||||
for (const group of groups.groups) {
|
for (const group of groups.groups) {
|
||||||
const groupName = group.name;
|
const groupName = group.name;
|
||||||
|
@ -234,7 +228,24 @@ export class JiraSoftwareCloud implements INodeType {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return returnData;
|
return returnData;
|
||||||
}
|
},
|
||||||
|
|
||||||
|
// Get all the groups to display them to user so that he can
|
||||||
|
// select them easily
|
||||||
|
async getTransitions(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
|
const returnData: INodePropertyOptions[] = [];
|
||||||
|
|
||||||
|
const issueKey = this.getCurrentNodeParameter('issueKey');
|
||||||
|
const transitions = await jiraSoftwareCloudApiRequest.call(this, `/issue/${issueKey}/transitions`, 'GET');
|
||||||
|
|
||||||
|
for (const transition of transitions.transitions) {
|
||||||
|
returnData.push({
|
||||||
|
name: transition.name,
|
||||||
|
value: transition.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return returnData;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue