Skip to content
GitHub Login

Commit summarizer

A simple GitHub Actions workflow that summarizes the commits in a pull request and posts the summary as a comment.

Commit Summarizer

You’ll need to add system instructions and create a param for the commit messages. For example:

## System
You are an assistant that summarizes commit messages into a concise summary to be attached to as a comment on a Pull Request.
## User
{{ commit_messages }}

You’ll need a GitHub Personal Access Token to comment on the pull request. The token will need the contents, issues, and pull-requests scopes.

Add the following workflow to your repository (e.g. .github/workflows/summarize-pr-commits.yml). Make sure you replace the ENDPOINT with your own endpoint path, and add your Github Personal Access Token (COMMENT_TOKEN) and 8080 API key (EIGHTY80_API_KEY) as secrets in your repository settings.

name: Summarize PR Commits
permissions:
contents: read
issues: write
on:
pull_request_target:
types: [opened,reopened]
jobs:
summarize:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
repository: ${{ github.repository }}
- name: Gather commit messages
id: commits
run: |
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
# Extract commit messages between base and head
COMMIT_MESSAGES=$(git log --format=%B "${BASE_SHA}..${HEAD_SHA}")
echo "commit_messages<<EOF" >> $GITHUB_OUTPUT
echo "${COMMIT_MESSAGES}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Summarize PR commit messages
id: summarize
env:
API_KEY: ${{ secrets.EIGHTY80_API_KEY }}
ENDPOINT: "org/project/endpointId"
run: |
# Build payload with commit_messages parameter
PAYLOAD=$(jq -n --arg user "${{ steps.commits.outputs.commit_messages }}" '{
commit_messages: $user
}')
echo "Payload: $PAYLOAD"
# Call the new endpoint API
RESPONSE=$(curl -s -X POST "https://api.8080.io/v1/endpoints/${ENDPOINT}" \
-H "Authorization: Bearer ${API_KEY}" \
-H "Content-Type: application/json" \
-d "$PAYLOAD")
echo "API Response: $RESPONSE"
# Extract the summary from the response (changed from .summary to .response)
SUMMARY=$(echo "$RESPONSE" | jq -r '.response')
# Only proceed if summary is not null
if [ "$SUMMARY" != "null" ] && [ -n "$SUMMARY" ]; then
# Output the plain summary
echo "summary<<EOF" >> $GITHUB_OUTPUT
echo "$SUMMARY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Encode the summary in Base64 and output it
SUMMARY_B64=$(echo "$SUMMARY" | base64)
echo "summary_b64<<EOF" >> $GITHUB_OUTPUT
echo "$SUMMARY_B64" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "No valid summary received from API"
exit 1
fi
- name: Post summary as a PR comment
uses: actions/github-script@v6
env:
SUMMARY_B64: ${{ steps.summarize.outputs.summary_b64 }}
with:
github-token: ${{ secrets.COMMENT_TOKEN }}
script: |
const summary = "\n" + Buffer.from(process.env.SUMMARY_B64, 'base64').toString('utf8');
const prNumber = context.payload.pull_request.number;
const commentBody = `## Commit Summary\n${summary}`;
await github.rest.issues.createComment({
...context.repo,
issue_number: prNumber,
body: commentBody
});