Compare commits

...

1 Commits

Author SHA1 Message Date
wangyue789 4b6c2a7a72 fix(context): normalize remote path segments 2026-06-11 10:37:19 +08:00
2 changed files with 4 additions and 2 deletions

View File

@ -59,10 +59,10 @@ func parseRemoteURL(remote string) (string, string, error) {
}
func parsePathSegments(path string) (string, string, error) {
path = strings.TrimPrefix(path, "/")
path = strings.Trim(path, "/")
path = strings.TrimSuffix(path, ".git")
parts := strings.SplitN(path, "/", 3)
if len(parts) < 2 {
if len(parts) < 2 || parts[0] == "" || parts[1] == "" {
return "", "", fmt.Errorf("cannot extract owner/repo from path: %s", path)
}
return parts[0], parts[1], nil

View File

@ -76,8 +76,10 @@ func TestParsePathSegments(t *testing.T) {
{"with git", "owner/repo.git", "owner", "repo", false},
{"leading slash", "/owner/repo", "owner", "repo", false},
{"both", "/owner/repo.git", "owner", "repo", false},
{"trailing slash", "/owner/repo.git/", "owner", "repo", false},
{"with subpath", "owner/repo/sub", "owner", "repo", false},
{"single segment", "onlyowner", "", "", true},
{"missing repo", "onlyowner/", "", "", true},
{"empty", "", "", "", true},
}
for _, tt := range tests {