2020-10-12 22:04:43 +03:00
|
|
|
package checks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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 {
|
|
|
|
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 {
|
|
|
|
totalWithPrs++
|
|
|
|
}
|
|
|
|
}
|
2020-10-13 18:35:55 +03:00
|
|
|
return checker.ProportionalResult(totalWithPrs, total, .9)
|
2020-10-12 22:04:43 +03:00
|
|
|
}
|