Support commits reviewed through Piper (#1889)

Co-authored-by: Azeem Shaikh <azeems@google.com>
This commit is contained in:
Azeem Shaikh 2022-05-06 11:41:44 -07:00 committed by GitHub
parent 9a7d030902
commit 22694dcd41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 7 deletions

View File

@ -232,6 +232,21 @@ func TestCodereview(t *testing.T) {
Score: 0, 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 { for _, tt := range tests {

View File

@ -22,11 +22,12 @@ import (
sce "github.com/ossf/scorecard/v4/errors" sce "github.com/ossf/scorecard/v4/errors"
) )
var ( const (
reviewPlatformGitHub = "GitHub" reviewPlatformGitHub = "GitHub"
reviewPlatformProw = "Prow" reviewPlatformProw = "Prow"
reviewPlatformGerrit = "Gerrit" reviewPlatformGerrit = "Gerrit"
reviewPlatformPhabricator = "Phabricator" reviewPlatformPhabricator = "Phabricator"
reviewPlatformPiper = "Piper"
) )
// CodeReview applies the score policy for the Code-Review check. // 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{ totalReviewed := map[string]int{
// The 4 platforms we support.
reviewPlatformGitHub: 0, reviewPlatformGitHub: 0,
reviewPlatformProw: 0, reviewPlatformProw: 0,
reviewPlatformGerrit: 0, reviewPlatformGerrit: 0,
reviewPlatformPhabricator: 0, reviewPlatformPhabricator: 0,
reviewPlatformPiper: 0,
} }
for i := range r.DefaultBranchCommits { for i := range r.DefaultBranchCommits {
@ -67,7 +68,7 @@ func CodeReview(name string, dl checker.DetailLogger,
if totalReviewed[reviewPlatformGitHub] == 0 && if totalReviewed[reviewPlatformGitHub] == 0 &&
totalReviewed[reviewPlatformGerrit] == 0 && totalReviewed[reviewPlatformGerrit] == 0 &&
totalReviewed[reviewPlatformProw] == 0 && totalReviewed[reviewPlatformProw] == 0 &&
totalReviewed[reviewPlatformPhabricator] == 0 { totalReviewed[reviewPlatformPhabricator] == 0 && totalReviewed[reviewPlatformPiper] == 0 {
return checker.CreateMinScoreResult(name, "no reviews found") return checker.CreateMinScoreResult(name, "no reviews found")
} }
@ -108,17 +109,15 @@ func getApprovedReviewSystem(c *checker.DefaultBranchCommit, dl checker.DetailLo
switch { switch {
case isReviewedOnGitHub(c, dl): case isReviewedOnGitHub(c, dl):
return reviewPlatformGitHub return reviewPlatformGitHub
case isReviewedOnProw(c, dl): case isReviewedOnProw(c, dl):
return reviewPlatformProw return reviewPlatformProw
case isReviewedOnGerrit(c, dl): case isReviewedOnGerrit(c, dl):
return reviewPlatformGerrit return reviewPlatformGerrit
case isReviewedOnPhabricator(c, dl): case isReviewedOnPhabricator(c, dl):
return reviewPlatformPhabricator return reviewPlatformPhabricator
case isReviewedOnPiper(c, dl):
return reviewPlatformPiper
} }
return "" return ""
} }
@ -212,3 +211,14 @@ func isReviewedOnPhabricator(c *checker.DefaultBranchCommit, dl checker.DetailLo
} }
return false 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
}