Skip to content

Commit

Permalink
fixed gist direct link generation
Browse files Browse the repository at this point in the history
  • Loading branch information
joeleonjr committed Nov 17, 2023
1 parent 39a603d commit 02c2ff8
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pkg/giturl/giturl.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,25 @@ func GenerateLink(repo, commit, file string, line int64) string {
fallthrough
default:
var baseLink string
if file == "" {

//Gist links are formatted differently
if strings.HasPrefix(repo, "https://gist.github.com") {
baseLink = repo[:len(repo)-4] + "/"
if commit != "" {
baseLink += commit + "/"
}
if file != "" {
cleanedFileName := strings.ReplaceAll(file, ".", "-")
baseLink += "#file-" + cleanedFileName
}
if line > 0 {
if strings.Contains(baseLink, "#") {
baseLink += "-L" + strconv.FormatInt(line, 10)
} else {
baseLink += "#L" + strconv.FormatInt(line, 10)
}
}
} else if file == "" {
baseLink = repo[:len(repo)-4] + "/commit/" + commit
} else {
baseLink = repo[:len(repo)-4] + "/blob/" + commit + "/" + file
Expand Down

0 comments on commit 02c2ff8

Please sign in to comment.