Skip to content

Commit a61492b

Browse files
committed
handle wiki links generation
1 parent fa512d5 commit a61492b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

pkg/giturl/giturl.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ func GenerateLink(repo, commit, file string, line int64) string {
159159
baseLink += "#L" + strconv.FormatInt(line, 10)
160160
}
161161
}
162+
} else if strings.HasSuffix(repo, ".wiki.git") {
163+
// GitHub Wiki links are formatted differently
164+
baseLink = repo[:len(repo)-9] + "/wiki/"
165+
if file != "" {
166+
baseLink += strings.TrimSuffix(file, ".md") + "/"
167+
}
168+
if commit != "" {
169+
baseLink += commit
170+
}
171+
if line > 0 {
172+
baseLink += "#L" + strconv.FormatInt(line, 10)
173+
}
174+
162175
} else if file == "" {
163176
baseLink = repo[:len(repo)-4] + "/commit/" + commit
164177
} else {

pkg/giturl/giturl_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ func TestGenerateLink(t *testing.T) {
210210
},
211211
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",
212212
},
213+
{
214+
name: "github wiki link gen",
215+
args: args{
216+
repo: "https://github.com/hxnyk/hxnyk.wiki.git",
217+
commit: "e5fdc764d6d405fc0e4e90e4bcf192357b1a1a87",
218+
file: "Home.md",
219+
line: int64(5),
220+
},
221+
want: "https://github.com/hxnyk/hxnyk/wiki/Home/e5fdc764d6d405fc0e4e90e4bcf192357b1a1a87#L5",
222+
},
213223
}
214224
for _, tt := range tests {
215225
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)