Feat/pr context - #1
Merged
Merged
Conversation
Reads git diff, digs the trail behind each touched region — widened by a context margin so insertions pick up the history of the code they land among — and excludes the change's own commits so it never reports a PR back at its author. Regions sharing a trail collapse, what remains ranks by how load-bearing its history looks, and when nothing is load-bearing it invites recording the why in the commit or PR. Posts and updates a single marked comment in place via gh; --dry-run prints the plan. Hop and note markdown formatting is now shared with dig.
Composite action builds why and runs 'why diff <base> --comment' on pull_request, updating one marker comment in place. Example workflow in examples/.
There was a problem hiding this comment.
Pull request overview
Adds a “PR context” feature that summarizes the decision/history trail for the exact regions touched by a change and (optionally) posts/updates that summary as a single pull request comment.
Changes:
- Refactors markdown rendering to reuse shared helpers for note/hop formatting.
- Introduces
why diffto parse a diff into changed regions, dig their trails, and render a consolidated PR comment (with optional posting/updating viagh). - Adds a composite GitHub Action (
action.yml) plus an example workflow to run it onpull_request.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/render/markdown.go | Extracts reusable helpers for note and hop markdown rendering. |
| internal/render/comment.go | Adds consolidated PR-comment rendering with section collapsing, ranking, and nudging. |
| internal/render/comment_test.go | Adds tests for comment section collapsing/tallying/nudging behavior. |
| cmd/diff.go | Adds why diff command to compute changed regions, dig trails, and optionally post/update a PR comment. |
| cmd/diff_test.go | Adds unit tests for commit exclusion and context expansion/clamping. |
| action.yml | Adds composite action to build why and post the context comment in PR workflows. |
| examples/why-pr-context.yml | Provides a sample workflow configuration for using the action. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+69
to
+81
| exclude := prCommits(cwd, base) | ||
| var trails []trail.Trail | ||
| for i, rg := range regions { | ||
| if i >= diffMax { | ||
| break | ||
| } | ||
| tr, err := dig.Run(cwd, rg, diffDepth) | ||
| if err != nil { | ||
| continue // a region we cannot read is one we simply skip | ||
| } | ||
| dropCommits(&tr, exclude) | ||
| trails = append(trails, tr) | ||
| } |
| run: | | ||
| # why walks line history, so the checkout must be unshallow | ||
| # (actions/checkout with fetch-depth: 0). Make sure the base is present. | ||
| git fetch --no-tags origin "${{ inputs.base }}" || true |
…omment dig.Run failures were silently skipped; if every region failed, the comment reported "No recorded history" — indistinguishable from genuinely-empty history. Now count skipped regions, warn on stderr, and fail when none of the considered regions could be read. Adds a runDig seam so the gather loop is unit-tested. Addresses Copilot review on the silently-ignored dig.Run errors.
Dropped the '|| true' that masked fetch failures; a missing base now fails at the fetch with an actionable ::error:: pointing at fetch-depth: 0, instead of surfacing later as a confusing why diff error. Fetches with an explicit refspec so origin/<base> is reliably created. Addresses Copilot review on the swallowed git fetch failure.
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.
No description provided.