Skip to content

Find, verify, and analyze leaked credentials

Fix Github Wiki Page Links (#4538)

Mustansirf1ccb3979760
diff --git a/pkg/giturl/giturl.go b/pkg/giturl/giturl.go
index 3270c72ab..7c2648bcf 100644
--- a/pkg/giturl/giturl.go
+++ b/pkg/giturl/giturl.go
@@ -2,6 +2,7 @@ package giturl
import (
"net/url"
+ "path/filepath"
"regexp"
"strconv"
"strings"
@@ -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)
+ }
} else if file == "" {
baseLink = repo[:len(repo)-4] + "/commit/" + commit
} else {
diff --git a/pkg/giturl/giturl_test.go b/pkg/giturl/giturl_test.go
index 27838a360..5e40d27db 100644
--- a/pkg/giturl/giturl_test.go
+++ b/pkg/giturl/giturl_test.go
@@ -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) {