Skip to content

Commit d2c5f98

Browse files
Update Jira workflow to trigger on push events
1 parent b736c2c commit d2c5f98

File tree

1 file changed

+41
-20
lines changed

1 file changed

+41
-20
lines changed

.github/workflows/jira-callback.yml

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,64 @@
1-
name: Jira → In Review when Copilot’s 2nd commit lands
1+
name: Jira → In Review when Copilot pushes a real commit
22

33
on:
4-
pull_request:
5-
types: [synchronize]
4+
push:
65

76
permissions:
8-
contents: write
7+
contents: read
8+
# give write if you want to add labels/comments later
99
pull-requests: write
1010

1111
jobs:
1212
mark_in_review:
13-
# Adjust the author/label checks to your setup if needed
14-
if: github.event.pull_request.commits >= 2
1513
runs-on: ubuntu-latest
1614
steps:
17-
- name: Get Jira key from PR title
18-
id: key
19-
shell: bash
15+
- name: Find Copilot commit with content + Jira key
16+
id: find
2017
run: |
2118
set -euo pipefail
22-
title="${{ github.event.pull_request.title }}"
23-
24-
# Match ABC-123 style key in title only
25-
if [[ "$title" =~ ([A-Z][A-Z0-9]+-[0-9]+) ]]; then
26-
echo "key=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT"
27-
else
28-
echo "No Jira issue key found in PR title" >&2
29-
exit 1
19+
20+
found_key=""
21+
for row in $(jq -c '.commits[]' <<< '${{ toJson(github.event.commits) }}'); do
22+
committer=$(jq -r '.committer.name' <<< "$row")
23+
message=$(jq -r '.message' <<< "$row")
24+
added=$(jq -r '.added | length' <<< "$row")
25+
modified=$(jq -r '.modified | length' <<< "$row")
26+
removed=$(jq -r '.removed | length' <<< "$row")
27+
28+
# condition 1: committer must be Copilot (adjust string after testing in your repo)
29+
if [[ "$committer" != "github-copilot[bot]" ]]; then
30+
continue
31+
fi
32+
33+
# condition 2: commit must have content
34+
total_changes=$((added + modified + removed))
35+
if [[ "$total_changes" -eq 0 ]]; then
36+
continue
37+
fi
38+
39+
# condition 3: commit message must contain a Jira key like ABC-123
40+
if [[ "$message" =~ ([A-Z][A-Z0-9]+-[0-9]+) ]]; then
41+
found_key="${BASH_REMATCH[1]}"
42+
break
43+
fi
44+
done
45+
46+
if [[ -z "$found_key" ]]; then
47+
echo "No matching Copilot contentful commit with Jira key found."
48+
exit 0
3049
fi
3150
51+
echo "jira_key=$found_key" >> "$GITHUB_OUTPUT"
52+
3253
- name: Call Jira Automation webhook
54+
if: steps.find.outputs.jira_key != ''
3355
env:
3456
WEBHOOK_URL: ${{ secrets.JIRA_WEBHOOK_URL }}
3557
WEBHOOK_TOKEN: ${{ secrets.JIRA_WEBHOOK_TOKEN }}
36-
ISSUE_KEY: ${{ steps.key.outputs.key }}
58+
ISSUE_KEY: ${{ steps.find.outputs.jira_key }}
3759
run: |
3860
set -euo pipefail
39-
40-
# Single work item in the URL as ?issue=KEY (per Jira spec)
61+
echo "Marking $ISSUE_KEY In Review…"
4162
curl -sS -X POST \
4263
-H "Content-Type: application/json" \
4364
-H "X-Automation-Webhook-Token: ${WEBHOOK_TOKEN}" \

0 commit comments

Comments
 (0)