Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/giturl/giturl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package giturl

import (
"net/url"
"path/filepath"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -159,6 +160,19 @@ func GenerateLink(repo, commit, file string, line int64) string {
baseLink += "#L" + strconv.FormatInt(line, 10)
}
}
} else if strings.HasSuffix(repo, ".wiki.git") {
// GitHub Wiki links are formatted differently
baseLink = repo[:len(repo)-9] + "/wiki/"
if file != "" {
// remove file extension
baseLink += strings.TrimSuffix(file, filepath.Ext(file)) + "/"
}
if commit != "" {
baseLink += commit
}
if line > 0 {
baseLink += "#L" + strconv.FormatInt(line, 10)
}
Comment on lines +170 to +175
Copy link
Contributor

Choose a reason for hiding this comment

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

If these are real possibilities, I think they should have test cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

} else if file == "" {
baseLink = repo[:len(repo)-4] + "/commit/" + commit
} else {
Expand Down
27 changes: 27 additions & 0 deletions pkg/giturl/giturl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,33 @@ func TestGenerateLink(t *testing.T) {
},
want: "https://github.com/GeekMasher/tree-sitter-hcl/blob/a7f23cc5795769262f5515e52902f86c1b768994/example/real_world_stuff/coreos/coreos%25tectonic-installer%25installer%25frontend%25ui-tests%25output%25metal.tfvars#L1",
},
{
name: "github wiki link gen",
args: args{
repo: "https://github.com/hxnyk/hxnyk.wiki.git",
commit: "e5fdc764d6d405fc0e4e90e4bcf192357b1a1a87",
file: "Home.md",
line: int64(5),
},
want: "https://github.com/hxnyk/hxnyk/wiki/Home/e5fdc764d6d405fc0e4e90e4bcf192357b1a1a87#L5",
},
{
name: "github wiki link gen - no line",
args: args{
repo: "https://github.com/hxnyk/hxnyk.wiki.git",
commit: "e5fdc764d6d405fc0e4e90e4bcf192357b1a1a87",
file: "Home.md",
},
want: "https://github.com/hxnyk/hxnyk/wiki/Home/e5fdc764d6d405fc0e4e90e4bcf192357b1a1a87",
},
{
name: "github wiki link gen - no commit no line",
args: args{
repo: "https://github.com/hxnyk/hxnyk.wiki.git",
file: "Home.md",
},
want: "https://github.com/hxnyk/hxnyk/wiki/Home/",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down