Skip to content

Commit b630944

Browse files
Fixed Gist URL Detection (#4284)
* Fixed Gist URL Detection * eased the condition * updated comment * added another example in comment
1 parent 562dd72 commit b630944

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

pkg/sources/github/github.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/url"
1010
"os"
1111
"regexp"
12+
"slices"
1213
"sort"
1314
"strings"
1415
"sync"
@@ -1165,8 +1166,26 @@ func extractGistID(urlParts []string) string {
11651166
return urlParts[len(urlParts)-1]
11661167
}
11671168

1169+
// isGistUrl returns true if the URL path is of a gist
11681170
func isGistUrl(urlParts []string) bool {
1169-
return strings.EqualFold(urlParts[0], "gist.github.com") || (len(urlParts) == 4 && strings.EqualFold(urlParts[1], "gist"))
1171+
if len(urlParts) == 0 {
1172+
return false
1173+
}
1174+
1175+
// standard github gists: gist.github.com/user/abc123
1176+
if strings.EqualFold(urlParts[0], "gist.github.com") {
1177+
return true
1178+
}
1179+
1180+
// github enterprise: any 3 or 4 parts url with 'gist'
1181+
if (len(urlParts) == 3 || len(urlParts) == 4) && slices.Contains(urlParts, "gist") {
1182+
// enterprise.company.com/gist/gist-id
1183+
// gist.company.com/gist/gist-id
1184+
// gist.company.com/path/gist/gist-id
1185+
return true
1186+
}
1187+
1188+
return false
11701189
}
11711190

11721191
func (s *Source) chunkGistComments(ctx context.Context, gistURL string, gistInfo repoInfo, comments []*github.GistComment, reporter sources.ChunkReporter, cutoffTime *time.Time) error {

0 commit comments

Comments
 (0)