// Munge is the workhorse the will actually make updates to the PR func (h LGTMHandler) Munge(obj *github.MungeObject) { if !obj.IsPR() { return } reviewers := getReviewers(obj) if len(reviewers) == 0 { return } comments, err := getCommentsAfterLastModified(obj) if err != nil { glog.Errorf("unexpected error getting comments: %v", err) return } events, err := obj.GetEvents() if err != nil { glog.Errorf("unexpected error getting events: %v", err) return } if !obj.HasLabel(lgtmLabel) { h.addLGTMIfCommented(obj, comments, events, reviewers) return } h.removeLGTMIfCancelled(obj, comments, events, reviewers) }
func getHumanCorrectedLabel(obj *github.MungeObject, s string) *string { myEvents, err := obj.GetEvents() if err != nil { glog.Errorf("Could not get the events associated with Issue %d", obj.Issue.Number) return nil } botEvents := event.FilterEvents(myEvents, event.And([]event.Matcher{event.BotActor(), event.AddLabel{}, event.LabelPrefix(s)})) if botEvents.Empty() { return nil } humanEventsAfter := event.FilterEvents( myEvents, event.And([]event.Matcher{ event.HumanActor(), event.AddLabel{}, event.LabelPrefix(s), event.CreatedAfter(*botEvents.GetLast().CreatedAt), }), ) if humanEventsAfter.Empty() { return nil } lastHumanLabel := humanEventsAfter.GetLast() glog.Infof("Recopying human-added label: %s for PR %d", *lastHumanLabel.Label.Name, *obj.Issue.Number) obj.RemoveLabel(*lastHumanLabel.Label.Name) obj.AddLabel(*lastHumanLabel.Label.Name) return lastHumanLabel.Label.Name }
func findLastInterestingEventUpdate(obj *github.MungeObject) (*time.Time, error) { lastInteresting := obj.Issue.CreatedAt events, err := obj.GetEvents() if err != nil { return nil, err } for i := range events { event := events[i] if event.Event == nil || *event.Event != "reopened" { continue } if lastInteresting.Before(*event.CreatedAt) { lastInteresting = event.CreatedAt } } return lastInteresting, nil }