diff --git a/checks/code_review.go b/checks/code_review.go index 39e52bf1138..7bd3ba4cbb2 100644 --- a/checks/code_review.go +++ b/checks/code_review.go @@ -55,17 +55,37 @@ func GithubCodeReview(c checker.Checker) checker.CheckResult { continue } totalMerged++ - // Merged PR! + + // check if the PR is approved by a reviewer + foundApprovedReview := false reviews, _, err := c.Client.PullRequests.ListReviews(c.Ctx, c.Owner, c.Repo, pr.GetNumber(), &github.ListOptions{}) if err != nil { continue } for _, r := range reviews { if r.GetState() == "APPROVED" { + c.Logf("found review approved pr: %d", pr.GetNumber()) totalReviewed++ + foundApprovedReview = true break } } + + // check if the PR is committed by someone other than author. this is kind + // of equivalent to a review and is done several times on small prs to save + // time on clicking the approve button. + if !foundApprovedReview { + commit, _, err := c.Client.Repositories.GetCommit(c.Ctx, c.Owner, c.Repo, pr.GetMergeCommitSHA()) + if err == nil { + commitAuthor := commit.GetAuthor().GetLogin() + commitCommitter := commit.GetCommitter().GetLogin() + if commitAuthor != "" && commitCommitter != "" && commitAuthor != commitCommitter { + c.Logf("found pr with committer different than author: %d", pr.GetNumber()) + totalReviewed++ + } + } + } + } if totalReviewed > 0 { diff --git a/cmd/root.go b/cmd/root.go index ab39ca6bfe1..575814850a3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -113,6 +113,7 @@ type checkResult struct { CheckName string Pass bool Confidence int + Details []string } type record struct { @@ -127,11 +128,17 @@ func outputJSON(results []pkg.Result) { Repo: repo.String(), Date: d.Format("2006-01-02"), } + for _, r := range results { + var details []string + if showDetails { + details = r.Cr.Details + } or.Checks = append(or.Checks, checkResult{ CheckName: r.Name, Pass: r.Cr.Pass, Confidence: r.Cr.Confidence, + Details: details, }) } output, err := json.Marshal(or)