Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

Summary

This PR fixes the issue where commit SHAs mentioned in PR comments are not highlighted and hyperlinked when viewed in the file view (inline comments).

Changes Completed

  • Understand the issue: Commit SHAs are not highlighted/hyperlinked in file view comments
  • Locate the code: Comments are rendered via GHPRComment.replaceBody() in src/github/prComment.ts
  • Identify the gap: The webview uses bodyHTML (pre-processed by GitHub), but file view uses body text and manually processes it
  • Add commit SHA detection and linking logic to GHPRComment.replaceBody()
  • Add tests for commit SHA regex pattern
  • Extract regex as exported constant for testability
  • Run linting and fix any issues
  • Address code review feedback
  • Run security checks (CodeQL - no vulnerabilities found)
  • Fix failing test (backtick exclusion test)

Implementation Details

Core Changes (src/github/prComment.ts)

  • Added COMMIT_SHA_EXPRESSION regex constant to match 7 or 40-character commit SHAs
  • Created replaceCommitShas() method that:
    • Detects standalone commit SHAs using regex with negative lookahead/lookbehind
    • Avoids matching SHAs in URLs, code blocks (backticks), or markdown links
    • Converts matched SHAs to markdown links: [shortSha](https://host/owner/repo/commit/sha)
  • Integrated into the replaceBody() transformation pipeline

Tests (src/test/github/prComment.test.ts)

  • 7 comprehensive test cases covering various SHA matching scenarios
  • Tests use the exported COMMIT_SHA_EXPRESSION constant for consistency
  • Fixed test expectation: regex correctly excludes SHAs after backticks via negative lookbehind

Security

  • CodeQL scan completed: 0 vulnerabilities found
  • No unsafe patterns or security issues introduced
Original prompt

This section details on the original issue you should resolve

<issue_title>Commit SHAs in PR comments are not highlighted or hyperlinked in the file view</issue_title>
<issue_description>Commit SHAs are not highlighted and hyperlinked when comments are rendered in-line in the file viewer.

Image

This works as expected in the PR description view:

Image

  • Extension version: 0.108.0
  • VSCode Version: 1.99.0-insider
  • OS: macOS Sequoia 15.4
  • Repository Clone Configuration (single repository/fork of an upstream repository): Single repository
  • Github Product (Github.com/Github Enterprise version x.x.x): GitHub.com

Steps to Reproduce:

  1. Create a pull request review comment in GitHub which references a commit SHA
  2. Open the PR's description view in VS Code. The SHA is highlighted and hyperlinked to the commit on GitHub.com.
  3. Open the file view in VS Code. The SHA is not highlighted or hyperlinked.
    </issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix commit SHAs highlighting in PR comments Link commit SHAs in inline file comments Dec 10, 2025
Copilot AI requested a review from alexr00 December 10, 2025 15:04
Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

@copilot test failure in CI:

 1) commit SHA replacement
       should not match SHAs in code blocks:

      AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

1 !== 2

      + expected - actual

      -1
      +2
      
      at Context.<anonymous> (src/test/github/prComment.test.ts:35:10)
      at processImmediate (node:internal/timers:485:21)

Copy link
Contributor Author

Copilot AI commented Dec 15, 2025

@copilot test failure in CI:

 1) commit SHA replacement...

Fixed in 490b411. The test expectation was incorrect - the regex's negative lookbehind (?<![/\w])` already prevents matching SHAs after backticks, so only 1 match is expected, not 2.

Copilot AI requested a review from alexr00 December 15, 2025 11:10
@alexr00 alexr00 marked this pull request as ready for review December 15, 2025 11:18
@alexr00 alexr00 marked this pull request as draft December 15, 2025 11:19
@alexr00 alexr00 marked this pull request as ready for review December 15, 2025 11:19
@alexr00 alexr00 enabled auto-merge (squash) December 15, 2025 11:19
@vs-code-engineering vs-code-engineering bot added this to the December / January 2026 milestone Dec 15, 2025
@alexr00 alexr00 merged commit 0bed968 into main Dec 15, 2025
6 checks passed
@alexr00 alexr00 deleted the copilot/fix-sha-highlighting-comments branch December 15, 2025 11:22
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.

Commit SHAs in PR comments are not highlighted or hyperlinked in the file view

3 participants