mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
🔀 Merge branch 'RicardoE105-feature/jira-server-node'
This commit is contained in:
commit
0aea33bbc5
|
@ -24,6 +24,7 @@ export class JiraSoftwareCloudApi implements ICredentialType {
|
||||||
name: 'domain',
|
name: 'domain',
|
||||||
type: 'string' as NodePropertyTypes,
|
type: 'string' as NodePropertyTypes,
|
||||||
default: '',
|
default: '',
|
||||||
|
placeholder: 'https://example.atlassian.net',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
import {
|
||||||
|
ICredentialType,
|
||||||
|
NodePropertyTypes,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export class JiraSoftwareServerApi implements ICredentialType {
|
||||||
|
name = 'jiraSoftwareServerApi';
|
||||||
|
displayName = 'Jira SW Server API';
|
||||||
|
properties = [
|
||||||
|
{
|
||||||
|
displayName: 'Email',
|
||||||
|
name: 'email',
|
||||||
|
type: 'string' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Password',
|
||||||
|
name: 'password',
|
||||||
|
typeOptions: {
|
||||||
|
password: true,
|
||||||
|
},
|
||||||
|
type: 'string' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Domain',
|
||||||
|
name: 'domain',
|
||||||
|
type: 'string' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
placeholder: 'https://example.com',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
|
@ -2,10 +2,9 @@ import { OptionsWithUri } from 'request';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
|
IExecuteSingleFunctions,
|
||||||
IHookFunctions,
|
IHookFunctions,
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
IExecuteSingleFunctions,
|
|
||||||
BINARY_ENCODING
|
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -13,18 +12,28 @@ 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): 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): Promise<any> { // tslint:disable-line:no-any
|
||||||
const credentials = this.getCredentials('jiraSoftwareCloudApi');
|
let data; let domain;
|
||||||
if (credentials === undefined) {
|
const jiraCloudCredentials = this.getCredentials('jiraSoftwareCloudApi');
|
||||||
|
const jiraServerCredentials = this.getCredentials('jiraSoftwareServerApi');
|
||||||
|
if (jiraCloudCredentials === undefined && jiraServerCredentials === 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);
|
if (jiraCloudCredentials !== undefined) {
|
||||||
const headerWithAuthentication = Object.assign({},
|
domain = jiraCloudCredentials!.domain;
|
||||||
{ Authorization: `Basic ${data}`, Accept: 'application/json', 'Content-Type': 'application/json' });
|
data = Buffer.from(`${jiraCloudCredentials!.email}:${jiraCloudCredentials!.apiToken}`).toString('base64');
|
||||||
|
} else {
|
||||||
|
domain = jiraServerCredentials!.domain;
|
||||||
|
data = Buffer.from(`${jiraServerCredentials!.email}:${jiraServerCredentials!.password}`).toString('base64');
|
||||||
|
}
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
headers: headerWithAuthentication,
|
headers: {
|
||||||
|
Authorization: `Basic ${data}`,
|
||||||
|
Accept: 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
method,
|
method,
|
||||||
qs: query,
|
qs: query,
|
||||||
uri: uri || `${credentials.domain}/rest/api/2${endpoint}`,
|
uri: uri || `${domain}/rest/api/2${endpoint}`,
|
||||||
body,
|
body,
|
||||||
json: true
|
json: true
|
||||||
};
|
};
|
||||||
|
@ -32,46 +41,37 @@ 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 =
|
let errorMessage = error;
|
||||||
error.response.body.message || error.response.body.Message;
|
if (error.error && error.error.errorMessages) {
|
||||||
|
errorMessage = error.error.errorMessages;
|
||||||
if (errorMessage !== undefined) {
|
|
||||||
throw errorMessage;
|
|
||||||
}
|
}
|
||||||
throw error.response.body;
|
throw new Error(errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make an API request to paginated intercom endpoint
|
|
||||||
* and return all results
|
|
||||||
*/
|
|
||||||
export async function jiraSoftwareCloudApiRequestAllItems(this: IHookFunctions | IExecuteFunctions, propertyName: string, endpoint: string, method: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
export async function jiraSoftwareCloudApiRequestAllItems(this: IHookFunctions | IExecuteFunctions, propertyName: string, endpoint: string, method: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||||
|
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
|
|
||||||
let responseData;
|
let responseData;
|
||||||
|
|
||||||
|
query.startAt = 0;
|
||||||
|
body.startAt = 0;
|
||||||
query.maxResults = 100;
|
query.maxResults = 100;
|
||||||
|
body.maxResults = 100;
|
||||||
let uri: string | undefined;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
responseData = await jiraSoftwareCloudApiRequest.call(this, endpoint, method, body, query, uri);
|
responseData = await jiraSoftwareCloudApiRequest.call(this, endpoint, method, body, query);
|
||||||
uri = responseData.nextPage;
|
|
||||||
returnData.push.apply(returnData, responseData[propertyName]);
|
returnData.push.apply(returnData, responseData[propertyName]);
|
||||||
|
query.startAt = responseData.startAt + responseData.maxResults;
|
||||||
|
body.startAt = responseData.startAt + responseData.maxResults;
|
||||||
} while (
|
} while (
|
||||||
responseData.isLast !== false &&
|
(responseData.startAt + responseData.maxResults < responseData.total)
|
||||||
responseData.nextPage !== undefined &&
|
|
||||||
responseData.nextPage !== null
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return returnData;
|
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',
|
||||||
|
@ -28,6 +28,11 @@ export const issueOpeations = [
|
||||||
value: 'get',
|
value: 'get',
|
||||||
description: 'Get an issue',
|
description: 'Get an issue',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Get All',
|
||||||
|
value: 'getAll',
|
||||||
|
description: 'Get all issues',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Changelog',
|
name: 'Changelog',
|
||||||
value: 'changelog',
|
value: 'changelog',
|
||||||
|
@ -452,6 +457,148 @@ export const issueFields = [
|
||||||
},
|
},
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* issue:getAll */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
displayName: 'Return All',
|
||||||
|
name: 'returnAll',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'issue',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
description: 'If all results should be returned or only up to a given limit.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Limit',
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'issue',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
returnAll: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typeOptions: {
|
||||||
|
minValue: 1,
|
||||||
|
maxValue: 100,
|
||||||
|
},
|
||||||
|
default: 50,
|
||||||
|
description: 'How many results to return.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Options',
|
||||||
|
name: 'options',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Add Option',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'issue',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: {},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Expand',
|
||||||
|
name: 'expand',
|
||||||
|
type: 'options',
|
||||||
|
default: '',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Changelog',
|
||||||
|
value: 'changelog',
|
||||||
|
description: 'Returns a list of recent updates to an issue, sorted by date, starting from the most recent.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Editmeta',
|
||||||
|
value: 'editmeta',
|
||||||
|
description: 'Returns information about how each field can be edited',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Names',
|
||||||
|
value: 'names',
|
||||||
|
description: 'Returns the display name of each field',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Operations',
|
||||||
|
value: 'operations',
|
||||||
|
description: 'Returns all possible operations for the issue.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Rendered Fields',
|
||||||
|
value: 'renderedFields',
|
||||||
|
description: ' Returns field values rendered in HTML format.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Schema',
|
||||||
|
value: 'schema',
|
||||||
|
description: 'Returns the schema describing a field type.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Transitions',
|
||||||
|
value: 'transitions',
|
||||||
|
description: ' Returns all possible transitions for the issue.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Versioned Representations',
|
||||||
|
value: 'versionedRepresentations',
|
||||||
|
description: `JSON array containing each version of a field's value`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
description: `Use expand to include additional information about issues in the response`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Fields',
|
||||||
|
name: 'fields',
|
||||||
|
type: 'string',
|
||||||
|
default: '*navigable',
|
||||||
|
description: `A list of fields to return for each issue, use it to retrieve a subset of fields. This parameter accepts a comma-separated list. Expand options include:<br/>
|
||||||
|
*all Returns all fields.<br/>
|
||||||
|
*navigable Returns navigable fields.<br/>
|
||||||
|
Any issue field, prefixed with a minus to exclude.<br/>`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Fields By Key',
|
||||||
|
name: 'fieldsByKey',
|
||||||
|
type: 'boolean',
|
||||||
|
required: false,
|
||||||
|
default: false,
|
||||||
|
description: `Indicates whether fields in fields are referenced by keys rather than IDs.<br/>
|
||||||
|
This parameter is useful where fields have been added by a connect app and a field's key<br/>
|
||||||
|
may differ from its ID.`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: ' JQL',
|
||||||
|
name: 'jql',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
typeOptions: {
|
||||||
|
alwaysOpenEditWindow: true,
|
||||||
|
},
|
||||||
|
description: 'A JQL expression.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
/* issue:changelog */
|
/* issue:changelog */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
|
|
|
@ -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,9 +45,43 @@ export class JiraSoftwareCloud implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'jiraSoftwareCloudApi',
|
name: 'jiraSoftwareCloudApi',
|
||||||
required: true,
|
required: true,
|
||||||
}
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
jiraVersion: [
|
||||||
|
'cloud',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'jiraSoftwareServerApi',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
jiraVersion: [
|
||||||
|
'server',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
|
{
|
||||||
|
displayName: 'Jira Version',
|
||||||
|
name: 'jiraVersion',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Cloud',
|
||||||
|
value: 'cloud',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Server (Self Hosted)',
|
||||||
|
value: 'server',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'cloud',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Resource',
|
displayName: 'Resource',
|
||||||
name: 'resource',
|
name: 'resource',
|
||||||
|
@ -62,7 +96,7 @@ export class JiraSoftwareCloud implements INodeType {
|
||||||
default: 'issue',
|
default: 'issue',
|
||||||
description: 'Resource to consume.',
|
description: 'Resource to consume.',
|
||||||
},
|
},
|
||||||
...issueOpeations,
|
...issueOperations,
|
||||||
...issueFields,
|
...issueFields,
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
@ -73,16 +107,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 jiraCloudCredentials = this.getCredentials('jiraSoftwareCloudApi');
|
||||||
let projects;
|
let projects;
|
||||||
|
let endpoint = '/project/search';
|
||||||
|
if (jiraCloudCredentials === undefined) {
|
||||||
|
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,
|
||||||
|
@ -353,6 +394,29 @@ export class JiraSoftwareCloud implements INodeType {
|
||||||
throw new Error(`Jira Error: ${JSON.stringify(err)}`);
|
throw new Error(`Jira Error: ${JSON.stringify(err)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-search-post
|
||||||
|
if (operation === 'getAll') {
|
||||||
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||||
|
const body: IDataObject = {};
|
||||||
|
if (options.fields) {
|
||||||
|
body.fields = (options.fields as string).split(',') as string[];
|
||||||
|
}
|
||||||
|
if (options.jql) {
|
||||||
|
body.jql = options.jql as string;
|
||||||
|
}
|
||||||
|
if (options.expand) {
|
||||||
|
body.expand = options.expand as string;
|
||||||
|
}
|
||||||
|
if (returnAll) {
|
||||||
|
responseData = await jiraSoftwareCloudApiRequestAllItems.call(this, 'issues', `/search`, 'POST', body);
|
||||||
|
} else {
|
||||||
|
const limit = this.getNodeParameter('limit', i) as number;
|
||||||
|
body.maxResults = limit;
|
||||||
|
responseData = await jiraSoftwareCloudApiRequest.call(this, `/search`, 'POST', body);
|
||||||
|
responseData = responseData.issues;
|
||||||
|
}
|
||||||
|
}
|
||||||
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-changelog-get
|
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-changelog-get
|
||||||
if (operation === 'changelog') {
|
if (operation === 'changelog') {
|
||||||
const issueKey = this.getNodeParameter('issueKey', i) as string;
|
const issueKey = this.getNodeParameter('issueKey', i) as string;
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
"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",
|
||||||
|
|
Loading…
Reference in a new issue