-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add CI changeset step to update jira issue with fixVersion (#13214)
* add ci changeset step to update jira issue with fixVersion and labels based on tags * fix with for env * change core for testing * add changeset * add pnpm install and update working directory * fix * fix * fix env * remove test from core * update trigger condition * remove tags for now * rename * refactor * add test to core * reorder step * update changeset content * update log text * add private:true to package.json
- Loading branch information
1 parent
c14576a
commit 921a015
Showing
6 changed files
with
259 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"chainlink": patch | ||
--- | ||
|
||
Add to CI changeset workflow an additional step to update the Jira issue associated with this PR and set the `fixVersions` for the issue with the upcoming core release version. #internal #wip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "jira", | ||
"version": "0.1.0", | ||
"description": "Updates Jira issue with release information like the version and tags for a PR.", | ||
"main": "update-jira-issue.js", | ||
"type": "module", | ||
"private": true, | ||
"keywords": [], | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@actions/core": "^1.10.1", | ||
"node-fetch": "^2.7.0" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/usr/bin/env node | ||
|
||
import * as core from "@actions/core"; | ||
import fetch from "node-fetch"; | ||
|
||
function parseIssueNumber(prTitle, commitMessage, branchName) { | ||
const jiraIssueRegex = /[A-Z]{2,}-\d+/; | ||
if (!!branchName && jiraIssueRegex.test(branchName.toUpperCase())) { | ||
return branchName.toUpperCase().match(jiraIssueRegex)[0]; | ||
} else if ( | ||
!!commitMessage && | ||
jiraIssueRegex.test(commitMessage.toUpperCase()) | ||
) { | ||
return commitMessage.toUpperCase().match(jiraIssueRegex)[0]; | ||
} else if (!!prTitle && jiraIssueRegex.test(prTitle.toUpperCase())) { | ||
return prTitle.toUpperCase().match(jiraIssueRegex)[0]; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
function getLabels(tags) { | ||
const labelPrefix = "core-release"; | ||
return tags.map((tag) => { | ||
return { | ||
add: `${labelPrefix}/${tag.substring(1)}`, | ||
}; | ||
}); | ||
} | ||
|
||
async function updateJiraIssue( | ||
jiraHost, | ||
jiraUserName, | ||
jiraApiToken, | ||
issueNumber, | ||
tags, | ||
fixVersionName | ||
) { | ||
const token = Buffer.from(`${jiraUserName}:${jiraApiToken}`).toString( | ||
"base64" | ||
); | ||
const bodyData = { | ||
update: { | ||
labels: getLabels(tags), | ||
fixVersions: [{ set: [{ name: fixVersionName }] }], | ||
}, | ||
}; | ||
|
||
fetch(`https://${jiraHost}/rest/api/3/issue/${issueNumber}`, { | ||
method: "PUT", | ||
headers: { | ||
Authorization: `Basic ${token}`, | ||
Accept: "application/json", | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(bodyData), | ||
}) | ||
.then((response) => { | ||
console.log(`Response: ${JSON.stringify(response)}`); | ||
return response.text(); | ||
}) | ||
.then((text) => console.log(text)) | ||
.catch((err) => console.error(err)); | ||
} | ||
|
||
async function run() { | ||
try { | ||
const jiraHost = process.env.JIRA_HOST; | ||
const jiraUserName = process.env.JIRA_USERNAME; | ||
const jiraApiToken = process.env.JIRA_API_TOKEN; | ||
const chainlinkVersion = process.env.CHAINLINK_VERSION; | ||
const prTitle = process.env.PR_TITLE; | ||
const commitMessage = process.env.COMMIT_MESSAGE; | ||
const branchName = process.env.BRANCH_NAME; | ||
// tags are not getting used at the current moment so will always default to [] | ||
const tags = process.env.FOUND_TAGS | ||
? process.env.FOUND_TAGS.split(",") | ||
: []; | ||
|
||
// Check for the existence of JIRA_HOST and JIRA_USERNAME and JIRA_API_TOKEN | ||
if (!jiraHost || !jiraUserName || !jiraApiToken) { | ||
core.setFailed( | ||
"Error: Missing required environment variables: JIRA_HOST and JIRA_USERNAME and JIRA_API_TOKEN." | ||
); | ||
return; | ||
} | ||
|
||
// Checks for the Jira issue number and exit if it can't find it | ||
const issueNumber = parseIssueNumber(prTitle, commitMessage, branchName); | ||
if (!issueNumber) { | ||
core.info( | ||
"No JIRA issue number found in: PR title, commit message, or branch name. Please include the issue ID in one of these." | ||
); | ||
core.notice( | ||
"No JIRA issue number found in: PR title, commit message, or branch name. Please include the issue ID in one of these." | ||
); | ||
return; | ||
} | ||
const fixVersionName = `chainlink-v${chainlinkVersion}`; | ||
await updateJiraIssue( | ||
jiraHost, | ||
jiraUserName, | ||
jiraApiToken, | ||
issueNumber, | ||
tags, | ||
fixVersionName | ||
); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters