-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (117 loc) · 5.02 KB
/
Copy pathqgs-ai-summary.yml
File metadata and controls
129 lines (117 loc) · 5.02 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: qgs-ai-summary
# Post a concise, human-readable summary of the real changes to QGIS .qgs
# project files on a PR. scripts/qgs-diff.py builds a churn-free diff of the
# changed files; the GitHub Copilot CLI turns it into per-file bullet points;
# the result is posted as a single self-updating PR comment. Nothing derived
# is committed.
on:
pull_request:
paths:
- '**/*.qgs'
permissions:
contents: read
pull-requests: write
copilot-requests: write
concurrency:
group: qgs-ai-summary-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
summarise:
runs-on: ubuntu-latest
env:
MODEL: gpt-5.4
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Build churn-free diff
id: diff
run: |
WORK="$RUNNER_TEMP/qgs-ai"
mkdir -p "$WORK"
python3 scripts/qgs-diff.py diff --base "${{ github.base_ref }}" > "$WORK/diff.txt"
[ -s "$WORK/diff.txt" ] && echo "changed=1" >> "$GITHUB_OUTPUT" || echo "changed=0" >> "$GITHUB_OUTPUT"
- name: Set up Node for the Copilot CLI
if: steps.diff.outputs.changed == '1'
uses: actions/setup-node@v4
with:
node-version: 24
- name: Install Copilot CLI
if: steps.diff.outputs.changed == '1'
run: npm install -g @github/copilot
- name: Summarise with the Copilot CLI
id: ai
if: steps.diff.outputs.changed == '1'
env:
# Built-in workflow token — the Copilot CLI authenticates from this
# (via the copilot-requests permission), so no PAT/secret is needed.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
WORK="$RUNNER_TEMP/qgs-ai"
cd "$WORK"
echo "::group::diff (contains $(wc -l < diff.txt) lines, $(wc -c < diff.txt) bytes)"
cat diff.txt
echo
echo "::endgroup::"
# Cap the inlined diff. Linux limits a single argv string to ~128 KB
# (MAX_ARG_STRLEN), so the whole -p argument (prompt + diff) must stay
# under that or copilot dies with "Argument list too long". The
# churn-free diff is normally well under this; only a wholesale rewrite
# truncates. Override with INPUT_CHAR_BUDGET.
BUDGET="${INPUT_CHAR_BUDGET:-110000}"
DIFF="$(head -c "$BUDGET" diff.txt)"
if [ "$(wc -c < diff.txt)" -gt "$BUDGET" ]; then
DIFF="$(printf '%s\n[...diff truncated to %s chars to fit the arg limit; summary is partial...]' "$DIFF" "$BUDGET")"
fi
echo "::group::Generating summary with Copilot CLI (model $MODEL)"
# One-shot: the diff is INLINE (not a file to read) and the answer comes
# back on stdout via -s. This sidesteps the agent read/write loop -- with
# nothing to read and nothing to write, a large tool-result can't get
# evicted and trigger endless re-reads; it's a single completion.
PROMPT="$(printf '%s\n\n--- BEGIN CHURN-FREE DIFF ---\n%s\n--- END CHURN-FREE DIFF ---\n\n%s' \
"$(cat "$GITHUB_WORKSPACE/scripts/assets/qgs-review-prompt.md")" \
"$DIFF" \
'The complete churn-free diff is included above. Do NOT read or write any files. Output ONLY the markdown summary (no preamble or conclusion).')"
copilot \
--model "$MODEL" \
--allow-all-tools \
--no-ask-user \
--max-ai-credits 50 \
-s \
-p "$PROMPT" > summary.md || true
cp summary.md "$GITHUB_WORKSPACE/summary.md" 2>/dev/null || true
echo
echo "::endgroup::"
- name: Post sticky PR comment
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
PR: ${{ github.event.pull_request.number }}
CHANGED: ${{ steps.diff.outputs.changed }}
MODEL: ${{ env.MODEL }}
run: |
set -euo pipefail
MARKER='<!-- qgs-ai-summary -->'
{
echo "$MARKER"
echo "## 🗺️ QGIS project change summary"
echo
if [ "$CHANGED" = "1" ] && [ -s summary.md ]; then
cat summary.md
echo
echo "<sub>Generated by \`$MODEL\` via the GitHub Copilot CLI from a churn-free diff - verify against the file diff.</sub>"
else
echo "_No substantive QGIS project changes detected - only QGIS session churn._"
fi
} > comment.md
id=$(gh api "repos/$REPO/issues/$PR/comments" --paginate \
--jq ".[] | select(.body | contains(\"$MARKER\")) | .id" | head -n1)
if [ -n "$id" ]; then
gh api -X PATCH "repos/$REPO/issues/comments/$id" -F body=@comment.md >/dev/null
echo "updated comment $id"
else
gh api -X POST "repos/$REPO/issues/$PR/comments" -F body=@comment.md >/dev/null
echo "created comment"
fi