Skip to content

Commit

Permalink
Create Sync GitHub Issues with Jira and Manage Assignees
Browse files Browse the repository at this point in the history
  • Loading branch information
hooni0918 authored Jun 25, 2024
1 parent 30b9864 commit 7899f76
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Sync GitHub Issues with Jira and Manage Assignees

on:
issues:
types: [opened, assigned, unassigned]

jobs:
manage_issues_and_assignees:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Jira integration
env:
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
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 }}"
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')

# Create or update Jira issue
if [ ${{ github.event.action }} == 'opened' ]; then
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"},
"assignee": {"id": "'$JIRA_ASSIGNEE_ID'"}
}
}' "$JIRA_BASE_URL/rest/api/3/issue/")
echo "Jira API response: $RESPONSE"
fi

# Sync assignee
if [ ${{ github.event.action }} == 'assigned' ] || [ ${{ github.event.action }} == 'unassigned' ]; then
curl -s -u $JIRA_EMAIL:$JIRA_API_TOKEN -X PUT -H "Content-Type: application/json" \
--data '{"update": {"assignee": [{"set": {"id": "'$JIRA_ASSIGNEE_ID'"}}]}}' "$JIRA_BASE_URL/rest/api/3/issue/${{ env.JIRA_ISSUE_KEY }}"
fi

0 comments on commit 7899f76

Please sign in to comment.