Skip to content

feat: Link annotations to the spec file at the failing line - #129

Closed
LuukvH wants to merge 2 commits into
masterfrom
claude/annotation-blob-link
Closed

LuukvH wants to merge 2 commits into
masterfrom
claude/annotation-blob-link

Conversation

@LuukvH

@LuukvH LuukvH commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Refs #92

GitHub builds the annotation link itself from the file and line parameters and opens the commit view. That view only shows files changed in that commit, so a failing spec in a file the commit didn't touch can't be seen there. Workflow commands have no parameter for setting the URL.

This PR appends a link to the spec file at the failing line in the tested commit to the annotation message:

https://github.com/<owner>/<repo>/blob/<sha>/spec/models/user_spec.rb#L12
  • The link is built from GITHUB_SERVER_URL, GITHUB_REPOSITORY and GITHUB_SHA, and is left out when those aren't set (e.g. local runs).
  • GITHUB_SHA is the commit that was tested (the merge commit on pull_request events), so the linked line matches the annotation's line.
  • Each path segment is percent-encoded, so characters like # or spaces don't break the link.
  • The specs clear these env vars by default so the existing exact-output tests also pass in CI.

Still to verify: whether GitHub makes URLs inside annotation messages clickable. Check the annotations of this PR's own failing integration spec in the CI run.

The annotation link that GitHub generates opens the commit view, which
only shows files changed in that commit. Append a link to the spec file
at the failing line in the tested revision to the annotation message.
For pull_request events the pull request head commit is used instead of
the temporary merge commit.

Refs #92
@LuukvH
LuukvH requested review from a team and a balanced review from Copilot November 16, 2026 11:10

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.

🟡 Changes recommended

Spec notification links break for paths containing # and can target the PR head instead of the tested merge commit, opening the wrong revision or line.

2 open issues
What changed in this PR

Adds direct spec-file links to annotation messages, addressing #92 by letting users navigate to files omitted from GitHub’s commit view.

Changes:

  • Builds file-and-line URLs from GitHub Actions environment variables, preferring the PR head SHA when available.
  • Adds URL assertions and isolates GitHub environment variables in formatter specs.
  • Documents the new links and the limitation of annotation navigation.
File Description
spec/​rspec/​github/​formatter_spec.rb Tests annotation URLs and isolates GitHub environment variables.
README.md Explains direct spec links and commit-view limitations.
lib/​rspec/​github/​notification_decorator.rb Builds revision-specific URLs and appends them to annotations.

Review effort: Balanced

Percent-encode each path segment so characters like # or spaces don't
break the link, and always use GITHUB_SHA so the link points at the
commit that was actually tested (the merge commit on pull_request
events), keeping line numbers in sync with the annotation.
@LuukvH LuukvH closed this Nov 16, 2026
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