From 51dc1b382082ec9272860d6a05323f39ff83669c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20R=C3=BCsch?= Date: Mon, 27 Nov 2023 23:23:41 +0100 Subject: [PATCH] Fix server provider for creating epics --- .../JiraServerProvider.ts | 116 ++++++++++-------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/electron/providers/jira-server-provider/JiraServerProvider.ts b/electron/providers/jira-server-provider/JiraServerProvider.ts index 94184477..6c5cb7c9 100644 --- a/electron/providers/jira-server-provider/JiraServerProvider.ts +++ b/electron/providers/jira-server-provider/JiraServerProvider.ts @@ -439,62 +439,70 @@ export class JiraServerProvider implements IProvider { const offsetDueDate = this.offsetDate(dueDate) return new Promise((resolve, reject) => { - this.getRestApiClient(2) - .post( - `/issue`, - { - fields: { - summary, - parent: { key: epic }, - issuetype: { id: type }, - project: { - id: projectId, - }, - reporter: { - name: reporter.name, - }, - ...(priority.id && { priority }), - ...(assignee && { - assignee: { - name: assignee.name, + this.getIssueTypesByProject(projectId) + .then((issueTypes) => { + const relevantIssueType = issueTypes.find((issueType) => issueType.id === type) + + this.getRestApiClient(2) + .post( + `/issue`, + { + fields: { + summary, + parent: { key: epic }, + issuetype: { id: type }, + project: { + id: projectId, + }, + reporter: { + name: reporter.name, + }, + ...(priority.id && { priority }), + ...(assignee && { + assignee: { + name: assignee.name, + }, + }), + description, + labels, + ...(offsetStartDate && { + [this.customFields.get("Start date")!]: offsetStartDate, + }), + ...(offsetDueDate && { + [this.customFields.get("Due date")!]: offsetDueDate, + }), + ...(sprint && + sprint.id && { + [this.customFields.get("Sprint")!]: +sprint.id, + }), + ...(storyPointsEstimate && { + [this.customFields.get("Story point estimate")!]: + storyPointsEstimate, + }), + ...(relevantIssueType && relevantIssueType.name === 'Epic' && { + [this.customFields.get("Epic Name")!]: summary + }), + // ...(files && { + // [this.customFields.get("Attachment")!]: files, + // }), }, - }), - description, - labels, - ...(offsetStartDate && { - [this.customFields.get("Start date")!]: offsetStartDate, - }), - ...(offsetDueDate && { - [this.customFields.get("Due date")!]: offsetDueDate, - }), - ...(sprint && - sprint.id && { - [this.customFields.get("Sprint")!]: +sprint.id, - }), - ...(storyPointsEstimate && { - [this.customFields.get("Story point estimate")!]: - storyPointsEstimate, - }), - // ...(files && { - // [this.customFields.get("Attachment")!]: files, - // }), - }, - } - ) - .then(async (response) => { - const createdIssue = response.data - resolve(JSON.stringify(createdIssue.key)) - await this.setTransition(createdIssue.id, status) - }) - .catch((error) => { - let specificError = error - if (error.response) { - if (error.response.status === 404) { - specificError = new Error("The user does not have the necessary permissions") - } - } + } + ) + .then(async (response) => { + const createdIssue = response.data + resolve(JSON.stringify(createdIssue.key)) + await this.setTransition(createdIssue.id, status) + }) + .catch((error) => { + let specificError = error + if (error.response) { + if (error.response.status === 404) { + specificError = new Error("The user does not have the necessary permissions") + } + } - reject(new Error(`Error creating issue: ${specificError}`)) + reject(new Error(`Error creating issue: ${specificError}`)) + }) }) }) }