// Munge is the workhorse the will actually make updates to the PR func (s *SizeMunger) Munge(obj *github.MungeObject) { if !obj.IsPR() { return } issue := obj.Issue s.getGeneratedFiles(obj) genFiles := *s.genFiles genPrefixes := *s.genPrefixes files, err := obj.ListFiles() if err != nil { return } adds := 0 dels := 0 for _, f := range files { skip := false for _, p := range genPrefixes { if strings.HasPrefix(*f.Filename, p) { skip = true break } } if skip { continue } if genFiles.Has(*f.Filename) { continue } if f.Additions != nil { adds += *f.Additions } if f.Deletions != nil { dels += *f.Deletions } } newSize := calculateSize(adds, dels) newLabel := labelSizePrefix + newSize existing := github.GetLabelsWithPrefix(issue.Labels, labelSizePrefix) needsUpdate := true for _, l := range existing { if l == newLabel { needsUpdate = false continue } obj.RemoveLabel(l) } if needsUpdate { obj.AddLabels([]string{newLabel}) body := fmt.Sprintf("Labelling this PR as %s", newLabel) obj.WriteComment(body) } }
func gatherData(cfg *githubhelper.Config) (*reportData, error) { issues, err := cfg.ListAllIssues(&github.IssueListByRepoOptions{ State: "open", Sort: "created", Labels: []string{"kind/flake"}, }) if err != nil { return nil, err } r := reportData{ loginToEmail: map[string]string{}, loginToIssues: map[string][]issueReportData{}, } for _, issue := range issues { assignee := "UNASSIGNED" if issue.Assignee != nil && issue.Assignee.Login != nil { assignee = *issue.Assignee.Login if _, ok := r.loginToEmail[assignee]; !ok { if u, err := cfg.GetUser(assignee); err == nil { if u.Email != nil { r.loginToEmail[assignee] = *u.Email } else { // Don't keep looking this up r.loginToEmail[assignee] = "" } } } } age := time.Duration(0) if issue.CreatedAt != nil { age = time.Now().Sub(*issue.CreatedAt) } priority := "??" priorityLabels := githubhelper.GetLabelsWithPrefix(issue.Labels, "priority/") if len(priorityLabels) == 1 { priority = strings.TrimPrefix(priorityLabels[0], "priority/") } if priority == "P2" || priority == "P3" { r.lowPriorityTests++ continue } reportData := issueReportData{ priority: priority, number: *issue.Number, title: *issue.Title, age: age, } r.loginToIssues[assignee] = append(r.loginToIssues[assignee], reportData) if priority == "??" { const unprioritized = "UNPRIORITIZED" r.loginToIssues[unprioritized] = append(r.loginToIssues[unprioritized], reportData) } r.totalTests++ } return &r, nil }
// Munge is the workhorse the will actually make updates to the PR func (s *LabelMunger) Munge(obj *github.MungeObject) { //this munger only works on issues if obj.IsPR() { return } issue := obj.Issue if obj.HasLabel("kind/flake") { return } tLabels := github.GetLabelsWithPrefix(issue.Labels, "team/") if len(tLabels) != 0 { //already labeled return } cLabels := github.GetLabelsWithPrefix(issue.Labels, "component/") if len(cLabels) != 0 { //already labeled return } routingLabelsToApply, err := http.PostForm("http://issue-triager-service:5000", url.Values{"title": {*issue.Title}, "body": {*issue.Body}}) if err != nil { //handle the error glog.Error(err) return } defer routingLabelsToApply.Body.Close() response, err := ioutil.ReadAll(routingLabelsToApply.Body) if routingLabelsToApply.StatusCode != 200 { glog.Errorf("%d: %s", routingLabelsToApply.StatusCode, response) return } obj.AddLabels(strings.Split(string(response), ",")) }
// findTimePeriod returns how often we should ping based on priority func findTimePeriod(labels []github.Label) time.Duration { priorities := mgh.GetLabelsWithPrefix(labels, "priority/") if len(priorities) == 0 { return defaultTimePeriod } // If we have multiple priority labels (shouldn't happen), use the first one period, ok := timePeriods[priorities[0]] if !ok { return defaultTimePeriod } return period }
// Munge is the workhorse the will actually make updates to the PR func (lm *LabelMunger) Munge(obj *github.MungeObject) { //this munger only works on issues if obj.IsPR() { return } if obj.HasLabel("kind/flake") { return } tLabels := github.GetLabelsWithPrefix(obj.Issue.Labels, "team/") cLabels := github.GetLabelsWithPrefix(obj.Issue.Labels, "component/") if len(tLabels) == 0 && len(cLabels) == 0 { obj.AddLabels(getRoutingLabels(lm.TriagerUrl, obj.Issue.Title, obj.Issue.Body)) } else { newLabels := needsUpdate(obj) if len(newLabels) != 0 { updateModel(lm.TriagerUrl, obj.Issue.Title, obj.Issue.Body, newLabels) } } }
// MungePullRequest is the workhorse the will actually make updates to the PR func (s *SizeMunger) MungePullRequest(config *github_util.Config, pr *github.PullRequest, issue *github.Issue, commits []github.RepositoryCommit, events []github.IssueEvent) { s.getGeneratedFiles(config) genFiles := *s.genFiles genPrefixes := *s.genPrefixes if pr.Additions == nil { glog.Warningf("PR %d has nil Additions", *pr.Number) return } adds := *pr.Additions if pr.Deletions == nil { glog.Warningf("PR %d has nil Deletions", *pr.Number) return } dels := *pr.Deletions for _, c := range commits { for _, f := range c.Files { for _, p := range genPrefixes { if strings.HasPrefix(*f.Filename, p) { adds = adds - *f.Additions dels = dels - *f.Deletions continue } } if genFiles.Has(*f.Filename) { adds = adds - *f.Additions dels = dels - *f.Deletions continue } } } newSize := calculateSize(adds, dels) newLabel := labelSizePrefix + newSize existing := github_util.GetLabelsWithPrefix(issue.Labels, labelSizePrefix) needsUpdate := true for _, l := range existing { if l == newLabel { needsUpdate = false continue } config.RemoveLabel(*pr.Number, l) } if needsUpdate { config.AddLabels(*pr.Number, []string{newLabel}) body := fmt.Sprintf("Labelling this PR as %s", newLabel) config.WriteComment(*pr.Number, body) } }
// syncPriority will sync the input priority to the issue if the input priority is higher than the existing ones func (s *IssueSyncer) syncPriority(obj *github.MungeObject, priority Priority) error { if obj.Priority() <= priority.Priority() { return nil } plabels := github.GetLabelsWithPrefix(obj.Issue.Labels, priorityPrefix) err := obj.AddLabel(priority.String()) if err != nil { return nil } for _, l := range plabels { err = obj.RemoveLabel(l) if err != nil { return err } } return nil }
// Munge is the workhorse the will actually make updates to the PR func (s *SizeMunger) Munge(obj *github.MungeObject) { if !obj.IsPR() { return } issue := obj.Issue pr, err := obj.GetPR() if err != nil { return } s.getGeneratedFiles(obj) genFiles := *s.genFiles genPrefixes := *s.genPrefixes if pr.Additions == nil { glog.Warningf("PR %d has nil Additions", *pr.Number) return } adds := *pr.Additions if pr.Deletions == nil { glog.Warningf("PR %d has nil Deletions", *pr.Number) return } dels := *pr.Deletions commits, err := obj.GetCommits() if err != nil { return } for _, c := range commits { for _, f := range c.Files { for _, p := range genPrefixes { if strings.HasPrefix(*f.Filename, p) { adds = adds - *f.Additions dels = dels - *f.Deletions continue } } if genFiles.Has(*f.Filename) { adds = adds - *f.Additions dels = dels - *f.Deletions continue } } } newSize := calculateSize(adds, dels) newLabel := labelSizePrefix + newSize existing := github.GetLabelsWithPrefix(issue.Labels, labelSizePrefix) needsUpdate := true for _, l := range existing { if l == newLabel { needsUpdate = false continue } obj.RemoveLabel(l) } if needsUpdate { obj.AddLabels([]string{newLabel}) body := fmt.Sprintf("Labelling this PR as %s", newLabel) obj.WriteComment(body) } }