Ejemplo n.º 1
0
// StaleComments returns a slice of stale comments
func (NagFlakeIssues) StaleComments(obj *mgh.MungeObject, comments []*github.IssueComment) []*github.IssueComment {
	// Remove all pings written before the last human actor comment
	return c.FilterComments(comments, c.And([]c.Matcher{
		c.MungerNotificationName(flakeNagNotifyName),
		c.CreatedBefore(*c.LastComment(comments, c.HumanActor(), &time.Time{})),
	}))
}
Ejemplo n.º 2
0
// Munge is the workhorse the will actually make updates to the PR
func (NagFlakeIssues) Munge(obj *mgh.MungeObject) {
	if obj.IsPR() || !obj.HasLabel("kind/flake") {
		return
	}

	comments, err := obj.ListComments()
	if err != nil {
		glog.Error(err)
		return
	}

	// Use the pinger to notify assignees:
	// - Set time period based on configuration (at the top of this file)
	// - Mention list of assignees as an argument
	// - Start the ping timer after the last HumanActor comment

	// How often should we ping
	period := findTimePeriod(obj.Issue.Labels)

	// Who are we pinging
	who := mungerutil.GetIssueUsers(obj.Issue).Assignees.Mention().Join()

	// When does the pinger start
	startDate := c.LastComment(comments, c.HumanActor(), obj.Issue.CreatedAt)

	// Get a notification if it's time to ping.
	notif := pinger.SetTimePeriod(period).PingNotification(
		comments,
		who,
		startDate,
	)
	if notif != nil {
		obj.WriteComment(notif.String())
	}
}
Ejemplo n.º 3
0
func getLastReviewerComment(obj *github.MungeObject, comments []*githubapi.IssueComment) *time.Time {
	var lastCommentTime *time.Time
	for _, reviewer := range obj.Issue.Assignees {
		lastReviewerCommentTime := comment.LastComment(comments, comment.Author(*reviewer), nil)
		if lastReviewerCommentTime == nil {
			continue
		}
		if lastCommentTime != nil && lastReviewerCommentTime.Before(*lastCommentTime) {
			continue
		}
		lastCommentTime = lastReviewerCommentTime
	}
	return lastCommentTime
}
Ejemplo n.º 4
0
// assigneeActionNeeded returns true if we are waiting on an action from the reviewer.
func isReviewerActionNeeded(obj *github.MungeObject) (bool, error) {
	comments, err := obj.ListComments()
	if err != nil {
		return false, err
	}

	lastAuthorCommentTime := comment.LastComment(comments, comment.Author(*obj.Issue.User), nil)
	lastReviewerCommentTime := getLastReviewerComment(obj, comments)

	if lastReviewerCommentTime == nil {
		// this implies that no reviewer has commented on the PR yet.
		return true, nil
	}

	if obj.LastModifiedTime().After(*lastReviewerCommentTime) {
		return true, nil
	}

	if lastAuthorCommentTime == nil {
		return false, nil
	}

	return lastReviewerCommentTime.Before(*lastAuthorCommentTime), nil
}