2020-10-12 22:04:43 +03:00
|
|
|
package checks
|
|
|
|
|
|
|
|
import (
|
2020-10-17 02:11:07 +03:00
|
|
|
"strings"
|
|
|
|
|
2020-10-12 22:04:43 +03:00
|
|
|
"github.com/dlorenc/scorecard/checker"
|
|
|
|
"github.com/google/go-github/v32/github"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2020-10-16 21:22:28 +03:00
|
|
|
registerCheck("Pull-Requests", PullRequests)
|
2020-10-12 22:04:43 +03:00
|
|
|
}
|
|
|
|
|
2020-10-13 18:35:55 +03:00
|
|
|
func PullRequests(c checker.Checker) checker.CheckResult {
|
2020-10-12 22:04:43 +03:00
|
|
|
commits, _, err := c.Client.Repositories.ListCommits(c.Ctx, c.Owner, c.Repo, &github.CommitsListOptions{})
|
|
|
|
if err != nil {
|
2020-10-13 18:35:55 +03:00
|
|
|
return checker.RetryResult(err)
|
2020-10-12 22:04:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
total := 0
|
|
|
|
totalWithPrs := 0
|
|
|
|
for _, commit := range commits {
|
2020-10-17 02:11:07 +03:00
|
|
|
isBot := false
|
|
|
|
committer := commit.GetCommitter().GetLogin()
|
|
|
|
for _, substring := range []string{"bot", "gardener"} {
|
|
|
|
if strings.Contains(committer, substring) {
|
|
|
|
isBot = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if isBot {
|
|
|
|
c.Logf("skip commit from bot account: %s", committer)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-10-12 22:04:43 +03:00
|
|
|
prs, _, err := c.Client.PullRequests.ListPullRequestsWithCommit(c.Ctx, c.Owner, c.Repo, commit.GetSHA(), &github.PullRequestListOptions{})
|
|
|
|
if err != nil {
|
2020-10-13 18:35:55 +03:00
|
|
|
return checker.RetryResult(err)
|
2020-10-12 22:04:43 +03:00
|
|
|
}
|
|
|
|
total++
|
|
|
|
if len(prs) > 0 {
|
2020-10-17 02:11:07 +03:00
|
|
|
c.Logf("found PRs, example: #%v", prs[0].GetNumber())
|
2020-10-12 22:04:43 +03:00
|
|
|
totalWithPrs++
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 02:11:07 +03:00
|
|
|
return checker.ProportionalResult(totalWithPrs, total, .75)
|
2020-10-12 22:04:43 +03:00
|
|
|
}
|