Skip to content

prevent-link-loss - Use "this PR" for same-PR commit links#8860

Merged
fregante merged 2 commits intomainfrom
copilot/prevent-link-loss-feature
Jan 10, 2026
Merged

prevent-link-loss - Use "this PR" for same-PR commit links#8860
fregante merged 2 commits intomainfrom
copilot/prevent-link-loss-feature

Conversation

Copy link
Contributor

Copilot AI commented Jan 9, 2026

When pasting a PR commit link into a comment on the same PR, the feature now displays "(this PR)" instead of redundantly showing the PR number.

Changes

  • Modified preventPrCommitLinkLoss to detect current PR via getConversationNumber() and conditionally render PR reference
  • Added test coverage for same-PR, different-PR, and non-PR contexts

Behavior

# Viewing PR #123, paste: github.com/org/repo/pull/123/commits/abc123
Before: `abc123` (#123)
After:  `abc123` (this PR)

# Viewing PR #123, paste: github.com/org/repo/pull/456/commits/abc123
Result: `abc123` (#456)  [unchanged]

Test URLs

Screenshot

(Manual testing in browser environment required to capture UI behavior)

Original prompt

This section details on the original issue you should resolve

<issue_title>prevent-link-loss: Don't include PR number in commit link in same PR</issue_title>
<issue_description>## Description

Currently, if you paste a commit link like https://github.com/refined-github/refined-github/pull/6145/commits/c71e0bc631a1e27ec75044fc95cc2b4b4839258a into a comment on my PR and use refined-github's "Fix link" feature, it includes the PR number like this: c71e0bc (#6145).

I propose that this feature should dynamically include/omit the PR number from the link's text depending on whether you are commenting in that same PR, in which case the PR number seems redundant.

So, using the same link as above…

  • OUTSIDE REPO (OUTSIDE PR) — currently supported ✅
    commenting elsewhere outside of the repo, it would replace the link with:

    refined-github/refined-github@c71e0bc (#6145)

  • INSIDE REPO, OUTSIDE PR — currently supported ✅
    commenting in the same repo, but outside the PR, it would replace the link with:

    c71e0bc (#6145)

  • INSIDE REPO, INSIDE PR — currently unsupported ❌
    commenting in the PR, it would replace the link with:

    c71e0bc

Screenshot

After pasting link

Screen Shot 2022-11-16 at 13 08 51

After clicking "Fix link" in "Write" mode

Screen Shot 2022-11-16 at 13 08 59

After clicking "Fix link" in "Preview" mode

Screen Shot 2022-11-16 at 13 09 03

Example URLs

https://github.com/refined-github/refined-github/pull/6145/commits/c71e0bc631a1e27ec75044fc95cc2b4b4839258a
```</issue_description>

<agent_instructions>it should say "this PR" if it points to the current PR</agent_instructions>

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

<comments>
<comment_new><author>@fregante</author><body>
If we don't include the PR number, I think we should still mention "PR commit" or else, like GitHub, a **commit link** will be indistinguishable from a **PR commit link**

- https://github.com/refined-github/refined-github/commit/c71e0bc631a1e27ec75044fc95cc2b4b4839258a
- [`c71e0bc`](https://github.com/refined-github/refined-github/pull/6145/commits/c71e0bc631a1e27ec75044fc95cc2b4b4839258a)</body></comment_new>
<comment_new><author>@fregante</author><body>
This should be fixed in:

- https://github.com/refined-github/refined-github/blob/71c16f38d5d7853e57bd3e36852175b30eed89c3/source/github-helpers/prevent-link-loss.ts

I'm not sure why the feature wasn't implemented using https://github.com/refined-github/shorten-repo-url, which has this specific logic already (although probably doesn't support this exact type of link)

Similar request:

- https://github.com/refined-github/refined-github/issues/6057</body></comment_new>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Prevent PR number in commit link for same PR feat(prevent-link-loss): Use "this PR" for same-PR commit links Jan 9, 2026
Copilot AI requested a review from fregante January 9, 2026 12:06
@fregante fregante changed the title feat(prevent-link-loss): Use "this PR" for same-PR commit links prevent-link-loss - Use "this PR" for same-PR commit links Jan 10, 2026
@fregante fregante marked this pull request as ready for review January 10, 2026 08:53
@fregante fregante enabled auto-merge (squash) January 10, 2026 08:55
@fregante fregante merged commit 7a1a0c2 into main Jan 10, 2026
19 checks passed
@SunsetTechuila SunsetTechuila deleted the copilot/prevent-link-loss-feature branch February 4, 2026 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

prevent-link-loss: Don't include PR number in commit link in same PR

2 participants