// 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) } }
// Munge is the workhorse the will actually make updates to the PR func (b *BlunderbussMunger) Munge(obj *github.MungeObject) { if !obj.IsPR() { return } issue := obj.Issue if !b.BlunderbussReassign && issue.Assignee != nil { glog.V(6).Infof("skipping %v: reassign: %v assignee: %v", *issue.Number, b.BlunderbussReassign, github.DescribeUser(issue.Assignee)) return } files, err := obj.ListFiles() if err != nil { return } potentialOwners, weightSum := getPotentialOwners(*obj.Issue.User.Login, b.features, files, true) if len(potentialOwners) == 0 { potentialOwners, weightSum = getPotentialOwners(*obj.Issue.User.Login, b.features, files, false) if len(potentialOwners) == 0 { glog.Errorf("No OWNERS found for PR %d", *issue.Number) return } } printChance(potentialOwners, weightSum) if issue.Assignee != nil { cur := *issue.Assignee.Login c := chance(potentialOwners[cur], weightSum) glog.Infof("Current assignee %v has a %02.2f%% chance of having been chosen", cur, c) } selection := rand.Int63n(weightSum) owner := "" for o, w := range potentialOwners { owner = o selection -= w if selection <= 0 { break } } c := chance(potentialOwners[owner], weightSum) glog.Infof("Assigning %v to %v who had a %02.2f%% chance to be assigned (previously assigned to %v)", *issue.Number, owner, c, github.DescribeUser(issue.Assignee)) obj.AssignPR(owner) }
// Munge is the workhorse the will actually make updates to the PR func (b *BlunderbussMunger) Munge(obj *github.MungeObject) { if !obj.IsPR() { return } issue := obj.Issue if !b.BlunderbussReassign && issue.Assignee != nil { glog.V(6).Infof("skipping %v: reassign: %v assignee: %v", *issue.Number, b.BlunderbussReassign, github.DescribeUser(issue.Assignee)) return } files, err := obj.ListFiles() if err != nil { return } potentialOwners := weightMap{} weightSum := int64(0) for _, file := range files { fileWeight := int64(1) if file.Changes != nil && *file.Changes != 0 { fileWeight = int64(*file.Changes) } // Judge file size on a log scale-- effectively this // makes three buckets, we shouldn't have many 10k+ // line changes. fileWeight = int64(math.Log10(float64(fileWeight))) + 1 fileOwners := b.features.Repos.LeafAssignees(*file.Filename) if fileOwners.Len() == 0 { glog.Warningf("Couldn't find an owner for: %s", *file.Filename) } if b.features.Aliases != nil && b.features.Aliases.IsEnabled { fileOwners = b.features.Aliases.Expand(fileOwners) } for _, owner := range fileOwners.List() { if owner == *issue.User.Login { continue } potentialOwners[owner] = potentialOwners[owner] + fileWeight weightSum += fileWeight } } if len(potentialOwners) == 0 { glog.Errorf("No owners found for PR %d", *issue.Number) return } printChance(potentialOwners, weightSum) if issue.Assignee != nil { cur := *issue.Assignee.Login c := chance(potentialOwners[cur], weightSum) glog.Infof("Current assignee %v has a %02.2f%% chance of having been chosen", cur, c) } selection := rand.Int63n(weightSum) owner := "" for o, w := range potentialOwners { owner = o selection -= w if selection <= 0 { break } } c := chance(potentialOwners[owner], weightSum) glog.Infof("Assigning %v to %v who had a %02.2f%% chance to be assigned (previously assigned to %v)", *issue.Number, owner, c, github.DescribeUser(issue.Assignee)) obj.AssignPR(owner) }