-
Notifications
You must be signed in to change notification settings - Fork 2
46 lines (39 loc) · 1.57 KB
/
create-jira-issue.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
name: Sync GitHub Actions with Jira
on:
push:
branches:
- '*'
issues:
types: [opened]
jobs:
sync_with_jira:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Sync commits with Jira on Push
if: github.event_name == 'push'
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
JIRA_ISSUE_KEY=$(echo "$COMMIT_MESSAGE" | grep -oE 'JIRA-\d+')
COMMIT_ID=$(git rev-parse HEAD)
if [ -z "$JIRA_ISSUE_KEY" ]; then
echo "No JIRA issue key found in commit message."
exit 1
fi
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_MESSAGE\"}}]}}" \
-H "Content-Type: application/json" \
"${{ secrets.JIRA_BASEURL }}/rest/api/2/issue/$JIRA_ISSUE_KEY"
- name: Create Branch on Issue Opened
if: github.event_name == 'issues' && github.event.action == 'opened'
run: |
ISSUE_TITLE=${{ github.event.issue.title }}
BRANCH_NAME=$(echo "$ISSUE_TITLE" | sed 's/[^a-zA-Z0-9]/-/g' | tr '[:upper:]' '[:lower:]')
git checkout -b "$BRANCH_NAME"
git push origin "$BRANCH_NAME"
env:
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
JIRA_BASEURL: ${{ secrets.JIRA_BASEURL }}
JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }}