Add support for github paths starting with "git@github.com:"

This commit is contained in:
Haiyan Meng
2019-12-16 11:08:38 -08:00
parent e44d1298df
commit 12fc8f41c7
2 changed files with 15 additions and 3 deletions

View File

@@ -78,11 +78,17 @@ func (doc *Document) ID() string {
}
func (doc *Document) RepositoryFullName() string {
doc.RepositoryURL = strings.TrimRight(doc.RepositoryURL, "/")
sections := strings.Split(doc.RepositoryURL, "/")
url := strings.TrimRight(doc.RepositoryURL, "/")
gitPrefix := "git@github.com:"
if strings.HasPrefix(url, gitPrefix) {
url = url[len(gitPrefix):]
}
sections := strings.Split(url, "/")
l := len(sections)
if l < 2 {
return doc.RepositoryURL
return url
}
return path.Join(sections[l-2], sections[l-1])
}

View File

@@ -92,6 +92,12 @@ func TestDocument_RepositoryFullName(t *testing.T) {
},
expectedRepositoryFullName: "",
},
{
doc: Document{
RepositoryURL: "git@github.com:user/repo",
},
expectedRepositoryFullName: "user/repo",
},
}
for _, tc := range testCases {