Skip to content

Commit 43856fb

Browse files
dblockCopilot
andcommitted
Generate AI commit summaries for automated API updates
The daily "update" workflow committed changes with a generic, date-only message ("Updated from Slack docs, YYYY/MM/DD"), which doesn't say anything about what actually changed. Add a GitHub Models-backed step (actions/ai-inference@v1, using the default GITHUB_TOKEN with models: read permission, no extra secrets/subscription needed) that summarizes git diff / git diff --stat of the scraped changes into a short commit title (<=72 chars) and a few bullet points, via a structured .github/prompts/commit-message.prompt.yml with a JSON schema response so the output is easy to parse reliably. Falls back to the original generic, date-based message if there are no changes, the AI call fails, or the response is malformed, so the workflow never blocks on this step. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ff2d6a0 commit 43856fb

2 files changed

Lines changed: 90 additions & 1 deletion

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
messages:
2+
- role: system
3+
content: |-
4+
You write concise git commit messages describing automated updates to a Slack Web
5+
API reference JSON repository (methods, groups and events scraped from Slack's docs).
6+
Given a diffstat and a diff, respond with:
7+
- title: a single line, imperative mood, at most 72 characters, no trailing period,
8+
describing the most significant change (e.g. "Add chat.appendStream and
9+
chat.stopStream methods").
10+
- summary: 1-5 short bullet points (each starting with "- "), each describing one
11+
notable change: new/removed/renamed methods or events, added/removed arguments,
12+
changed error codes, etc.
13+
If the diff is routine or has no notable API surface changes, keep the title generic
14+
(e.g. "Minor documentation updates") and the summary brief or empty.
15+
- role: user
16+
content: |-
17+
Diffstat:
18+
{{diff_stat}}
19+
20+
Diff (may be truncated):
21+
{{diff}}
22+
model: openai/gpt-4o-mini
23+
responseFormat: json_schema
24+
jsonSchema: |-
25+
{
26+
"name": "commit_message",
27+
"strict": true,
28+
"schema": {
29+
"type": "object",
30+
"properties": {
31+
"title": {
32+
"type": "string",
33+
"description": "Single-line, imperative-mood commit title, max 72 characters, no trailing period"
34+
},
35+
"summary": {
36+
"type": "string",
37+
"description": "1-5 short bullet points, each starting with '- ', or empty string if nothing notable"
38+
}
39+
},
40+
"additionalProperties": false,
41+
"required": ["title", "summary"]
42+
}
43+
}

‎.github/workflows/update.yml‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
schedule:
66
- cron: "15 22 * * *"
77

8+
permissions:
9+
contents: write
10+
models: read
11+
812
jobs:
913
update:
1014
runs-on: ubuntu-latest
@@ -24,9 +28,51 @@ jobs:
2428
run: bundle exec rake api:validate
2529
- name: Get current date
2630
run: echo "CURRENT_DATE=$(date +%Y/%m/%d)" >> $GITHUB_ENV
31+
- name: Check for changes
32+
id: changes
33+
run: |
34+
if git diff --quiet; then
35+
echo "changed=false" >> "$GITHUB_OUTPUT"
36+
else
37+
echo "changed=true" >> "$GITHUB_OUTPUT"
38+
fi
39+
- name: Prepare diff for AI summary
40+
if: steps.changes.outputs.changed == 'true'
41+
run: |
42+
git diff --stat > /tmp/diff_stat.txt
43+
git diff | head -c 20000 > /tmp/diff.txt
44+
- name: Generate commit message with AI
45+
if: steps.changes.outputs.changed == 'true'
46+
id: ai
47+
uses: actions/ai-inference@v1
48+
with:
49+
prompt-file: ./.github/prompts/commit-message.prompt.yml
50+
file_input: |
51+
diff_stat: /tmp/diff_stat.txt
52+
diff: /tmp/diff.txt
53+
- name: Build commit message
54+
id: message
55+
run: |
56+
title=""
57+
summary=""
58+
if [ "${{ steps.changes.outputs.changed }}" = "true" ]; then
59+
title="$(jq -r '.title // empty' "${{ steps.ai.outputs.response-file }}" 2>/dev/null)"
60+
summary="$(jq -r '.summary // empty' "${{ steps.ai.outputs.response-file }}" 2>/dev/null)"
61+
fi
62+
if [ -z "$title" ]; then
63+
title="Updated from Slack docs, ${CURRENT_DATE}"
64+
summary=""
65+
fi
66+
{
67+
echo 'message<<COMMIT_MESSAGE_EOF'
68+
echo "$title"
69+
echo ""
70+
echo "$summary"
71+
echo 'COMMIT_MESSAGE_EOF'
72+
} >> "$GITHUB_OUTPUT"
2773
- name: Commit changes
2874
uses: EndBug/add-and-commit@v9
2975
with:
3076
author_name: Slack API Ref Buildbot
3177
author_email: buildbot@slack-api-ref.com
32-
message: "Updated from Slack docs, ${{ env.CURRENT_DATE }}"
78+
message: ${{ steps.message.outputs.message }}

0 commit comments

Comments
 (0)