// getTags pull all tags from a repo, and use them for a release where appropriate. func (g Source) processRepoTags(repo github.Repository) { var repotags []github.RepositoryTag rv := RepoVersion{Name: *repo.Name, Org: *repo.Owner.Login} opts := &github.ListOptions{PerPage: 100} log.Printf("fetching tags for %s/%s\n", rv.Org, rv.Name) for { t, resp, err := g.client.Repositories.ListTags(rv.Org, rv.Name, opts) if err != nil { log.Printf("error fetching tags for repos: %s\n%s\n", rv.Name, err) continue } repotags = append(repotags, t...) if resp.NextPage == 0 { break } opts.Page = resp.NextPage } successCount := 0 for _, t := range repotags { if successCount >= g.Conf.MaxVersions { break } v, err := universe.ParseVersion(*t.Name) if err != nil { log.Printf("couldn't parse version '%s' for repo '%s', %s", *t.Name, rv.Name, err) continue } rv.Version = *v rv.Tag = *t.Name if len(rv.Version.Segments()) < 3 { log.Printf("version for %s at tag %s is not valid, skipping", rv.Name, *t.Name) continue } g.AddRepoRelease(rv) successCount++ } return }
func ParseVersion(t *testing.T) { for k, v := range map[string]string{ "v1": "1.1.0", "v1.0": "1.1.0", "v1.0.0": "1.1.0", "v1.0.0-patch": "1.1.0", "v1.0.0+build123": "1.1.0", } { tv, err := universe.ParseVersion(k) if err != nil { t.Fatalf("Error processing version for %s : %s", k, err.Error()) } if tv.String() != v { t.Fatalf("Expected '%s' got '%s' for input '%s'", v, tv.String(), k) } } }
// EventProcessor runs the loop for watching github events and tossing them over to universe func (g Source) EventProcessor(events <-chan hook.Event) { log.Printf("Starting hook event processor") for { select { case event := <-events: log.Printf("Processing event %s for repo %s ", event.Type, event.Repo) if event.Type == "create_tag" { v, err := universe.ParseVersion(event.Ref) if err != nil { log.Println("Recived 'create_tag' event with bad version: ", err) } else { rv := RepoVersion{Name: event.Repo, Org: event.Owner, Version: *v, Tag: event.Ref} go g.AddRepoRelease(rv) } } else { log.Println("event isn't a tag create, ignoring") } } } }