Skip to content

Feat/pr context - #1

Merged
pyjeebz merged 4 commits into
mainfrom
feat/pr-context
Jun 30, 2026
Merged

Feat/pr context#1
pyjeebz merged 4 commits into
mainfrom
feat/pr-context

Conversation

@pyjeebz

@pyjeebz pyjeebz commented Jun 30, 2026

Copy link
Copy Markdown
Owner

No description provided.

pyjeebz added 2 commits June 30, 2026 01:55
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/.
Copilot AI review requested due to automatic review settings June 30, 2026 06:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 diff to parse a diff into changed regions, dig their trails, and render a consolidated PR comment (with optional posting/updating via gh).
  • Adds a composite GitHub Action (action.yml) plus an example workflow to run it on pull_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 thread cmd/diff.go
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)
}
Comment thread action.yml Outdated
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
pyjeebz added 2 commits June 30, 2026 02:24
…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.
@pyjeebz
pyjeebz merged commit c494c2e into main Jun 30, 2026
1 check passed
@pyjeebz
pyjeebz deleted the feat/pr-context branch July 18, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants