Skip to content

Commit

Permalink
✨ Add support for Phabricator as a code review system
Browse files Browse the repository at this point in the history
Signed-off-by: Vihang Mehta <vihang@pixielabs.ai>
  • Loading branch information
vihangm committed May 4, 2022
1 parent 74ea0f4 commit 1e2116b
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions checks/evaluation/code_review.go
Expand Up @@ -23,9 +23,10 @@ import (
)

var (
reviewPlatformGitHub = "GitHub"
reviewPlatformProw = "Prow"
reviewPlatformGerrit = "Gerrit"
reviewPlatformGitHub = "GitHub"
reviewPlatformProw = "Prow"
reviewPlatformGerrit = "Gerrit"
reviewPlatformPhabricator = "Phabricator"
)

// CodeReview applies the score policy for the Code-Review check.
Expand All @@ -42,10 +43,11 @@ func CodeReview(name string, dl checker.DetailLogger,
}

totalReviewed := map[string]int{
// The 3 platforms we support.
reviewPlatformGitHub: 0,
reviewPlatformProw: 0,
reviewPlatformGerrit: 0,
// The 4 platforms we support.
reviewPlatformGitHub: 0,
reviewPlatformProw: 0,
reviewPlatformGerrit: 0,
reviewPlatformPhabricator: 0,
}

for i := range r.DefaultBranchCommits {
Expand All @@ -64,7 +66,8 @@ func CodeReview(name string, dl checker.DetailLogger,

if totalReviewed[reviewPlatformGitHub] == 0 &&
totalReviewed[reviewPlatformGerrit] == 0 &&
totalReviewed[reviewPlatformProw] == 0 {
totalReviewed[reviewPlatformProw] == 0 &&
totalReviewed[reviewPlatformPhabricator] == 0 {
return checker.CreateMinScoreResult(name, "no reviews found")
}

Expand Down Expand Up @@ -111,6 +114,9 @@ func getApprovedReviewSystem(c *checker.DefaultBranchCommit, dl checker.DetailLo

case isReviewedOnGerrit(c, dl):
return reviewPlatformGerrit

case isReviewedOnPhabricator(c, dl):
return reviewPlatformPhabricator
}

return ""
Expand Down Expand Up @@ -187,3 +193,21 @@ func isReviewedOnGerrit(c *checker.DefaultBranchCommit, dl checker.DetailLogger)
}
return false
}

func isReviewedOnPhabricator(c *checker.DefaultBranchCommit, dl checker.DetailLogger) bool {
if isBot(c.Committer.Login) {
dl.Debug(&checker.LogMessage{
Text: fmt.Sprintf("skip commit %s from bot account: %s", c.SHA, c.Committer.Login),
})
return true
}

m := c.CommitMessage
if strings.Contains(m, "\nReviewed By: ") {
dl.Debug(&checker.LogMessage{
Text: fmt.Sprintf("commit %s was approved through %s", c.SHA, reviewPlatformPhabricator),
})
return true
}
return false
}

0 comments on commit 1e2116b

Please sign in to comment.