Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
18 changes: 10 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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({
Expand All @@ -21,24 +22,24 @@ 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) {
core.setFailed(error.message);
}
})();

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(",");
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) {
Expand All @@ -54,7 +55,7 @@ async function createAndSetVersion(issueKeys, versionName, versionDescription, v
await jira.updateVersion({
id: versionId,
released: true,
projectId: projectId,
projectId: projectId,
releaseDate: date
});
}
Expand All @@ -65,6 +66,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
}
Expand Down