scorecard/checks/prs.go

32 lines
774 B
Go
Raw Normal View History

package checks
import (
"github.com/dlorenc/scorecard/checker"
"github.com/google/go-github/v32/github"
)
func init() {
2020-10-13 22:43:12 +03:00
registerCheck("PullRequests", PullRequests)
}
func PullRequests(c checker.Checker) checker.CheckResult {
commits, _, err := c.Client.Repositories.ListCommits(c.Ctx, c.Owner, c.Repo, &github.CommitsListOptions{})
if err != nil {
return checker.RetryResult(err)
}
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 {
return checker.RetryResult(err)
}
total++
if len(prs) > 0 {
totalWithPrs++
}
}
return checker.ProportionalResult(totalWithPrs, total, .9)
}