func (h *LGTMHandler) addLGTMIfCommented(obj *github.MungeObject, comments []*githubapi.IssueComment, reviewers mungerutil.UserSet) { // Assumption: The comments should be sorted (by default from github api) from oldest to latest for i := len(comments) - 1; i >= 0; i-- { comment := comments[i] if !mungerutil.IsValidUser(comment.User) { continue } // TODO: An approver should be acceptable. // See https://github.com/kubernetes/contrib/pull/1428#discussion_r72563935 if !mungerutil.IsMungeBot(comment.User) && !isReviewer(comment.User, reviewers) { continue } fields := getFields(*comment.Body) if isCancelComment(fields) { // "/lgtm cancel" if commented more recently than "/lgtm" return } if !isLGTMComment(fields) { continue } // TODO: support more complex policies for multiple reviewers. // See https://github.com/kubernetes/contrib/issues/1389#issuecomment-235161164 glog.Infof("Adding lgtm label. Reviewer (%s) LGTM", *comment.User.Login) obj.AddLabel(lgtmLabel) return } }
func (h *LGTMHandler) removeLGTMIfCancelled(obj *github.MungeObject, comments []*githubapi.IssueComment, reviewers mungerutil.UserSet) { for i := len(comments) - 1; i >= 0; i-- { comment := comments[i] if !mungerutil.IsValidUser(comment.User) { continue } if !mungerutil.IsMungeBot(comment.User) && !isReviewer(comment.User, reviewers) { continue } fields := getFields(*comment.Body) if isLGTMComment(fields) { // "/lgtm" if commented more recently than "/lgtm cancel" return } if !isCancelComment(fields) { continue } glog.Infof("Removing lgtm label. Reviewer (%s) cancelled", *comment.User.Login) obj.RemoveLabel(lgtmLabel) return } }
func (h *LGTMHandler) removeLGTMIfCancelled(obj *github.MungeObject, comments []*githubapi.IssueComment, events []*githubapi.IssueEvent, reviewers mungerutil.UserSet) { // Get time when the last (unlabeled, lgtm) event occurred. addLGTMTime := e.LastEvent(events, e.And{e.AddLabel{}, e.LabelName(lgtmLabel), e.HumanActor()}, nil) for i := len(comments) - 1; i >= 0; i-- { comment := comments[i] if !mungerutil.IsValidUser(comment.User) { continue } if !mungerutil.IsMungeBot(comment.User) && !isReviewer(comment.User, reviewers) { continue } fields := getFields(*comment.Body) if isLGTMComment(fields) { // "/lgtm" if commented more recently than "/lgtm cancel" return } if !isCancelComment(fields) { continue } // check if someone manually added the lgtm label after the `/lgtm cancel` comment // and honor it. if addLGTMTime != nil && addLGTMTime.After(*comment.CreatedAt) { return } glog.Infof("Removing lgtm label. Reviewer (%s) cancelled", *comment.User.Login) obj.RemoveLabel(lgtmLabel) return } }
func (h *LGTMHandler) addLGTMIfCommented(obj *github.MungeObject, comments []*githubapi.IssueComment, events []*githubapi.IssueEvent, reviewers mungerutil.UserSet) { // Get the last time when the someone applied lgtm manually. removeLGTMTime := e.LastEvent(events, e.And{e.RemoveLabel{}, e.LabelName(lgtmLabel), e.HumanActor()}, nil) // Assumption: The comments should be sorted (by default from github api) from oldest to latest for i := len(comments) - 1; i >= 0; i-- { comment := comments[i] if !mungerutil.IsValidUser(comment.User) { continue } // TODO: An approver should be acceptable. // See https://github.com/kubernetes/contrib/pull/1428#discussion_r72563935 if !mungerutil.IsMungeBot(comment.User) && !isReviewer(comment.User, reviewers) { continue } fields := getFields(*comment.Body) if isCancelComment(fields) { // "/lgtm cancel" if commented more recently than "/lgtm" return } if !isLGTMComment(fields) { continue } // check if someone manually removed the lgtm label after the `/lgtm` comment // and honor it. if removeLGTMTime != nil && removeLGTMTime.After(*comment.CreatedAt) { return } // TODO: support more complex policies for multiple reviewers. // See https://github.com/kubernetes/contrib/issues/1389#issuecomment-235161164 glog.Infof("Adding lgtm label. Reviewer (%s) LGTM", *comment.User.Login) obj.AddLabel(lgtmLabel) return } }