Improve code review check to account for diff author-committer usecase.

See
$ go run . --repo=https://github.com/protocolbuffers/protobuf --show-details --checks=Code-Review
Starting [Code-Review]
Finished [Code-Review]

RESULTS
-------
Code-Review: Pass 9
    found different author and committer for pr: 8053
    found different author and committer for pr: 8052
    found review approved pr: 8048
    found review approved pr: 8045
    found different author and committer for pr: 8043
    found review approved pr: 8035
    found review approved pr: 8032
    found review approved pr: 8030
    found review approved pr: 8029
    found review approved pr: 8028
    found review approved pr: 8026
    found review approved pr: 8025
    found review approved pr: 8024
    found review approved pr: 8023
    found review approved pr: 8022
    found different author and committer for pr: 8014
    found different author and committer for pr: 8013
    found review approved pr: 8011
    found review approved pr: 8010
    found review approved pr: 8006
    found review approved pr: 8005
    found different author and committer for pr: 8003
    found review approved pr: 8000
    found different author and committer for pr: 7997
    github code reviews found
This commit is contained in:
Abhishek Arya 2020-11-20 13:21:59 -08:00
parent c3c5bc8060
commit 3379ada1d5

View File

@ -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 different author and committer for pr: %d", pr.GetNumber())
totalReviewed++
}
}
}
}
if totalReviewed > 0 {