mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Support for Jira server
This commit is contained in:
parent
c06934d973
commit
94b13ddea2
|
@ -5,23 +5,77 @@ import {
|
||||||
|
|
||||||
export class JiraSoftwareCloudApi implements ICredentialType {
|
export class JiraSoftwareCloudApi implements ICredentialType {
|
||||||
name = 'jiraSoftwareCloudApi';
|
name = 'jiraSoftwareCloudApi';
|
||||||
displayName = 'Jira SW Cloud API';
|
displayName = 'Jira SW API';
|
||||||
properties = [
|
properties = [
|
||||||
|
{
|
||||||
|
displayName: 'Jira Version',
|
||||||
|
name: 'jiraVersion',
|
||||||
|
type: 'options' as NodePropertyTypes,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Cloud',
|
||||||
|
value: 'cloud',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Server (Self Hosted)',
|
||||||
|
value: 'server',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'cloud',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Email',
|
displayName: 'Email',
|
||||||
name: 'email',
|
name: 'email',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
jiraVersion: [
|
||||||
|
'cloud',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
type: 'string' as NodePropertyTypes,
|
type: 'string' as NodePropertyTypes,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'API Token',
|
displayName: 'API Token',
|
||||||
name: 'apiToken',
|
name: 'apiToken',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
jiraVersion: [
|
||||||
|
'cloud',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
type: 'string' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Password',
|
||||||
|
name: 'password',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
jiraVersion: [
|
||||||
|
'server',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typeOptions: {
|
||||||
|
password: true,
|
||||||
|
},
|
||||||
type: 'string' as NodePropertyTypes,
|
type: 'string' as NodePropertyTypes,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Domain',
|
displayName: 'Domain',
|
||||||
name: 'domain',
|
name: 'domain',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
jiraVersion: [
|
||||||
|
'cloud',
|
||||||
|
'server',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
type: 'string' as NodePropertyTypes,
|
type: 'string' as NodePropertyTypes,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
import {
|
|
||||||
ICredentialType,
|
|
||||||
NodePropertyTypes,
|
|
||||||
} from 'n8n-workflow';
|
|
||||||
|
|
||||||
export class JiraSoftwareServerApi implements ICredentialType {
|
|
||||||
name = 'jiraSoftwareServerApi';
|
|
||||||
displayName = 'Jira SW Server API';
|
|
||||||
properties = [
|
|
||||||
{
|
|
||||||
displayName: 'Domain',
|
|
||||||
name: 'domain',
|
|
||||||
type: 'string' as NodePropertyTypes,
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Username',
|
|
||||||
name: 'username',
|
|
||||||
type: 'string' as NodePropertyTypes,
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Password',
|
|
||||||
name: 'password',
|
|
||||||
type: 'string' as NodePropertyTypes,
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
|
|
@ -17,37 +17,7 @@ export async function jiraSoftwareCloudApiRequest(this: IHookFunctions | IExecut
|
||||||
if (credentials === undefined) {
|
if (credentials === undefined) {
|
||||||
throw new Error('No credentials got returned!');
|
throw new Error('No credentials got returned!');
|
||||||
}
|
}
|
||||||
const data = Buffer.from(`${credentials!.email}:${credentials!.apiToken}`).toString(BINARY_ENCODING);
|
const data = Buffer.from(`${credentials!.email}:${(credentials.jiraVersion === 'server') ? credentials.password : credentials.apiKey }`).toString(BINARY_ENCODING);
|
||||||
const headerWithAuthentication = Object.assign({},
|
|
||||||
{ Authorization: `Basic ${data}`, Accept: 'application/json', 'Content-Type': 'application/json' });
|
|
||||||
const options: OptionsWithUri = {
|
|
||||||
headers: headerWithAuthentication,
|
|
||||||
method,
|
|
||||||
qs: query,
|
|
||||||
uri: uri || `${credentials.domain}/rest/api/2${endpoint}`,
|
|
||||||
body,
|
|
||||||
json: true
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
return await this.helpers.request!(options);
|
|
||||||
} catch (error) {
|
|
||||||
const errorMessage =
|
|
||||||
error.response.body.message || error.response.body.Message;
|
|
||||||
|
|
||||||
if (errorMessage !== undefined) {
|
|
||||||
throw errorMessage;
|
|
||||||
}
|
|
||||||
throw error.response.body;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function jiraSoftwareServerApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise<any> { // tslint:disable-line:no-any
|
|
||||||
const credentials = this.getCredentials('jiraSoftwareServerApi');
|
|
||||||
if (credentials === undefined) {
|
|
||||||
throw new Error('No credentials got returned!');
|
|
||||||
}
|
|
||||||
const data = Buffer.from(`${credentials!.username}:${credentials!.password}`).toString(BINARY_ENCODING);
|
|
||||||
const headerWithAuthentication = Object.assign({},
|
const headerWithAuthentication = Object.assign({},
|
||||||
{ Authorization: `Basic ${data}`, Accept: 'application/json', 'Content-Type': 'application/json' });
|
{ Authorization: `Basic ${data}`, Accept: 'application/json', 'Content-Type': 'application/json' });
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
|
@ -95,29 +65,6 @@ export async function jiraSoftwareCloudApiRequestAllItems(this: IHookFunctions |
|
||||||
return returnData;
|
return returnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function jiraSoftwareServerApiRequestAllItems(this: IHookFunctions | IExecuteFunctions, propertyName: string, endpoint: string, method: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
|
||||||
|
|
||||||
const returnData: IDataObject[] = [];
|
|
||||||
|
|
||||||
let responseData;
|
|
||||||
|
|
||||||
query.maxResults = 100;
|
|
||||||
|
|
||||||
let uri: string | undefined;
|
|
||||||
|
|
||||||
do {
|
|
||||||
responseData = await jiraSoftwareCloudApiRequest.call(this, endpoint, method, body, query, uri);
|
|
||||||
uri = responseData.nextPage;
|
|
||||||
returnData.push.apply(returnData, responseData[propertyName]);
|
|
||||||
} while (
|
|
||||||
responseData.isLast !== false &&
|
|
||||||
responseData.nextPage !== undefined &&
|
|
||||||
responseData.nextPage !== null
|
|
||||||
);
|
|
||||||
|
|
||||||
return returnData;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
|
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
|
||||||
let result;
|
let result;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { INodeProperties } from "n8n-workflow";
|
import { INodeProperties } from "n8n-workflow";
|
||||||
|
|
||||||
export const issueOpeations = [
|
export const issueOperations = [
|
||||||
{
|
{
|
||||||
displayName: 'Operation',
|
displayName: 'Operation',
|
||||||
name: 'operation',
|
name: 'operation',
|
||||||
|
|
|
@ -15,7 +15,7 @@ import {
|
||||||
validateJSON,
|
validateJSON,
|
||||||
} from './GenericFunctions';
|
} from './GenericFunctions';
|
||||||
import {
|
import {
|
||||||
issueOpeations,
|
issueOperations,
|
||||||
issueFields,
|
issueFields,
|
||||||
} from './IssueDescription';
|
} from './IssueDescription';
|
||||||
import {
|
import {
|
||||||
|
@ -28,15 +28,15 @@ import {
|
||||||
|
|
||||||
export class JiraSoftwareCloud implements INodeType {
|
export class JiraSoftwareCloud implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
displayName: 'Jira Software Cloud',
|
displayName: 'Jira Software',
|
||||||
name: 'Jira Software Cloud',
|
name: 'Jira Software Cloud',
|
||||||
icon: 'file:jira.png',
|
icon: 'file:jira.png',
|
||||||
group: ['output'],
|
group: ['output'],
|
||||||
version: 1,
|
version: 1,
|
||||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||||
description: 'Consume Jira Software Cloud API',
|
description: 'Consume Jira Software API',
|
||||||
defaults: {
|
defaults: {
|
||||||
name: 'Jira Software Cloud',
|
name: 'Jira Software',
|
||||||
color: '#c02428',
|
color: '#c02428',
|
||||||
},
|
},
|
||||||
inputs: ['main'],
|
inputs: ['main'],
|
||||||
|
@ -45,7 +45,7 @@ export class JiraSoftwareCloud implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'jiraSoftwareCloudApi',
|
name: 'jiraSoftwareCloudApi',
|
||||||
required: true,
|
required: true,
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
|
@ -62,7 +62,7 @@ export class JiraSoftwareCloud implements INodeType {
|
||||||
default: 'issue',
|
default: 'issue',
|
||||||
description: 'Resource to consume.',
|
description: 'Resource to consume.',
|
||||||
},
|
},
|
||||||
...issueOpeations,
|
...issueOperations,
|
||||||
...issueFields,
|
...issueFields,
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
@ -73,16 +73,23 @@ export class JiraSoftwareCloud implements INodeType {
|
||||||
// select them easily
|
// select them easily
|
||||||
async getProjects(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getProjects(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
|
const credentials = this.getCredentials('jiraSoftwareCloudApi');
|
||||||
let projects;
|
let projects;
|
||||||
|
let endpoint = '/project/search';
|
||||||
|
if (credentials!.jiraVersion === 'server') {
|
||||||
|
endpoint = '/project';
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
projects = await jiraSoftwareCloudApiRequest.call(this, '/project/search', 'GET');
|
projects = await jiraSoftwareCloudApiRequest.call(this, endpoint, 'GET');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(`Jira Error: ${err}`);
|
throw new Error(`Jira Error: ${err}`);
|
||||||
}
|
}
|
||||||
for (const project of projects.values) {
|
if (projects.values && Array.isArray(projects.values)) {
|
||||||
|
projects = projects.values;
|
||||||
|
}
|
||||||
|
for (const project of projects) {
|
||||||
const projectName = project.name;
|
const projectName = project.name;
|
||||||
const projectId = project.id;
|
const projectId = project.id;
|
||||||
|
|
||||||
returnData.push({
|
returnData.push({
|
||||||
name: projectName,
|
name: projectName,
|
||||||
value: projectId,
|
value: projectId,
|
||||||
|
|
|
@ -1,498 +0,0 @@
|
||||||
import {
|
|
||||||
IExecuteFunctions,
|
|
||||||
} from 'n8n-core';
|
|
||||||
import {
|
|
||||||
IDataObject,
|
|
||||||
INodeTypeDescription,
|
|
||||||
INodeExecutionData,
|
|
||||||
INodeType,
|
|
||||||
ILoadOptionsFunctions,
|
|
||||||
INodePropertyOptions,
|
|
||||||
} from 'n8n-workflow';
|
|
||||||
import {
|
|
||||||
jiraSoftwareServerApiRequest,
|
|
||||||
jiraSoftwareServerApiRequestAllItems,
|
|
||||||
validateJSON,
|
|
||||||
} from './GenericFunctions';
|
|
||||||
import {
|
|
||||||
issueOpeations,
|
|
||||||
issueFields,
|
|
||||||
} from './IssueDescription';
|
|
||||||
import {
|
|
||||||
IIssue,
|
|
||||||
IFields,
|
|
||||||
INotify,
|
|
||||||
INotificationRecipients,
|
|
||||||
NotificationRecipientsRestrictions,
|
|
||||||
} from './IssueInterface';
|
|
||||||
|
|
||||||
export class JiraSoftwareServer implements INodeType {
|
|
||||||
description: INodeTypeDescription = {
|
|
||||||
displayName: 'Jira Software Server',
|
|
||||||
name: 'Jira Software Server',
|
|
||||||
icon: 'file:jira.png',
|
|
||||||
group: ['output'],
|
|
||||||
version: 1,
|
|
||||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
||||||
description: 'Consume Jira Software Server API',
|
|
||||||
defaults: {
|
|
||||||
name: 'Jira Software Server',
|
|
||||||
color: '#c02428',
|
|
||||||
},
|
|
||||||
inputs: ['main'],
|
|
||||||
outputs: ['main'],
|
|
||||||
credentials: [
|
|
||||||
{
|
|
||||||
name: 'jiraSoftwareServerApi',
|
|
||||||
required: true,
|
|
||||||
}
|
|
||||||
],
|
|
||||||
properties: [
|
|
||||||
{
|
|
||||||
displayName: 'Resource',
|
|
||||||
name: 'resource',
|
|
||||||
type: 'options',
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
name: 'Issue',
|
|
||||||
value: 'issue',
|
|
||||||
description: 'Creates an issue or, where the option to create subtasks is enabled in Jira, a subtask',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
default: 'issue',
|
|
||||||
description: 'Resource to consume.',
|
|
||||||
},
|
|
||||||
...issueOpeations,
|
|
||||||
...issueFields,
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
methods = {
|
|
||||||
loadOptions: {
|
|
||||||
// Get all the projects to display them to user so that he can
|
|
||||||
// select them easily
|
|
||||||
async getProjects(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
||||||
const returnData: INodePropertyOptions[] = [];
|
|
||||||
let projects;
|
|
||||||
try {
|
|
||||||
projects = await jiraSoftwareServerApiRequest.call(this, '/project/search', 'GET');
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Jira Error: ${err}`);
|
|
||||||
}
|
|
||||||
for (const project of projects.values) {
|
|
||||||
const projectName = project.name;
|
|
||||||
const projectId = project.id;
|
|
||||||
|
|
||||||
returnData.push({
|
|
||||||
name: projectName,
|
|
||||||
value: projectId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return returnData;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Get all the issue types to display them to user so that he can
|
|
||||||
// select them easily
|
|
||||||
async getIssueTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
||||||
const returnData: INodePropertyOptions[] = [];
|
|
||||||
let issueTypes;
|
|
||||||
try {
|
|
||||||
issueTypes = await jiraSoftwareServerApiRequest.call(this, '/issuetype', 'GET');
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Jira Error: ${err}`);
|
|
||||||
}
|
|
||||||
for (const issueType of issueTypes) {
|
|
||||||
const issueTypeName = issueType.name;
|
|
||||||
const issueTypeId = issueType.id;
|
|
||||||
|
|
||||||
returnData.push({
|
|
||||||
name: issueTypeName,
|
|
||||||
value: issueTypeId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return returnData;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Get all the labels to display them to user so that he can
|
|
||||||
// select them easily
|
|
||||||
async getLabels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
||||||
const returnData: INodePropertyOptions[] = [];
|
|
||||||
let labels;
|
|
||||||
try {
|
|
||||||
labels = await jiraSoftwareServerApiRequest.call(this, '/label', 'GET');
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Jira Error: ${err}`);
|
|
||||||
}
|
|
||||||
for (const label of labels.values) {
|
|
||||||
const labelName = label;
|
|
||||||
const labelId = label;
|
|
||||||
|
|
||||||
returnData.push({
|
|
||||||
name: labelName,
|
|
||||||
value: labelId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return returnData;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Get all the priorities to display them to user so that he can
|
|
||||||
// select them easily
|
|
||||||
async getPriorities(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
||||||
const returnData: INodePropertyOptions[] = [];
|
|
||||||
let priorities;
|
|
||||||
try {
|
|
||||||
priorities = await jiraSoftwareServerApiRequest.call(this, '/priority', 'GET');
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Jira Error: ${err}`);
|
|
||||||
}
|
|
||||||
for (const priority of priorities) {
|
|
||||||
const priorityName = priority.name;
|
|
||||||
const priorityId = priority.id;
|
|
||||||
|
|
||||||
returnData.push({
|
|
||||||
name: priorityName,
|
|
||||||
value: priorityId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return returnData;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Get all the users to display them to user so that he can
|
|
||||||
// select them easily
|
|
||||||
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
||||||
const returnData: INodePropertyOptions[] = [];
|
|
||||||
let users;
|
|
||||||
try {
|
|
||||||
users = await jiraSoftwareServerApiRequest.call(this, '/users/search', 'GET');
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Jira Error: ${err}`);
|
|
||||||
}
|
|
||||||
for (const user of users) {
|
|
||||||
const userName = user.displayName;
|
|
||||||
const userId = user.accountId;
|
|
||||||
|
|
||||||
returnData.push({
|
|
||||||
name: userName,
|
|
||||||
value: userId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return returnData;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Get all the groups to display them to user so that he can
|
|
||||||
// select them easily
|
|
||||||
async getGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
||||||
const returnData: INodePropertyOptions[] = [];
|
|
||||||
let groups;
|
|
||||||
try {
|
|
||||||
groups = await jiraSoftwareServerApiRequest.call(this, '/groups/picker', 'GET');
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Jira Error: ${err}`);
|
|
||||||
}
|
|
||||||
for (const group of groups.groups) {
|
|
||||||
const groupName = group.name;
|
|
||||||
const groupId = group.name;
|
|
||||||
|
|
||||||
returnData.push({
|
|
||||||
name: groupName,
|
|
||||||
value: groupId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return returnData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
||||||
const items = this.getInputData();
|
|
||||||
const returnData: IDataObject[] = [];
|
|
||||||
const length = items.length as unknown as number;
|
|
||||||
let responseData;
|
|
||||||
const qs: IDataObject = {};
|
|
||||||
|
|
||||||
const resource = this.getNodeParameter('resource', 0) as string;
|
|
||||||
const operation = this.getNodeParameter('operation', 0) as string;
|
|
||||||
|
|
||||||
for (let i = 0; i < length; i++) {
|
|
||||||
if (resource === 'issue') {
|
|
||||||
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-post
|
|
||||||
if (operation === 'create') {
|
|
||||||
const summary = this.getNodeParameter('summary', i) as string;
|
|
||||||
const projectId = this.getNodeParameter('project', i) as string;
|
|
||||||
const issueTypeId = this.getNodeParameter('issueType', i) as string;
|
|
||||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
||||||
const body: IIssue = {};
|
|
||||||
const fields: IFields = {
|
|
||||||
summary,
|
|
||||||
project: {
|
|
||||||
id: projectId,
|
|
||||||
},
|
|
||||||
issuetype: {
|
|
||||||
id: issueTypeId,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
if (additionalFields.labels) {
|
|
||||||
fields.labels = additionalFields.labels as string[];
|
|
||||||
}
|
|
||||||
if (additionalFields.priority) {
|
|
||||||
fields.priority = {
|
|
||||||
id: additionalFields.priority as string,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (additionalFields.assignee) {
|
|
||||||
fields.assignee = {
|
|
||||||
id: additionalFields.assignee as string,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (additionalFields.description) {
|
|
||||||
fields.description = additionalFields.description as string;
|
|
||||||
}
|
|
||||||
if (additionalFields.updateHistory) {
|
|
||||||
qs.updateHistory = additionalFields.updateHistory as boolean;
|
|
||||||
}
|
|
||||||
const issueTypes = await jiraSoftwareServerApiRequest.call(this, '/issuetype', 'GET', body, qs);
|
|
||||||
const subtaskIssues = [];
|
|
||||||
for (const issueType of issueTypes) {
|
|
||||||
if (issueType.subtask) {
|
|
||||||
subtaskIssues.push(issueType.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!additionalFields.parentIssueKey
|
|
||||||
&& subtaskIssues.includes(issueTypeId)) {
|
|
||||||
throw new Error('You must define a Parent Issue Key when Issue type is sub-task');
|
|
||||||
|
|
||||||
} else if (additionalFields.parentIssueKey
|
|
||||||
&& subtaskIssues.includes(issueTypeId)) {
|
|
||||||
fields.parent = {
|
|
||||||
key: (additionalFields.parentIssueKey as string).toUpperCase(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
body.fields = fields;
|
|
||||||
try {
|
|
||||||
responseData = await jiraSoftwareServerApiRequest.call(this, '/issue', 'POST', body);
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Jira Error: ${JSON.stringify(err)}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-put
|
|
||||||
if (operation === 'update') {
|
|
||||||
const issueKey = this.getNodeParameter('issueKey', i) as string;
|
|
||||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
||||||
const body: IIssue = {};
|
|
||||||
const fields: IFields = {};
|
|
||||||
if (updateFields.summary) {
|
|
||||||
fields.summary = updateFields.summary as string;
|
|
||||||
}
|
|
||||||
if (updateFields.issueType) {
|
|
||||||
fields.issuetype = {
|
|
||||||
id: updateFields.issueType as string,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (updateFields.labels) {
|
|
||||||
fields.labels = updateFields.labels as string[];
|
|
||||||
}
|
|
||||||
if (updateFields.priority) {
|
|
||||||
fields.priority = {
|
|
||||||
id: updateFields.priority as string,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (updateFields.assignee) {
|
|
||||||
fields.assignee = {
|
|
||||||
id: updateFields.assignee as string,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (updateFields.description) {
|
|
||||||
fields.description = updateFields.description as string;
|
|
||||||
}
|
|
||||||
const issueTypes = await jiraSoftwareServerApiRequest.call(this, '/issuetype', 'GET', body);
|
|
||||||
const subtaskIssues = [];
|
|
||||||
for (const issueType of issueTypes) {
|
|
||||||
if (issueType.subtask) {
|
|
||||||
subtaskIssues.push(issueType.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!updateFields.parentIssueKey
|
|
||||||
&& subtaskIssues.includes(updateFields.issueType)) {
|
|
||||||
throw new Error('You must define a Parent Issue Key when Issue type is sub-task');
|
|
||||||
|
|
||||||
} else if (updateFields.parentIssueKey
|
|
||||||
&& subtaskIssues.includes(updateFields.issueType)) {
|
|
||||||
fields.parent = {
|
|
||||||
key: (updateFields.parentIssueKey as string).toUpperCase(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
body.fields = fields;
|
|
||||||
try {
|
|
||||||
responseData = await jiraSoftwareServerApiRequest.call(this, `/issue/${issueKey}`, 'PUT', body);
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Jira Error: ${JSON.stringify(err)}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-get
|
|
||||||
if (operation === 'get') {
|
|
||||||
const issueKey = this.getNodeParameter('issueKey', i) as string;
|
|
||||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
||||||
if (additionalFields.fields) {
|
|
||||||
qs.fields = additionalFields.fields as string;
|
|
||||||
}
|
|
||||||
if (additionalFields.fieldsByKey) {
|
|
||||||
qs.fieldsByKey = additionalFields.fieldsByKey as boolean;
|
|
||||||
}
|
|
||||||
if (additionalFields.expand) {
|
|
||||||
qs.expand = additionalFields.expand as string;
|
|
||||||
}
|
|
||||||
if (additionalFields.properties) {
|
|
||||||
qs.properties = additionalFields.properties as string;
|
|
||||||
}
|
|
||||||
if (additionalFields.updateHistory) {
|
|
||||||
qs.updateHistory = additionalFields.updateHistory as string;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
responseData = await jiraSoftwareServerApiRequest.call(this, `/issue/${issueKey}`, 'GET', {}, qs);
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Jira Error: ${JSON.stringify(err)}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-changelog-get
|
|
||||||
if (operation === 'changelog') {
|
|
||||||
const issueKey = this.getNodeParameter('issueKey', i) as string;
|
|
||||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
|
||||||
try {
|
|
||||||
if (returnAll) {
|
|
||||||
responseData = await jiraSoftwareServerApiRequestAllItems.call(this, 'values',`/issue/${issueKey}/changelog`, 'GET');
|
|
||||||
} else {
|
|
||||||
qs.maxResults = this.getNodeParameter('limit', i) as number;
|
|
||||||
responseData = await jiraSoftwareServerApiRequest.call(this, `/issue/${issueKey}/changelog`, 'GET', {}, qs);
|
|
||||||
responseData = responseData.values;
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Jira Error: ${JSON.stringify(err)}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-notify-post
|
|
||||||
if (operation === 'notify') {
|
|
||||||
const issueKey = this.getNodeParameter('issueKey', i) as string;
|
|
||||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
||||||
const jsonActive = this.getNodeParameter('jsonParameters', 0) as boolean;
|
|
||||||
const body: INotify = {};
|
|
||||||
if (additionalFields.textBody) {
|
|
||||||
body.textBody = additionalFields.textBody as string;
|
|
||||||
}
|
|
||||||
if (additionalFields.htmlBody) {
|
|
||||||
body.htmlBody = additionalFields.htmlBody as string;
|
|
||||||
}
|
|
||||||
if (!jsonActive) {
|
|
||||||
const notificationRecipientsValues = (this.getNodeParameter('notificationRecipientsUi', i) as IDataObject).notificationRecipientsValues as IDataObject[];
|
|
||||||
const notificationRecipients: INotificationRecipients = {};
|
|
||||||
if (notificationRecipientsValues) {
|
|
||||||
// @ts-ignore
|
|
||||||
if (notificationRecipientsValues.reporter) {
|
|
||||||
// @ts-ignore
|
|
||||||
notificationRecipients.reporter = notificationRecipientsValues.reporter as boolean;
|
|
||||||
}
|
|
||||||
// @ts-ignore
|
|
||||||
if (notificationRecipientsValues.assignee) {
|
|
||||||
// @ts-ignore
|
|
||||||
notificationRecipients.assignee = notificationRecipientsValues.assignee as boolean;
|
|
||||||
}
|
|
||||||
// @ts-ignore
|
|
||||||
if (notificationRecipientsValues.assignee) {
|
|
||||||
// @ts-ignore
|
|
||||||
notificationRecipients.watchers = notificationRecipientsValues.watchers as boolean;
|
|
||||||
}
|
|
||||||
// @ts-ignore
|
|
||||||
if (notificationRecipientsValues.voters) {
|
|
||||||
// @ts-ignore
|
|
||||||
notificationRecipients.watchers = notificationRecipientsValues.voters as boolean;
|
|
||||||
}
|
|
||||||
// @ts-ignore
|
|
||||||
if (notificationRecipientsValues.users.length > 0) {
|
|
||||||
// @ts-ignore
|
|
||||||
notificationRecipients.users = notificationRecipientsValues.users.map(user => {
|
|
||||||
return {
|
|
||||||
accountId: user
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// @ts-ignore
|
|
||||||
if (notificationRecipientsValues.groups.length > 0) {
|
|
||||||
// @ts-ignore
|
|
||||||
notificationRecipients.groups = notificationRecipientsValues.groups.map(group => {
|
|
||||||
return {
|
|
||||||
name: group
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
body.to = notificationRecipients;
|
|
||||||
const notificationRecipientsRestrictionsValues = (this.getNodeParameter('notificationRecipientsRestrictionsUi', i) as IDataObject).notificationRecipientsRestrictionsValues as IDataObject[];
|
|
||||||
const notificationRecipientsRestrictions: NotificationRecipientsRestrictions = {};
|
|
||||||
if (notificationRecipientsRestrictionsValues) {
|
|
||||||
// @ts-ignore
|
|
||||||
if (notificationRecipientsRestrictionsValues.groups. length > 0) {
|
|
||||||
// @ts-ignore
|
|
||||||
notificationRecipientsRestrictions.groups = notificationRecipientsRestrictionsValues.groups.map(group => {
|
|
||||||
return {
|
|
||||||
name: group
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
body.restrict = notificationRecipientsRestrictions;
|
|
||||||
} else {
|
|
||||||
const notificationRecipientsJson = validateJSON(this.getNodeParameter('notificationRecipientsJson', i) as string);
|
|
||||||
if (notificationRecipientsJson) {
|
|
||||||
body.to = notificationRecipientsJson;
|
|
||||||
}
|
|
||||||
const notificationRecipientsRestrictionsJson = validateJSON(this.getNodeParameter('notificationRecipientsRestrictionsJson', i) as string);
|
|
||||||
if (notificationRecipientsRestrictionsJson) {
|
|
||||||
body.restrict = notificationRecipientsRestrictionsJson;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
responseData = await jiraSoftwareServerApiRequest.call(this, `/issue/${issueKey}/notify`, 'POST', body, qs);
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Jira Error: ${JSON.stringify(err)}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-transitions-get
|
|
||||||
if (operation === 'transitions') {
|
|
||||||
const issueKey = this.getNodeParameter('issueKey', i) as string;
|
|
||||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
||||||
if (additionalFields.transitionId) {
|
|
||||||
qs.transitionId = additionalFields.transitionId as string;
|
|
||||||
}
|
|
||||||
if (additionalFields.expand) {
|
|
||||||
qs.expand = additionalFields.expand as string;
|
|
||||||
}
|
|
||||||
if (additionalFields.skipRemoteOnlyCondition) {
|
|
||||||
qs.skipRemoteOnlyCondition = additionalFields.skipRemoteOnlyCondition as boolean;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
responseData = await jiraSoftwareServerApiRequest.call(this, `/issue/${issueKey}/transitions`, 'GET', {}, qs);
|
|
||||||
responseData = responseData.transitions;
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Jira Error: ${JSON.stringify(err)}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-delete
|
|
||||||
if (operation === 'delete') {
|
|
||||||
const issueKey = this.getNodeParameter('issueKey', i) as string;
|
|
||||||
const deleteSubtasks = this.getNodeParameter('deleteSubtasks', i) as boolean;
|
|
||||||
qs.deleteSubtasks = deleteSubtasks;
|
|
||||||
try {
|
|
||||||
responseData = await jiraSoftwareServerApiRequest.call(this, `/issue/${issueKey}`, 'DELETE', {}, qs);
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Jira Error: ${JSON.stringify(err)}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Array.isArray(responseData)) {
|
|
||||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
|
||||||
} else {
|
|
||||||
returnData.push(responseData as IDataObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return [this.helpers.returnJsonArray(returnData)];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -58,7 +58,6 @@
|
||||||
"dist/credentials/Imap.credentials.js",
|
"dist/credentials/Imap.credentials.js",
|
||||||
"dist/credentials/IntercomApi.credentials.js",
|
"dist/credentials/IntercomApi.credentials.js",
|
||||||
"dist/credentials/JiraSoftwareCloudApi.credentials.js",
|
"dist/credentials/JiraSoftwareCloudApi.credentials.js",
|
||||||
"dist/credentials/JiraSoftwareServerApi.credentials.js",
|
|
||||||
"dist/credentials/JotFormApi.credentials.js",
|
"dist/credentials/JotFormApi.credentials.js",
|
||||||
"dist/credentials/LinkFishApi.credentials.js",
|
"dist/credentials/LinkFishApi.credentials.js",
|
||||||
"dist/credentials/MailchimpApi.credentials.js",
|
"dist/credentials/MailchimpApi.credentials.js",
|
||||||
|
@ -150,7 +149,6 @@
|
||||||
"dist/nodes/Intercom/Intercom.node.js",
|
"dist/nodes/Intercom/Intercom.node.js",
|
||||||
"dist/nodes/Interval.node.js",
|
"dist/nodes/Interval.node.js",
|
||||||
"dist/nodes/Jira/JiraSoftwareCloud.node.js",
|
"dist/nodes/Jira/JiraSoftwareCloud.node.js",
|
||||||
"dist/nodes/Jira/JiraSoftwareServer.node.js",
|
|
||||||
"dist/nodes/JotForm/JotFormTrigger.node.js",
|
"dist/nodes/JotForm/JotFormTrigger.node.js",
|
||||||
"dist/nodes/LinkFish/LinkFish.node.js",
|
"dist/nodes/LinkFish/LinkFish.node.js",
|
||||||
"dist/nodes/Mailchimp/Mailchimp.node.js",
|
"dist/nodes/Mailchimp/Mailchimp.node.js",
|
||||||
|
|
Loading…
Reference in a new issue