From d76c9e46ad00001bdfebe8731a728186cb716a71 Mon Sep 17 00:00:00 2001 From: Florian Krauthan Date: Wed, 11 Sep 2024 20:40:26 -0700 Subject: [PATCH 1/2] Fixes !7 - Added a system to specify the project key --- README.md | 1 + action.yml | 3 +++ index.js | 12 ++++++------ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d4ca53f..af80053 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ The action will set the "fix version" in Jira to the given version (and creates - `versionDescription`: The description of the Version (default: "CD version") - `versionArchived`: Mark the new version as archived (default: `false`) - `versionReleased`: Mark the new version as released (default: `false`) +- `projectKey`: The project the new version should be created in (default: project key of the first issue key) ## Outputs None diff --git a/action.yml b/action.yml index 49c16f2..2c23298 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,9 @@ inputs: versionReleased: description: 'Mark the new version as released (default: false)' required: false + projectKey: + description: 'The project the new version should be created in (default: project key of the first issue key)' + required: false runs: using: 'node20' main: 'index.js' diff --git a/index.js b/index.js index 9862f08..9abfac5 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ const core = require("@actions/core"); const JiraApi = require("jira-client") -let jira, domain, username, password, versionName, versionDescription, versionArchived, issueKeys, versionReleased; +let jira, domain, username, password, versionName, versionDescription, versionArchived, issueKeys, versionReleased, projectKey; (async () => { try { domain = core.getInput("domain"); @@ -12,6 +12,7 @@ let jira, domain, username, password, versionName, versionDescription, versionAr versionDescription = core.getInput("versionDescription") || "CD Version"; versionArchived = core.getInput("versionArchived") === "true" || core.getInput("versionArchived") === true; versionReleased = core.getInput("versionReleased") === "true" || core.getInput("versionReleased") === true; + projectKey = core.getInput("projectKey") || getProjectKey(issueKeys); // Initialize jira = new JiraApi({ @@ -21,7 +22,7 @@ let jira, domain, username, password, versionName, versionDescription, versionAr password: password, }); //core.setFailed(`version is not correct: [${version}] must be "1.0.0"/"v1.0.0"/"test 1.0.0" pattern`); - createAndSetVersion(issueKeys, versionName, versionDescription, versionArchived, versionReleased) + await createAndSetVersion(projectKey, issueKeys, versionName, versionDescription, versionArchived, versionReleased) // core.setOutput("new-version", nextVersion); } catch (error) { @@ -29,9 +30,7 @@ let jira, domain, username, password, versionName, versionDescription, versionAr } })(); -async function createAndSetVersion(issueKeys, versionName, versionDescription, versionArchived, versionReleased) { - // from e.g. TEST-1 get the project key --> TEST - const projectKey = getProjectKey(issueKeys); +async function createAndSetVersion(projectKey, issueKeys, versionName, versionDescription, versionArchived, versionReleased) { const projectId = await getProjectId(projectKey); const versionId = await createVersion(projectId, versionName, versionDescription); const issueKeyArr = issueKeys.split(","); @@ -54,7 +53,7 @@ async function createAndSetVersion(issueKeys, versionName, versionDescription, v await jira.updateVersion({ id: versionId, released: true, - projectId: projectId, + projectId: projectId, releaseDate: date }); } @@ -65,6 +64,7 @@ function getProjectKey(issueKey) { } async function getProjectId(projectKey) { + // from e.g. TEST-1 get the project key --> TEST const project = await jira.getProject(projectKey); return project.id } From 54457773737514d29e06554da9872a7d2aeb3881 Mon Sep 17 00:00:00 2001 From: Florian Krauthan Date: Thu, 12 Sep 2024 16:21:03 -0700 Subject: [PATCH 2/2] Ignore empty issue keys --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9abfac5..a60af5b 100644 --- a/index.js +++ b/index.js @@ -36,8 +36,10 @@ async function createAndSetVersion(projectKey, issueKeys, versionName, versionDe const issueKeyArr = issueKeys.split(","); for (let i = 0; i < issueKeyArr.length; i++) { const issueKey = issueKeyArr[i]; - const issueId = await getIssueId(issueKey); - await setVersion(issueId, versionId); + if (issueKey) { + const issueId = await getIssueId(issueKey); + await setVersion(issueId, versionId); + } } // archive version (passing it as argument while creating version doesn't work if (versionArchived) {