mirror of
https://github.com/ossf/scorecard.git
synced 2024-09-11 00:45:36 +03:00
Support commits reviewed through Piper (#1889)
Co-authored-by: Azeem Shaikh <azeems@google.com>
This commit is contained in:
parent
9a7d030902
commit
22694dcd41
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user