Skip to content

Commit

Permalink
add workflow to close jira tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
“Dafydd committed Nov 5, 2024
1 parent 2139d3a commit 188c964
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/close_jira_ticket.yaml
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.

0 comments on commit 188c964

Please sign in to comment.