Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions pkg/giturl/giturl.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,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 != "" {
baseLink += strings.TrimSuffix(file, ".md") + "/"
Copy link
Contributor

Choose a reason for hiding this comment

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

This assumes that if file is empty, the actual file we care about is a markdown file, right? That seems very specific. How do we know that?

In any case, this seems like something that should be explained in a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for this comment because my assumption was that wiki documents can only be created in markdown format, but it turns out github supports all of these:
image

Even though markdown is set by default and most wikis would be using markdown, best solution would be to just remove the file extension, whatever it is. I'll do that

}
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


Copy link
Contributor

Choose a reason for hiding this comment

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

I know I'm being persnickety but this newline is bugging me :/

} else if file == "" {
baseLink = repo[:len(repo)-4] + "/commit/" + commit
} else {
Expand Down
10 changes: 10 additions & 0 deletions pkg/giturl/giturl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ 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",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down