forked from CWorthy-ocean/C-Star
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
“Dafydd
committed
Nov 5, 2024
1 parent
2139d3a
commit 188c964
Showing
2 changed files
with
72 additions
and
0 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,72 @@ | ||
name: Close Jira Ticket on Issue Close | ||
|
||
on: | ||
issues: | ||
types: [closed] | ||
|
||
jobs: | ||
close-jira-ticket: | ||
runs-on: ubuntu-latest | ||
if: contains(github.event.issue.labels.*.name, 'jira-story') | ||
steps: | ||
- name: Extract Jira Story Key from Issue Comment | ||
id: extract_story_key | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
// Fetch all comments on the closed issue | ||
const { data: comments } = await github.rest.issues.listComments({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number | ||
}); | ||
// Find the comment containing the Jira link | ||
const jiraComment = comments.find(comment => comment.body.includes('This issue has been linked to Jira story')); | ||
if (!jiraComment) { | ||
core.setFailed("No Jira comment found with story key."); | ||
return; | ||
} | ||
// Extract the Jira story key from the comment | ||
const match = jiraComment.body.match(/\[(.*?)\]\(https:\/\/cworthy\.atlassian\.net\/browse\/.*?\)/); | ||
if (!match || match.length < 2) { | ||
core.setFailed("Jira story key not found in the comment."); | ||
return; | ||
} | ||
const storyKey = match[1]; | ||
// Print the extracted story key | ||
console.log("Extracted STORY_KEY:", storyKey); | ||
core.setOutput("story_key", storyKey); | ||
- name: Verify Issue Exists and Accessible in Jira | ||
env: | ||
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN_DAFYDD }} | ||
JIRA_EMAIL: ${{ secrets.JIRA_EMAIL_DAFYDD }} | ||
STORY_KEY: ${{ steps.extract_story_key.outputs.story_key }} | ||
run: | | ||
story_key="${{ steps.extract_story_key.outputs.story_key }}" | ||
jira_domain="https://cworthy.atlassian.net" | ||
# Attempt to retrieve issue details and print the response directly | ||
curl -s -X GET \ | ||
-H "Authorization: Basic $(echo -n $JIRA_EMAIL:$JIRA_API_TOKEN | base64)" \ | ||
-H "Content-Type: application/json" \ | ||
"$jira_domain/rest/api/3/issue/$story_key" | ||
- name: Close Jira Ticket | ||
env: | ||
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN_DAFYDD }} | ||
JIRA_EMAIL: ${{ secrets.JIRA_EMAIL_DAFYDD }} | ||
STORY_KEY: ${{ steps.extract_story_key.outputs.story_key }} | ||
run: | | ||
story_key="${{ steps.extract_story_key.outputs.story_key }}" | ||
jira_domain="https://cworthy.atlassian.net" | ||
curl -X POST --http1.1 -v\ | ||
-H "Authorization: Basic $(echo -n $JIRA_EMAIL:$JIRA_API_TOKEN | base64)" \ | ||
-H "Content-Type: application/json" \ | ||
--data '{"transition": {"id": "31"}}' \ | ||
"$jira_domain/rest/api/3/issue/$story_key/transitions" |
File renamed without changes.