Sync GitHub Issues with Jira #1
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 Issues with Jira | |
on: | |
issues: | |
types: [opened, assigned, unassigned] | |
jobs: | |
sync_with_jira: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Sync issue with Jira | |
env: | |
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | |
JIRA_BASE_URL: ${{ secrets.JIRA_BASEURL }} | |
JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }} | |
JIRA_PROJECT_KEY: ${{ secrets.JIRA_PROJECT_KEY }} | |
run: | | |
ISSUE_TITLE="${{ github.event.issue.title }}" | |
ISSUE_BODY="${{ github.event.issue.body }}" | |
echo "Creating or updating Jira issue with title: $ISSUE_TITLE and body: $ISSUE_BODY" | |
RESPONSE=$(curl -s -u $JIRA_EMAIL:$JIRA_API_TOKEN -X POST \ | |
-H "Content-Type: application/json" \ | |
--data '{ | |
"fields": { | |
"project": { | |
"key": "$JIRA_PROJECT_KEY" | |
}, | |
"summary": "$ISSUE_TITLE", | |
"description": "$ISSUE_BODY", | |
"issuetype": { | |
"name": "Task" | |
} | |
} | |
}' "$JIRA_BASE_URL/rest/api/2/issue/") | |
echo "Jira API response: $RESPONSE" | |
- name: Update Jira issue with assignee | |
if: github.event.action == 'assigned' || github.event.action == 'unassigned' | |
run: | | |
ISSUE_ASSIGNEE="${{ github.event.issue.assignee.login }}" | |
JIRA_ASSIGNEE_ID=$(curl -s -u $JIRA_EMAIL:$JIRA_API_TOKEN "$JIRA_BASE_URL/rest/api/3/user/search?query=$ISSUE_ASSIGNEE" | jq -r '.[0].accountId') | |
curl -s -u $JIRA_EMAIL:$JIRA_API_TOKEN -X PUT \ | |
-H "Content-Type: application/json" \ | |
--data '{ | |
"update": { | |
"assignee": [ | |
{ | |
"set": { | |
"accountId": "$JIRA_ASSIGNEE_ID" | |
} | |
} | |
] | |
} | |
}' "$JIRA_BASE_URL/rest/api/2/issue/${{ env.JIRA_ISSUE_KEY }}" |