Skip to content
Snippets Groups Projects
Commit 6caa7833 authored by David McKay's avatar David McKay Committed by Tamer Tas
Browse files

Allowing a version/branch string to be parsed in download url (#18)

Allows a version/branch string to be parsed in download url
parent f1747fbb
No related branches found
No related tags found
No related merge requests found
......@@ -2,16 +2,32 @@ package host
import (
"path/filepath"
"regexp"
"strings"
)
// ZipURL returns the URL of the zip archive given a github repository URL.
func ZipURL(url string) string {
var version = "master"
url = strings.TrimSuffix(strings.TrimPrefix(url, "/"), "/")
if strings.HasSuffix(url, "zip/master") {
zipRegex, _ := regexp.Compile(`zip/(\S+)$`)
if zipRegex.MatchString(url) {
return url
}
return "https://codeload.github.com/" + filepath.Join(url, "/zip/master")
// So this could identify a port number, but since we only support github
// I don't believe using it as a version modifier is a problem. Though
// perhaps we should use something else instead?
if strings.Contains(url, ":") {
parts := strings.SplitAfter(url, ":")
url = parts[0]
version = parts[1]
url = strings.TrimSuffix(url, ":")
}
return "https://codeload.github.com/" + filepath.Join(url, "/zip/"+version)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment