Skip to content

Commit

Permalink
fix reference to commit of outside repo
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Oct 4, 2024
1 parent abcb059 commit 096c815
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion reflink.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (l *Reflinker) linkCommitURL(m [][]byte, url []byte, start, end int) {
if bytes.HasPrefix(url, []byte(l.repo)) {
replaced = fmt.Sprintf("[`%s`](%s)", hash, url)
} else {
replaced = fmt.Sprintf("[`%s@%s`](%s)", slug, hash, url)
replaced = fmt.Sprintf("[%s@`%s`](%s)", slug, hash, url)
}

l.links = append(l.links, refLink{
Expand Down
12 changes: 6 additions & 6 deletions reflink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,22 +401,22 @@ func TestLinkRefs(t *testing.T) {
{
what: "commit URL with full hash",
input: "this is https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe test",
want: "this is [`foo/bar@1d457ba853`](https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe) test",
want: "this is [foo/bar@`1d457ba853`](https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe) test",
},
{
what: "commit URL with partial hash",
input: "this is https://github.com/foo/bar/commit/1d457ba test",
want: "this is [`foo/bar@1d457ba`](https://github.com/foo/bar/commit/1d457ba) test",
want: "this is [foo/bar@`1d457ba`](https://github.com/foo/bar/commit/1d457ba) test",
},
{
what: "commit URL at start of text",
input: "https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe test",
want: "[`foo/bar@1d457ba853`](https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe) test",
want: "[foo/bar@`1d457ba853`](https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe) test",
},
{
what: "commit URL at end of text",
input: "test https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe",
want: "test [`foo/bar@1d457ba853`](https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe)",
want: "test [foo/bar@`1d457ba853`](https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe)",
},
{
what: "commit URL with explicit auto link",
Expand Down Expand Up @@ -456,7 +456,7 @@ func TestLinkRefs(t *testing.T) {
{
what: "commit URL in bold text",
input: "**https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe**",
want: "**[`foo/bar@1d457ba853`](https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe)**",
want: "**[foo/bar@`1d457ba853`](https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe)**",
},
{
what: "commit URL with GHE",
Expand All @@ -467,7 +467,7 @@ func TestLinkRefs(t *testing.T) {
{
what: "commit URL of outside repository with GHE",
input: "https://github.company.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe",
want: "[`foo/bar@1d457ba853`](https://github.company.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe)",
want: "[foo/bar@`1d457ba853`](https://github.company.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe)",
repoURL: "https://github.company.com/u/r",
},
{
Expand Down

0 comments on commit 096c815

Please sign in to comment.