// Munge is the workhorse the will actually make updates to the PR func (a *AssignFixesMunger) Munge(obj *github.MungeObject) { if !obj.IsPR() { return } // we need the PR for the "User" (creator of the PR not the assignee) pr, err := obj.GetPR() if err != nil { glog.Infof("Couldn't get PR %v", obj.Issue.Number) return } prOwner := github.DescribeUser(pr.User) issuesFixed := obj.GetPRFixesList() if issuesFixed == nil { return } for _, fixesNum := range issuesFixed { // "issue" is the issue referenced by the "fixes #<num>" issueObj, err := a.config.GetObject(fixesNum) if err != nil { glog.Infof("Couldn't get issue %v", fixesNum) continue } issue := issueObj.Issue if !a.AssignfixesReassign && issue.Assignee != nil { glog.V(6).Infof("skipping %v: reassign: %v assignee: %v", *issue.Number, a.AssignfixesReassign, github.DescribeUser(issue.Assignee)) continue } glog.Infof("Assigning %v to %v (previously assigned to %v)", *issue.Number, prOwner, github.DescribeUser(issue.Assignee)) // although it says "AssignPR" it's more generic than that and is really just an issue. issueObj.AssignPR(prOwner) } }
func findLastHumanPullRequestUpdate(obj *github.MungeObject) (*time.Time, error) { pr, err := obj.GetPR() if err != nil { return nil, err } comments, err := obj.ListReviewComments() if err != nil { return nil, err } lastHuman := pr.CreatedAt for i := range comments { comment := comments[i] if comment.User == nil || comment.User.Login == nil || comment.CreatedAt == nil || comment.Body == nil { continue } if *comment.User.Login == botName || *comment.User.Login == jenkinsBotName { continue } if lastHuman.Before(*comment.UpdatedAt) { lastHuman = comment.UpdatedAt } } return lastHuman, nil }
// Munge is the workhorse the will actually make updates to the PR func (c *CherrypickQueue) Munge(obj *github.MungeObject) { if !obj.HasLabel(cpCandidateLabel) { return } if !obj.IsPR() { return } // This will cache the PR and events so when we try to view the queue we don't // hit github while trying to load the page obj.GetPR() num := *obj.Issue.Number c.Lock() merged, _ := obj.IsMerged() if merged { if obj.HasLabel(cpApprovedLabel) { c.mergedAndApproved[num] = obj } else { c.merged[num] = obj } } else { c.unmerged[num] = obj } c.Unlock() return }
func objToStatusPullRequest(obj *github.MungeObject) *statusPullRequest { if obj == nil { return &statusPullRequest{} } res := statusPullRequest{ Number: *obj.Issue.Number, URL: *obj.Issue.HTMLURL, Title: *obj.Issue.Title, Login: *obj.Issue.User.Login, AvatarURL: *obj.Issue.User.AvatarURL, } pr, err := obj.GetPR() if err != nil { return &res } if pr.Additions != nil { res.Additions = *pr.Additions } if pr.Deletions != nil { res.Deletions = *pr.Deletions } prio, ok := obj.Annotations["priority"] if !ok { var prio string p := priority(obj) if p == retestNotRequiredMergePriority { prio = retestNotRequiredLabel } else { prio = fmt.Sprintf("P%d", p) // store it a P1, P2, P3. Not just 1,2,3 } obj.Annotations["priority"] = prio } if prio != "" { res.ExtraInfo = append(res.ExtraInfo, prio) } milestone, ok := obj.Annotations["milestone"] if !ok { milestone = obj.ReleaseMilestone() obj.Annotations["milestone"] = milestone } if milestone != "" { res.ExtraInfo = append(res.ExtraInfo, milestone) } return &res }
// 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) } }