Update create-jira-issue.yml #76
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
name: Sync GitHub Actions with Jira | |
on: | |
push: | |
branches: | |
- '*' | |
jobs: | |
sync_with_jira: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup environment | |
run: | | |
function extract_issue_key_from_commit_message { | |
echo "$1" | grep -oE 'JIRA-\d+' | |
} | |
- name: Sync commits with Jira | |
run: | | |
JIRA_ISSUE_KEY=$(extract_issue_key_from_commit_message "${{ github.event.head_commit.message }}") | |
if [ -z "$JIRA_ISSUE_KEY" ]; then | |
echo "No JIRA issue key found in commit message." | |
exit 1 | |
fi | |
COMMIT_ID="${{ github.event.head_commit.id }}" | |
COMMIT_MSG="${{ github.event.head_commit.message }}" | |
curl -u "${{ secrets.JIRA_EMAIL }}:${{ secrets.JIRA_API_TOKEN }}" \ | |
-X POST \ | |
--data "{\"update\": {\"comment\": [{\"add\": {\"body\": \"Commit '$COMMIT_ID' was added to this issue: $COMMIT_MSG\"}}]}}" \ | |
-H "Content-Type: application/json" \ | |
"${{ secrets.JIRA_BASEURL }}/rest/api/2/issue/$JIRA_ISSUE_KEY" | |
env: | |
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | |
JIRA_BASEURL: ${{ secrets.JIRA_BASEURL }} | |
JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }} |