add a github action for generating mermaid diagram on 'needs-diagram' PR#2095
add a github action for generating mermaid diagram on 'needs-diagram' PR#2095jeesunikim wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds automation to generate and embed a Mermaid “architecture diagram” into PR descriptions when a needs-diagram label is applied, plus enables a Claude plugin intended to make generated HTML easier to review.
Changes:
- Introduces a new GitHub Actions workflow that fetches a PR diff, calls Anthropic to generate a Mermaid diagram, and updates the PR body between marker comments.
- Adds
.claude/settings.jsonto enable theplaygroundplugin.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| .github/workflows/pr-diagram.yml | New workflow to generate Mermaid diagrams from PR diffs and write them into the PR body on needs-diagram labeling. |
| .claude/settings.json | Enables the playground@claude-plugins-official plugin. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| payload = { | ||
| "model": "claude-sonnet-4-6", | ||
| "max_tokens": 4096, | ||
| "system": system, | ||
| "messages": [{ | ||
| "role": "user", | ||
| "content": ( | ||
| "Generate a Mermaid diagram summarizing the architectural " | ||
| "changes in this PR diff:\n\n" + diff | ||
| ), |
| on: | ||
| pull_request: | ||
| types: [labeled] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| concurrency: | ||
| group: pr-diagram-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| diagram: | ||
| if: github.event.label.name == 'needs-diagram' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 |
| # Extract the fenced mermaid block in case the model wrapped it in prose. | ||
| match = re.search(r'```mermaid.*?```', mermaid, re.DOTALL) | ||
| if match: | ||
| mermaid = match.group(0) | ||
|
|
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Fetch PR diff | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| PR: ${{ github.event.pull_request.number }} | ||
| run: | | ||
| gh pr diff "$PR" > /tmp/pr.diff |
|
Preview is available here: |
|
|
||
| - name: Generate Mermaid diagram | ||
| env: | ||
| ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
There was a problem hiding this comment.
Plan to switch to Anthropic WIF auth, see this for example: https://github.com/stellar/internal-agents/blob/20ebd49e46ed2a4473a653e27de9b57cd3e8a024/.github/workflows/bug-finder.yml#L48-L56
Don't block on this though, we should just come back and generate a WIF auth setup for this repo to replace the key usage.
|
Preview is available here: |
playgroundplugin for generating html for easy code review (example)pr-diagram.yml:-- Triggers only on pull_request: labeled with
needs-diagram-- Concurrency group cancels in-progress runs if you re-label quickly
-- Fetches diff via gh pr diff, truncates to 200KB if oversized (line 32–43)
-- Calls Anthropic API (Sonnet 4.6) via Python stdlib — no extra deps needed (line 49–93)
-- Updates the PR body between / markers; appends if absent (line 95–134)