Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
close #55 - be more robust in handling repo input
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Mar 12, 2018
1 parent c3fe34a commit d724148
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion main.go
Expand Up @@ -73,6 +73,21 @@ func makeName(prefix, target string) (string, error) {
return out.String(), err
}

// returns the owner/name repo from input
//
// see https://github.com/goreleaser/godownloader/issues/55
func normalizeRepo(repo string) string {
// handle full or partial URLs
repo = strings.TrimPrefix(repo, "https://github.com/")
repo = strings.TrimPrefix(repo, "http://github.com/")
repo = strings.TrimPrefix(repo, "github.com/")

// hande /name/repo or name/repo/ cases
repo = strings.Trim(repo, "/")

return repo
}

func loadURLs(path string) (*config.Project, error) {
for _, file := range []string{"goreleaser.yml", ".goreleaser.yml", "goreleaser.yaml", ".goreleaser.yaml"} {
var url = fmt.Sprintf("%s/%s", path, file)
Expand Down Expand Up @@ -118,7 +133,8 @@ func Load(repo string, file string) (project *config.Project, err error) {
return nil, fmt.Errorf("repo or file not specified")
}
if file == "" {
log.Printf("read repo %q on github", repo)
repo = normalizeRepo(repo)
log.Printf("reading repo %q on github", repo)
project, err = loadURLs(
fmt.Sprintf("https://raw.githubusercontent.com/%s/master", repo),
)
Expand Down

0 comments on commit d724148

Please sign in to comment.