Skip to content

Commit

Permalink
fix: getFirstReviewToLastReview should use non-author approvals for e…
Browse files Browse the repository at this point in the history
…nd review
  • Loading branch information
jack-michaud authored and hectcastro committed Apr 11, 2022
1 parent 2890d24 commit 82cb2e1
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cmd/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,29 @@ func (ui *UI) getFeatureLeadTime(prMergedAtString string, commits Commits) strin
return formatDuration(ui.subtractTime(prMergedAt, prFirstCommittedAt))
}

// getFirstReviewToLastReview returns the first review to last review time, in
// getFirstReviewToLastReview returns the first review to last approving review time, in
// hours and minutes, for a given PR.
//
// firstReviewToLastReview = lastReviewedAt - firstReviewedAt
//
func (ui *UI) getFirstReviewToLastReview(login string, reviews Reviews) string {
var nonAuthorReviews ReviewNodes
for _, review := range reviews.Nodes {
if review.Author.Login != login {
firstReviewedAt, _ := time.Parse(time.RFC3339, review.CreatedAt)
lastReviewedAt, _ := time.Parse(time.RFC3339, reviews.Nodes[len(reviews.Nodes)-1].CreatedAt)
nonAuthorReviews = append(nonAuthorReviews, review)
}
}

if len(nonAuthorReviews) == 0 {
return DefaultEmptyCell
}

firstReviewedAt, _ := time.Parse(time.RFC3339, nonAuthorReviews[0].CreatedAt)

// Iterate in reverse order to get the last approving review
for i := len(nonAuthorReviews) - 1; i >= 0; i-- {
if nonAuthorReviews[i].State == ReviewApprovedState {
lastReviewedAt, _ := time.Parse(time.RFC3339, nonAuthorReviews[i].CreatedAt)
return formatDuration(ui.subtractTime(lastReviewedAt, firstReviewedAt))
}
}
Expand Down

0 comments on commit 82cb2e1

Please sign in to comment.