features: support jira self-hosted server

This commit is contained in:
zou wendi
2020-05-05 12:07:19 +08:00
parent 2bed4a6246
commit e4cc3a4bc9
7 changed files with 117 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
import {
import {
OptionsWithUri,
} from 'request';
@@ -9,13 +9,19 @@ import {
ILoadOptionsFunctions,
} from 'n8n-core';
import {
import {
IDataObject,
ICredentialDataDecryptedObject,
} 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
let data; let domain;
const jiraCloudCredentials = this.getCredentials('jiraSoftwareCloudApi');
let jiraCloudCredentials: ICredentialDataDecryptedObject | undefined;
try {
jiraCloudCredentials = this.getCredentials('jiraSoftwareCloudApi');
} catch (error) {
}
const jiraServerCredentials = this.getCredentials('jiraSoftwareServerApi');
if (jiraCloudCredentials === undefined && jiraServerCredentials === undefined) {
throw new Error('No credentials got returned!');

View File

@@ -174,6 +174,31 @@ export const issueFields = [
default: [],
required : false,
description: 'Labels',
displayOptions: {
show: {
'/jiraVersion': [
'cloud',
],
},
},
},
{
displayName: 'Labels',
name: 'serverLabels',
type: 'string',
default: [],
required : false,
description: 'Labels',
displayOptions: {
show: {
'/jiraVersion': [
'server',
],
},
},
typeOptions: {
multipleValues: true,
},
},
{
displayName: 'Parent Issue Key',
@@ -284,6 +309,31 @@ export const issueFields = [
default: [],
required : false,
description: 'Labels',
displayOptions: {
show: {
'/jiraVersion': [
'cloud',
],
},
},
},
{
displayName: 'Labels',
name: 'serverLabels',
type: 'string',
default: [],
required : false,
description: 'Labels',
displayOptions: {
show: {
'/jiraVersion': [
'server',
],
},
},
typeOptions: {
multipleValues: true,
},
},
{
displayName: 'Parent Issue Key',

View File

@@ -140,18 +140,31 @@ export class JiraSoftwareCloud implements INodeType {
const returnData: INodePropertyOptions[] = [];
const issueTypes = await jiraSoftwareCloudApiRequest.call(this, '/issuetype', 'GET');
for (const issueType of issueTypes) {
if (issueType.scope.project.id === projectId) {
const jiraVersion = this.getCurrentNodeParameter('jiraVersion') as string;
if (jiraVersion === "server") {
for (const issueType of issueTypes) {
const issueTypeName = issueType.name;
const issueTypeId = issueType.id;
returnData.push({
name: issueTypeName,
value: issueTypeId,
});
}
} else {
for (const issueType of issueTypes) {
if (issueType.scope.project.id === projectId) {
const issueTypeName = issueType.name;
const issueTypeId = issueType.id;
returnData.push({
name: issueTypeName,
value: issueTypeId,
});
}
}
}
return returnData;
},
@@ -197,18 +210,37 @@ export class JiraSoftwareCloud implements INodeType {
// select them easily
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const jiraVersion = this.getCurrentNodeParameter("jiraVersion") as string;
if (jiraVersion === "server") {
// the interface call must bring username
const users = await jiraSoftwareCloudApiRequest.call(this, "/user/search", "GET", {},
{
username: "'",
}
);
for (const user of users) {
const userName = user.displayName;
const userId = user.name;
returnData.push({
name: userName,
value: userId,
});
}
} else {
const users = await jiraSoftwareCloudApiRequest.call(this, '/users/search', 'GET');
const users = await jiraSoftwareCloudApiRequest.call(this, '/users/search', 'GET');
for (const user of users) {
const userName = user.displayName;
const userId = user.accountId;
for (const user of users) {
const userName = user.displayName;
const userId = user.accountId;
returnData.push({
name: userName,
value: userId,
});
returnData.push({
name: userName,
value: userId,
});
}
}
return returnData;
},
@@ -283,6 +315,9 @@ export class JiraSoftwareCloud implements INodeType {
if (additionalFields.labels) {
fields.labels = additionalFields.labels as string[];
}
if (additionalFields.serverLabels) {
fields.labels = additionalFields.serverLabels as string[];
}
if (additionalFields.priority) {
fields.priority = {
id: additionalFields.priority as string,
@@ -342,6 +377,9 @@ export class JiraSoftwareCloud implements INodeType {
if (updateFields.labels) {
fields.labels = updateFields.labels as string[];
}
if (updateFields.serverLabels) {
fields.labels = updateFields.serverLabels as string[];
}
if (updateFields.priority) {
fields.priority = {
id: updateFields.priority as string,