better RepoID parsing

This commit is contained in:
AJ ONeal 2021-03-17 11:39:47 -06:00
parent aace88348e
commit d5dec5f3b3
1 changed files with 14 additions and 0 deletions

View File

@ -173,6 +173,20 @@ func getRepoID(url string) string {
repoID := strings.TrimPrefix(url, "https://")
repoID = strings.TrimPrefix(repoID, "http://")
repoID = strings.TrimPrefix(repoID, "ssh://")
// "gitea@example.com:my-org/my-project" // removes gitea@
// "git/ea@example.com:my-org/my-project" // no change
// "gitea@" // empty string
firstSlash := strings.Index(repoID, "/")
firstAt := strings.Index(repoID, "@")
if firstSlash < 0 {
firstSlash = 999999
}
if firstAt >= 0 && firstAt < firstSlash && len(repoID) >= firstAt {
repoID = repoID[firstAt+1:]
repoID = strings.Replace(repoID, ":", "/", 1)
}
repoID = strings.TrimSuffix(repoID, ".git")
return repoID
}