Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Support commits reviewed through Piper #1889

Merged
merged 1 commit into from May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions checks/code_review_test.go
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
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
}