diff --git a/pkg/host/github.go b/pkg/host/github.go index 9265a3c632abaa2cb8c8516fb45df7575a8d3b33..ff1fdd4a2c4fd6f9cb948827cae0755735a9ad49 100644 --- a/pkg/host/github.go +++ b/pkg/host/github.go @@ -5,7 +5,10 @@ import ( "strings" ) -const githubStorageURL = "https://codeload.github.com" +const ( + githubURL = "https://github.com" + githubStorageURL = "https://codeload.github.com" +) // ZipURL returns the URL of the zip archive given a github repository URL. func ZipURL(repo string) string { @@ -34,3 +37,13 @@ func ZipURL(repo string) string { return strings.Join(urlTokens, "/") } + +// URL returns the normalized URL of a GitHub repository. +func URL(repo string) string { + githubRegex := regexp.MustCompile(githubURL + `/(\S+)$`) + if githubRegex.MatchString(repo) { + return repo + } + + return strings.Join([]string{githubURL, repo}, "/") +}