|
1 | | -name: Jira → In Review when Copilot’s 2nd commit lands |
| 1 | +name: Jira → In Review when Copilot pushes a real commit |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request: |
5 | | - types: [synchronize] |
| 4 | + push: |
6 | 5 |
|
7 | 6 | permissions: |
8 | | - contents: write |
| 7 | + contents: read |
| 8 | + # give write if you want to add labels/comments later |
9 | 9 | pull-requests: write |
10 | 10 |
|
11 | 11 | jobs: |
12 | 12 | mark_in_review: |
13 | | - # Adjust the author/label checks to your setup if needed |
14 | | - if: github.event.pull_request.commits >= 2 |
15 | 13 | runs-on: ubuntu-latest |
16 | 14 | 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 |
20 | 17 | run: | |
21 | 18 | 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 |
30 | 49 | fi |
31 | 50 |
|
| 51 | + echo "jira_key=$found_key" >> "$GITHUB_OUTPUT" |
| 52 | +
|
32 | 53 | - name: Call Jira Automation webhook |
| 54 | + if: steps.find.outputs.jira_key != '' |
33 | 55 | env: |
34 | 56 | WEBHOOK_URL: ${{ secrets.JIRA_WEBHOOK_URL }} |
35 | 57 | WEBHOOK_TOKEN: ${{ secrets.JIRA_WEBHOOK_TOKEN }} |
36 | | - ISSUE_KEY: ${{ steps.key.outputs.key }} |
| 58 | + ISSUE_KEY: ${{ steps.find.outputs.jira_key }} |
37 | 59 | run: | |
38 | 60 | set -euo pipefail |
39 | | -
|
40 | | - # Single work item in the URL as ?issue=KEY (per Jira spec) |
| 61 | + echo "Marking $ISSUE_KEY In Review…" |
41 | 62 | curl -sS -X POST \ |
42 | 63 | -H "Content-Type: application/json" \ |
43 | 64 | -H "X-Automation-Webhook-Token: ${WEBHOOK_TOKEN}" \ |
|
0 commit comments