Links to pull request commits are auto-converted incorrectly

The following description is copied (with minor rewordings) from Links to pull request commits are auto-converted incorrectly by mspncp · Pull Request #3 · mspncp/playground · GitHub, which not only explains, but also demonstrates the issue.

Observed behaviour

If you copy&base the following URL in the editor control at the end of the pull request thread

https://github.com/mspncp/playground/pull/3/commits/aa7cea14c709dfe772d297b68f43543a5f17c5eb

the editor recognizes and auto-converts it to a pretty short hash URL aa7cea1. Unfortunately, that auto-converted link points to the “detached commit”

https://github.com/mspncp/playground/commit/aa7cea14c709dfe772d297b68f43543a5f17c5eb

and not to the original commit attached to the pull request, i.e., the “Files changed” view, narrowed down to that single commit.

This is inconvenient, because reviewers might follow the link and make code comments which don’t become part of this pr’s thread.

Expected behaviour

Regardless of how the commit is entered by the user (text or URL), an auto-converted commit link should always link to the “pull request commit”

https://github.com/<user>/<repo>/pull/<pr_num>/commits/<commit_id>

if the commit <commit_id> is part of the pull request, and only otherwise to the “detached commit”

https://github.com/<user>/<repo>/commit/<commit_id>

Commits are Git object independent of branches, pull requests, etc. A same commit might exist in different branches. The expected behavior for Autolinked references and URLs is exactly what you’re seeing.

I see what you mean, but reviewing single commits is a supported GitHub feature with its own merits (i.e. it can be viewed from any branch that contains the commit, even if it didn’t go through a PR).

If you want to reference a pull request, just use the #3 notation (or mspncp/playground#3).