From 22694dcd410f3e1e17d6614b7ecd78a16d2c8aae Mon Sep 17 00:00:00 2001 From: Azeem Shaikh Date: Fri, 6 May 2022 11:41:44 -0700 Subject: [PATCH] Support commits reviewed through Piper (#1889) Co-authored-by: Azeem Shaikh --- checks/code_review_test.go | 15 +++++++++++++++ checks/evaluation/code_review.go | 24 +++++++++++++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/checks/code_review_test.go b/checks/code_review_test.go index 5080f7c2..26c8de7a 100644 --- a/checks/code_review_test.go +++ b/checks/code_review_test.go @@ -232,6 +232,21 @@ func TestCodereview(t *testing.T) { Score: 0, }, }, + { + name: "Valid piper commit", + commits: []clients.Commit{ + { + SHA: "sha", + Committer: clients.User{ + Login: "", + }, + Message: "Title\nPiperOrigin-RevId: 444529962", + }, + }, + expected: checker.CheckResult{ + Score: 10, + }, + }, } for _, tt := range tests { diff --git a/checks/evaluation/code_review.go b/checks/evaluation/code_review.go index 7b72de44..258bd637 100644 --- a/checks/evaluation/code_review.go +++ b/checks/evaluation/code_review.go @@ -22,11 +22,12 @@ import ( sce "github.com/ossf/scorecard/v4/errors" ) -var ( +const ( reviewPlatformGitHub = "GitHub" reviewPlatformProw = "Prow" reviewPlatformGerrit = "Gerrit" reviewPlatformPhabricator = "Phabricator" + reviewPlatformPiper = "Piper" ) // CodeReview applies the score policy for the Code-Review check. @@ -43,11 +44,11 @@ func CodeReview(name string, dl checker.DetailLogger, } totalReviewed := map[string]int{ - // The 4 platforms we support. reviewPlatformGitHub: 0, reviewPlatformProw: 0, reviewPlatformGerrit: 0, reviewPlatformPhabricator: 0, + reviewPlatformPiper: 0, } for i := range r.DefaultBranchCommits { @@ -67,7 +68,7 @@ func CodeReview(name string, dl checker.DetailLogger, if totalReviewed[reviewPlatformGitHub] == 0 && totalReviewed[reviewPlatformGerrit] == 0 && totalReviewed[reviewPlatformProw] == 0 && - totalReviewed[reviewPlatformPhabricator] == 0 { + totalReviewed[reviewPlatformPhabricator] == 0 && totalReviewed[reviewPlatformPiper] == 0 { return checker.CreateMinScoreResult(name, "no reviews found") } @@ -108,17 +109,15 @@ func getApprovedReviewSystem(c *checker.DefaultBranchCommit, dl checker.DetailLo switch { case isReviewedOnGitHub(c, dl): return reviewPlatformGitHub - case isReviewedOnProw(c, dl): return reviewPlatformProw - case isReviewedOnGerrit(c, dl): return reviewPlatformGerrit - case isReviewedOnPhabricator(c, dl): return reviewPlatformPhabricator + case isReviewedOnPiper(c, dl): + return reviewPlatformPiper } - return "" } @@ -212,3 +211,14 @@ func isReviewedOnPhabricator(c *checker.DefaultBranchCommit, dl checker.DetailLo } return false } + +func isReviewedOnPiper(c *checker.DefaultBranchCommit, dl checker.DetailLogger) bool { + m := c.CommitMessage + if strings.Contains(m, "\nPiperOrigin-RevId: ") { + dl.Debug(&checker.LogMessage{ + Text: fmt.Sprintf("commit %s was approved through %s", c.SHA, reviewPlatformPhabricator), + }) + return true + } + return false +}