Skip to content

Commit

Permalink
Support commits reviewed through Piper
Browse files Browse the repository at this point in the history
  • Loading branch information
azeemsgoogle committed May 6, 2022
1 parent 9a7d030 commit 71404a4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
15 changes: 15 additions & 0 deletions checks/code_review_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 17 additions & 7 deletions checks/evaluation/code_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand All @@ -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")
}

Expand Down Expand Up @@ -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 ""
}

Expand Down Expand Up @@ -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
}

0 comments on commit 71404a4

Please sign in to comment.