add a github action for generating mermaid diagram on 'needs-diagram' PR#2095
Open
jeesunikim wants to merge 1 commit into
Open
add a github action for generating mermaid diagram on 'needs-diagram' PR#2095jeesunikim wants to merge 1 commit into
jeesunikim wants to merge 1 commit into
Conversation
Contributor
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.
Comment on lines
+61
to
+70
| 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 | ||
| ), |
Comment on lines
+7
to
+25
| 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 |
Comment on lines
+111
to
+115
| # 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) | ||
|
|
Comment on lines
+24
to
+32
| - 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)