Skip to content

Commit b019203

Browse files
committed
refactor getGitHubRepo to simplify prefix match
1 parent 608fc6b commit b019203

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

gitty/helper.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,16 @@ var (
2121

2222
// getGitHubRepo parses and extracts the repository path from a GitHub URL.
2323
func getGitHubRepo(url string) (string, error) {
24-
h, hFound := strings.CutPrefix(url, hPrefix)
25-
p, found := strings.CutPrefix(url, prefix)
26-
27-
switch {
28-
case hFound:
29-
if isInvalidFormat(h) {
30-
return "", ErrNotValidURLFormat
31-
}
32-
return h, nil
33-
case found:
34-
if isInvalidFormat(p) {
35-
return "", ErrNotValidURLFormat
24+
prefixes := []string{hPrefix, prefix}
25+
for _, pref := range prefixes {
26+
if path, ok := strings.CutPrefix(url, pref); ok {
27+
if isInvalidFormat(path) {
28+
return "", ErrNotValidURLFormat
29+
}
30+
return path, nil
3631
}
37-
return p, nil
38-
default:
39-
return "", ErrNotValidURL
4032
}
33+
return "", ErrNotValidURL
4134
}
4235

4336
// isInvalidFormat checks if the URL has an invalid format.

0 commit comments

Comments
 (0)