本文整理匯總了Golang中k8s/io/contrib/mungegithub/config.MungeConfig.AssignPR方法的典型用法代碼示例。如果您正苦於以下問題:Golang MungeConfig.AssignPR方法的具體用法?Golang MungeConfig.AssignPR怎麽用?Golang MungeConfig.AssignPR使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/contrib/mungegithub/config.MungeConfig
的用法示例。
在下文中一共展示了MungeConfig.AssignPR方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MungePullRequest
func (b *BlunderbussMunger) MungePullRequest(config *config.MungeConfig, pr *github.PullRequest, issue *github.Issue, commits []github.RepositoryCommit, events []github.IssueEvent) {
if b.config == nil {
b.loadConfig()
}
if !b.blunderbussReassign && issue.Assignee != nil {
glog.V(6).Infof("skipping %v: reassign: %v assignee: %v", *pr.Number, b.blunderbussReassign, describeUser(issue.Assignee))
return
}
potentialOwners := weightMap{}
weightSum := int64(0)
for _, commit := range commits {
if commit.Author == nil || commit.Author.Login == nil || commit.SHA == nil {
glog.Warningf("Skipping invalid commit for %d: %#v", *pr.Number, commit)
continue
}
for _, file := range commit.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.config.FindOwners(*file.Filename)
if len(fileOwners) == 0 {
glog.Warningf("Couldn't find an owner for: %s", *file.Filename)
}
for owner, ownerWeight := range fileOwners {
if owner == *pr.User.Login {
continue
}
potentialOwners[owner] = potentialOwners[owner] + fileWeight*ownerWeight
weightSum += fileWeight * ownerWeight
}
}
}
if len(potentialOwners) == 0 {
glog.Errorf("No owners found for PR %d", *pr.Number)
return
}
glog.V(4).Infof("Weights: %#v\nSum: %v", potentialOwners, weightSum)
if issue.Assignee != nil {
cur := *issue.Assignee.Login
glog.Infof("Current assignee %v has a %02.2f%% chance of having been chosen", cur, 100.0*float64(potentialOwners[cur])/float64(weightSum))
}
selection := rand.Int63n(weightSum)
owner := ""
for o, w := range potentialOwners {
owner = o
selection -= w
if selection <= 0 {
break
}
}
glog.Infof("Assigning %v to %v (previously assigned to %v)", *pr.Number, owner, describeUser(issue.Assignee))
config.AssignPR(*pr.Number, owner)
}