fixes done

This commit is contained in:
Ricardo Espinoza 2019-12-01 16:47:53 -05:00
parent 1dc80e3bdd
commit 8ca31db0aa
4 changed files with 250 additions and 320 deletions

View file

@ -117,24 +117,6 @@ export const issueFields = [
default: '',
description: 'Summary',
},
{
displayName: 'Parent Issue Key',
name: 'parentIssueKey',
type: 'string',
required: false,
displayOptions: {
show: {
resource: [
'issue',
],
operation: [
'create',
],
},
},
default: '',
description: 'Parent Issue Key',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
@ -152,6 +134,14 @@ export const issueFields = [
},
},
options: [
{
displayName: 'Parent Issue Key',
name: 'parentIssueKey',
type: 'string',
required: false,
default: '',
description: 'Parent Issue Key',
},
{
displayName: 'Labels',
name: 'labels',
@ -226,65 +216,8 @@ export const issueFields = [
description: 'Issue Key',
},
{
displayName: 'Issue Type',
name: 'issueType',
type: 'options',
required: false,
displayOptions: {
show: {
resource: [
'issue',
],
operation: [
'update'
]
},
},
typeOptions: {
loadOptionsMethod: 'getIssueTypes',
},
default: '',
description: 'Issue Types',
},
{
displayName: 'Summary',
name: 'summary',
type: 'string',
required: false,
displayOptions: {
show: {
resource: [
'issue',
],
operation: [
'update',
],
},
},
default: '',
description: 'Summary',
},
{
displayName: 'Parent Issue Key',
name: 'parentIssueKey',
type: 'string',
required: false,
displayOptions: {
show: {
resource: [
'issue',
],
operation: [
'update',
],
},
},
default: '',
description: 'Parent Issue Key',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
@ -299,6 +232,33 @@ export const issueFields = [
},
},
options: [
{
displayName: 'Issue Type',
name: 'issueType',
type: 'options',
required: false,
typeOptions: {
loadOptionsMethod: 'getIssueTypes',
},
default: '',
description: 'Issue Types',
},
{
displayName: 'Summary',
name: 'summary',
type: 'string',
required: false,
default: '',
description: 'Summary',
},
{
displayName: 'Parent Issue Key',
name: 'parentIssueKey',
type: 'string',
required: false,
default: '',
description: 'Parent Issue Key',
},
{
displayName: 'Labels',
name: 'labels',
@ -405,10 +365,11 @@ export const issueFields = [
description: 'Issue Key',
},
{
displayName: 'Fields',
name: 'fields',
type: 'string',
required: false,
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: [
@ -419,8 +380,15 @@ export const issueFields = [
],
},
},
options: [
{
displayName: 'Fields',
name: 'fields',
type: 'string',
required: false,
default: '',
description: `A list of fields to return for the issue. This parameter accepts a comma-separated list. Use it to retrieve a subset of fields. Allowed values:
description: `A list of fields to return for the issue. This parameter accepts a comma-separated list.
Use it to retrieve a subset of fields. Allowed values:
*all Returns all fields.
*navigable Returns navigable fields.
Any issue field, prefixed with a minus to exclude.`
@ -430,36 +398,19 @@ export const issueFields = [
name: 'fieldsByKey',
type: 'boolean',
required: false,
displayOptions: {
show: {
resource: [
'issue',
],
operation: [
'get',
],
},
},
default: false,
description: `Indicates whether fields in fields are referenced by keys rather than IDs. This parameter is useful where fields have been added by a connect app and a field's key may differ from its ID.`,
description: `Indicates whether fields in fields are referenced by keys rather than IDs.
This parameter is useful where fields have been added by a connect app and a field's key
may differ from its ID.`,
},
{
displayName: 'Expand',
name: 'expand',
type: 'string',
required: false,
displayOptions: {
show: {
resource: [
'issue',
],
operation: [
'get',
],
},
},
default: '',
description: `Use expand to include additional information about the issues in the response. This parameter accepts a comma-separated list. Expand options include:
description: `Use expand to include additional information about the issues in the response.
This parameter accepts a comma-separated list. Expand options include:
renderedFields Returns field values rendered in HTML format.
names Returns the display name of each field.
schema Returns the schema describing a field type.
@ -473,18 +424,9 @@ export const issueFields = [
name: 'properties',
type: 'string',
required: false,
displayOptions: {
show: {
resource: [
'issue',
],
operation: [
'get',
],
},
},
default: '',
description: `A list of issue properties to return for the issue. This parameter accepts a comma-separated list. Allowed values:
description: `A list of issue properties to return for the issue.
This parameter accepts a comma-separated list. Allowed values:
*all Returns all issue properties.
Any issue property key, prefixed with a minus to exclude.
Examples:
@ -498,18 +440,12 @@ export const issueFields = [
name: 'updateHistory',
type: 'boolean',
required: false,
displayOptions: {
show: {
resource: [
'issue',
],
operation: [
'get',
],
},
},
default: false,
description: `Whether the project in which the issue is created is added to the user's Recently viewed project list, as shown under Projects in Jira. This also populates the JQL issues search lastViewed field.`,
description: `Whether the project in which the issue is created is added to the user's
Recently viewed project list, as shown under Projects in Jira. This also populates the
JQL issues search lastViewed field.`,
},
]
},
/* -------------------------------------------------------------------------- */
@ -574,7 +510,6 @@ export const issueFields = [
default: 50,
description: 'How many results to return.',
},
/* -------------------------------------------------------------------------- */
/* issue:notify */
/* -------------------------------------------------------------------------- */
@ -596,66 +531,6 @@ export const issueFields = [
default: '',
description: 'Issue Key',
},
{
displayName: 'Subject',
name: 'subject',
type: 'string',
required: false,
displayOptions: {
show: {
resource: [
'issue',
],
operation: [
'notify',
],
},
},
default: '',
description: 'The subject of the email notification for the issue. If this is not specified, then the subject is set to the issue key and summary.',
},
{
displayName: 'Text Body',
name: 'textBody',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
required: false,
displayOptions: {
show: {
resource: [
'issue',
],
operation: [
'notify',
],
},
},
default: '',
description: 'The subject of the email notification for the issue. If this is not specified, then the subject is set to the issue key and summary.',
},
{
displayName: 'HTML Body',
name: 'htmlBody',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
required: false,
displayOptions: {
show: {
resource: [
'issue',
],
operation: [
'notify',
],
},
},
default: '',
description: 'The HTML body of the email notification for the issue.',
},
{
displayName: 'JSON Parameters',
name: 'jsonParameters',
@ -673,6 +548,57 @@ export const issueFields = [
},
},
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: [
'issue',
],
operation: [
'notify',
],
},
},
options: [
{
displayName: 'Subject',
name: 'subject',
type: 'string',
required: false,
default: '',
description: `The subject of the email notification for the issue. If this is not specified,
then the subject is set to the issue key and summary.`
},
{
displayName: 'Text Body',
name: 'textBody',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
required: false,
default: '',
description: `The subject of the email notification for the issue.
If this is not specified, then the subject is set to the issue key and summary.`
},
{
displayName: 'HTML Body',
name: 'htmlBody',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
required: false,
default: '',
description: 'The HTML body of the email notification for the issue.',
},
],
},
{
displayName: 'Notification Recipients',
name: 'notificationRecipientsUi',
@ -878,10 +804,11 @@ export const issueFields = [
description: 'Issue Key',
},
{
displayName: 'Expand',
name: 'expand',
type: 'string',
required: false,
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: [
@ -892,24 +819,23 @@ export const issueFields = [
],
},
},
options: [
{
displayName: 'Expand',
name: 'expand',
type: 'string',
required: false,
default: '',
description: 'Use expand to include additional information about transitions in the response. This parameter accepts transitions.fields, which returns information about the fields in the transition screen for each transition. Fields hidden from the screen are not returned. Use this information to populate the fields and update fields in Transition issue.',
description: `Use expand to include additional information about transitions in the response.
This parameter accepts transitions.fields, which returns information about the fields in the
transition screen for each transition. Fields hidden from the screen are not returned. Use this
information to populate the fields and update fields in Transition issue.`
},
{
displayName: 'Transition ID',
name: 'transitionId',
type: 'string',
required: false,
displayOptions: {
show: {
resource: [
'issue',
],
operation: [
'transitions',
],
},
},
default: '',
description: 'The ID of the transition.',
},
@ -918,17 +844,9 @@ export const issueFields = [
name: 'skipRemoteOnlyCondition',
type: 'boolean',
required: false,
displayOptions: {
show: {
resource: [
'issue',
],
operation: [
'transitions',
],
},
},
default: false,
description: 'Indicates whether transitions with the condition Hide From User Condition are included in the response.',
},
],
},
] as INodeProperties[];

View file

@ -1,7 +1,7 @@
import { IDataObject } from "n8n-workflow";
export interface IFields {
summary: string;
summary?: string;
project?: IDataObject;
issuetype?: IDataObject;
labels?: string[];

View file

@ -219,7 +219,6 @@ export class JiraSoftwareCloud implements INodeType {
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 parentIssueKey = this.getNodeParameter('parentIssueKey', i) as string;
const body: IIssue = {};
const fields: IFields = {
summary,
@ -256,12 +255,14 @@ export class JiraSoftwareCloud implements INodeType {
subtaskIssues.push(issueType.id);
}
}
if (!parentIssueKey && subtaskIssues.includes(issueTypeId)) {
if (!additionalFields.parentIssueKey
&& subtaskIssues.includes(issueTypeId)) {
throw new Error('You must define a Parent Issue Key when Issue type is sub-task');
} else if (parentIssueKey && subtaskIssues.includes(issueTypeId)) {
} else if (additionalFields.parentIssueKey
&& subtaskIssues.includes(issueTypeId)) {
fields.parent = {
key: parentIssueKey.toUpperCase(),
key: (additionalFields.parentIssueKey as string).toUpperCase(),
};
}
body.fields = fields;
@ -273,33 +274,33 @@ export class JiraSoftwareCloud implements INodeType {
}
//https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issue-issueIdOrKey-put
if (operation === 'update') {
const summary = this.getNodeParameter('summary', i) as string;
const issueTypeId = this.getNodeParameter('issueType', i) as string;
const issueKey = this.getNodeParameter('issueKey', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const parentIssueKey = this.getNodeParameter('parentIssueKey', i) as string;
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
const body: IIssue = {};
const fields: IFields = {
summary,
issuetype: {
id: issueTypeId
const fields: IFields = {};
if (updateFields.summary) {
fields.summary = updateFields.summary as string;
}
if (updateFields.issueType) {
fields.issuetype = {
id: updateFields.issueType as string,
};
if (additionalFields.labels) {
fields.labels = additionalFields.labels as string[];
}
if (additionalFields.priority) {
if (updateFields.labels) {
fields.labels = updateFields.labels as string[];
}
if (updateFields.priority) {
fields.priority = {
id: additionalFields.priority as string,
id: updateFields.priority as string,
};
}
if (additionalFields.assignee) {
if (updateFields.assignee) {
fields.assignee = {
id: additionalFields.assignee as string,
id: updateFields.assignee as string,
};
}
if (additionalFields.description) {
fields.description = additionalFields.description as string;
if (updateFields.description) {
fields.description = updateFields.description as string;
}
const issueTypes = await jiraSoftwareCloudApiRequest.call(this, '/issuetype', 'GET', body);
const subtaskIssues = [];
@ -308,12 +309,14 @@ export class JiraSoftwareCloud implements INodeType {
subtaskIssues.push(issueType.id);
}
}
if (!parentIssueKey && subtaskIssues.includes(issueTypeId)) {
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 (parentIssueKey && subtaskIssues.includes(issueTypeId)) {
} else if (updateFields.parentIssueKey
&& subtaskIssues.includes(updateFields.issueType)) {
fields.parent = {
key: parentIssueKey.toUpperCase(),
key: (updateFields.parentIssueKey as string).toUpperCase(),
};
}
body.fields = fields;
@ -326,16 +329,22 @@ export class JiraSoftwareCloud implements INodeType {
//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 fields = this.getNodeParameter('fields', i) as string;
const fieldsByKey = this.getNodeParameter('fieldsByKey', i) as boolean;
const expand = this.getNodeParameter('expand', i) as string;
const properties = this.getNodeParameter('properties', i) as string;
const updateHistory = this.getNodeParameter('updateHistory', i) as boolean;
qs.fields = fields;
qs.fieldsByKey = fieldsByKey;
qs.expand = expand;
qs.properties = properties;
qs.updateHistory = updateHistory;
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 jiraSoftwareCloudApiRequest.call(this, `/issue/${issueKey}`, 'GET', {}, qs);
} catch (err) {
@ -361,12 +370,15 @@ export class JiraSoftwareCloud implements INodeType {
//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 textBody = this.getNodeParameter('textBody', i) as string;
const htmlBody = this.getNodeParameter('htmlBody', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const jsonActive = this.getNodeParameter('jsonParameters', 0) as boolean;
const body: INotify = {};
body.htmlBody = htmlBody;
body.textBody = textBody;
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 = {};
@ -441,19 +453,19 @@ export class JiraSoftwareCloud implements INodeType {
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
//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 transitionId = this.getNodeParameter('transitionId', i) as string;
const expand = this.getNodeParameter('expand', i) as string;
if (transitionId) {
qs.transitionId = transitionId;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (additionalFields.transitionId) {
qs.transitionId = additionalFields.transitionId as string;
}
if (expand) {
qs.expand = expand;
if (additionalFields.expand) {
qs.expand = additionalFields.expand as string;
}
if (additionalFields.skipRemoteOnlyCondition) {
qs.skipRemoteOnlyCondition = additionalFields.skipRemoteOnlyCondition as boolean;
}
qs.skipRemoteOnlyCondition = this.getNodeParameter('skipRemoteOnlyCondition', i) as boolean;
try {
responseData = await jiraSoftwareCloudApiRequest.call(this, `/issue/${issueKey}/transitions`, 'GET', {}, qs);
responseData = responseData.transitions;