scorecard/checks/ci_tests.go

167 lines
4.4 KiB
Go
Raw Normal View History

// Copyright 2020 Security Scorecard Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2020-10-09 17:47:59 +03:00
package checks
import (
"fmt"
2020-10-09 17:47:59 +03:00
"strings"
2022-01-12 22:49:01 +03:00
"github.com/ossf/scorecard/v4/checker"
"github.com/ossf/scorecard/v4/clients"
sce "github.com/ossf/scorecard/v4/errors"
2020-10-09 17:47:59 +03:00
)
const (
// CheckCITests is the registered name for CITests.
CI-Test: stop assuming either "statuses" or "check runs" are used (#1259) Projects with a lot of different CI services use both and the check should take that into account so as not to report that PRs like https://github.com/systemd/systemd/pull/21329 with 28 successful, 4 failing, and 2 neutral checks were merged without any tests. Without this patch `scorecard` says that 5 out 30 PRs were merged without running tests: ``` "Debug: CI test found: pr: 21299, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/472a52d22b9f505a4c284e7ad020ea1b3728466d", "Debug: CI test found: pr: 21300, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/cf35602cbc1bffcb5ab01153af153d0bf4e5a7e9", "Debug: CI test found: pr: 21301, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/13b7b8bd7362d198e123a67b8dfdc1c558df5b21", "Debug: CI test found: pr: 21302, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/dfa4876c417e2a9935d58100d44d94bb41cd5bfb", "Debug: CI test found: pr: 21304, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/01f6c450b655a8ce233cb5feeaddb4ec8a5610f7", "Debug: CI test found: pr: 21305, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/547f97d5714b6e1efb8c64fd60b001c13c8880d0", "Debug: CI test found: pr: 21310, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/0078bbb232ce7dc6f6bf30bba8b8b26645f58b26", "Debug: CI test found: pr: 21312, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/df8a8240d33a04f66a0ffd756fac2d35b52274da", "Debug: merged PR without CI test: 21313", "Debug: CI test found: pr: 21314, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/a942a2784005212c34bba790fd7d4688d3bc098c", "Debug: CI test found: pr: 21316, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/3fec0e6cbfbfa17e018d88efbdf2e7a9231f364b", "Debug: CI test found: pr: 21318, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/db4f0788c51b7ec70369604a8a327e682c98405c", "Debug: CI test found: pr: 21320, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/875afa02fabe1dad5aa3d1e9bff89d493a369fd0", "Debug: CI test found: pr: 21321, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/a55277b88966d7449222c21a663b7dd9d3d330bb", "Debug: CI test found: pr: 21324, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/b9df4a2b208f586838ecf19648169406cf8c71e9", "Debug: merged PR without CI test: 21325", "Debug: CI test found: pr: 21327, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/44ddfb922f1434411763a9a0d92d4778f75054f8", "Debug: CI test found: pr: 21328, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/5e034d4d32ce2a0374c9613cf2660d146a35e830", "Debug: merged PR without CI test: 21329", "Debug: CI test found: pr: 21330, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/4df52c20f4ddc6249c114c4476b50ec9b640ec20", "Debug: CI test found: pr: 21331, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/5dd57a00d5c48e0553062e8eb39357c5f36df20b", "Debug: merged PR without CI test: 21332", "Debug: CI test found: pr: 21333, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/e0c311b1aa146852b992c1501d032a6908033c25", "Debug: CI test found: pr: 21334, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/55caae6a787ab328d7bc52adfd92aefecf789ec9", "Debug: CI test found: pr: 21335, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/f1d467af2589d129ccd6bba9ed7eaa0b77e568a2", "Debug: merged PR without CI test: 21337", "Debug: CI test found: pr: 21341, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/17f8d8f9b4bfaf0ea191409030c511cd713f64eb", "Debug: CI test found: pr: 21342, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/38ac3ab10aaad96ece4805ca29354e0006a51719", "Debug: CI test found: pr: 21347, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/4f8c9645dfaad98b544e0ba3fdc9258513d8669f", "Debug: CI test found: pr: 21349, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/502e2b4b9e1dd54a6ac29e7609c2d5e8aa220384" ``` With this patch: ``` "Debug: CI test found: pr: 21299, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/472a52d22b9f505a4c284e7ad020ea1b3728466d", "Debug: CI test found: pr: 21300, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/cf35602cbc1bffcb5ab01153af153d0bf4e5a7e9", "Debug: CI test found: pr: 21301, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/13b7b8bd7362d198e123a67b8dfdc1c558df5b21", "Debug: CI test found: pr: 21302, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/dfa4876c417e2a9935d58100d44d94bb41cd5bfb", "Debug: CI test found: pr: 21304, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/01f6c450b655a8ce233cb5feeaddb4ec8a5610f7", "Debug: CI test found: pr: 21305, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/547f97d5714b6e1efb8c64fd60b001c13c8880d0", "Debug: CI test found: pr: 21310, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/0078bbb232ce7dc6f6bf30bba8b8b26645f58b26", "Debug: CI test found: pr: 21312, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/df8a8240d33a04f66a0ffd756fac2d35b52274da", "Debug: CI test found: pr: 21313, context: github-actions: https://api.github.com/repos/systemd/systemd/check-runs/4191612395", "Debug: CI test found: pr: 21314, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/a942a2784005212c34bba790fd7d4688d3bc098c", "Debug: CI test found: pr: 21316, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/3fec0e6cbfbfa17e018d88efbdf2e7a9231f364b", "Debug: CI test found: pr: 21318, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/db4f0788c51b7ec70369604a8a327e682c98405c", "Debug: CI test found: pr: 21320, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/875afa02fabe1dad5aa3d1e9bff89d493a369fd0", "Debug: CI test found: pr: 21321, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/a55277b88966d7449222c21a663b7dd9d3d330bb", "Debug: CI test found: pr: 21324, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/b9df4a2b208f586838ecf19648169406cf8c71e9", "Debug: CI test found: pr: 21325, context: github-actions: https://api.github.com/repos/systemd/systemd/check-runs/4191237494", "Debug: CI test found: pr: 21327, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/44ddfb922f1434411763a9a0d92d4778f75054f8", "Debug: CI test found: pr: 21328, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/5e034d4d32ce2a0374c9613cf2660d146a35e830", "Debug: CI test found: pr: 21329, context: github-actions: https://api.github.com/repos/systemd/systemd/check-runs/4192198481", "Debug: CI test found: pr: 21330, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/4df52c20f4ddc6249c114c4476b50ec9b640ec20", "Debug: CI test found: pr: 21331, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/5dd57a00d5c48e0553062e8eb39357c5f36df20b", "Debug: CI test found: pr: 21332, context: github-actions: https://api.github.com/repos/systemd/systemd/check-runs/4192365458", "Debug: CI test found: pr: 21333, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/e0c311b1aa146852b992c1501d032a6908033c25", "Debug: CI test found: pr: 21334, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/55caae6a787ab328d7bc52adfd92aefecf789ec9", "Debug: CI test found: pr: 21335, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/f1d467af2589d129ccd6bba9ed7eaa0b77e568a2", "Debug: CI test found: pr: 21337, context: github-actions: https://api.github.com/repos/systemd/systemd/check-runs/4197451714", "Debug: CI test found: pr: 21341, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/17f8d8f9b4bfaf0ea191409030c511cd713f64eb", "Debug: CI test found: pr: 21342, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/38ac3ab10aaad96ece4805ca29354e0006a51719", "Debug: CI test found: pr: 21347, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/4f8c9645dfaad98b544e0ba3fdc9258513d8669f", "Debug: CI test found: pr: 21349, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/502e2b4b9e1dd54a6ac29e7609c2d5e8aa220384" ``` Co-authored-by: Naveen <172697+naveensrinivasan@users.noreply.github.com>
2021-11-15 03:03:18 +03:00
CheckCITests = "CI-Tests"
success = "success"
)
//nolint:gochecknoinits
2020-10-09 17:47:59 +03:00
func init() {
supportedRequestTypes := []checker.RequestType{
checker.CommitBased,
}
if err := registerCheck(CheckCITests, CITests, supportedRequestTypes); err != nil {
// this should never happen
panic(err)
}
2020-10-09 17:47:59 +03:00
}
// CITests runs CI-Tests check.
func CITests(c *checker.CheckRequest) checker.CheckResult {
commits, err := c.RepoClient.ListCommits()
2020-10-09 17:47:59 +03:00
if err != nil {
e := sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("RepoClient.ListCommits: %v", err))
return checker.CreateRuntimeErrorResult(CheckCITests, e)
2020-10-09 17:47:59 +03:00
}
totalMerged := 0
totalTested := 0
for i := range commits {
pr := &commits[i].AssociatedMergeRequest
// TODO(#575): We ignore associated PRs if Scorecard is being run on a fork
// but the PR was created in the original repo.
if pr.MergedAt.IsZero() {
2020-10-09 17:47:59 +03:00
continue
}
totalMerged++
var foundCI bool
// Github Statuses.
CI-Test: stop assuming either "statuses" or "check runs" are used (#1259) Projects with a lot of different CI services use both and the check should take that into account so as not to report that PRs like https://github.com/systemd/systemd/pull/21329 with 28 successful, 4 failing, and 2 neutral checks were merged without any tests. Without this patch `scorecard` says that 5 out 30 PRs were merged without running tests: ``` "Debug: CI test found: pr: 21299, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/472a52d22b9f505a4c284e7ad020ea1b3728466d", "Debug: CI test found: pr: 21300, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/cf35602cbc1bffcb5ab01153af153d0bf4e5a7e9", "Debug: CI test found: pr: 21301, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/13b7b8bd7362d198e123a67b8dfdc1c558df5b21", "Debug: CI test found: pr: 21302, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/dfa4876c417e2a9935d58100d44d94bb41cd5bfb", "Debug: CI test found: pr: 21304, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/01f6c450b655a8ce233cb5feeaddb4ec8a5610f7", "Debug: CI test found: pr: 21305, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/547f97d5714b6e1efb8c64fd60b001c13c8880d0", "Debug: CI test found: pr: 21310, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/0078bbb232ce7dc6f6bf30bba8b8b26645f58b26", "Debug: CI test found: pr: 21312, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/df8a8240d33a04f66a0ffd756fac2d35b52274da", "Debug: merged PR without CI test: 21313", "Debug: CI test found: pr: 21314, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/a942a2784005212c34bba790fd7d4688d3bc098c", "Debug: CI test found: pr: 21316, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/3fec0e6cbfbfa17e018d88efbdf2e7a9231f364b", "Debug: CI test found: pr: 21318, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/db4f0788c51b7ec70369604a8a327e682c98405c", "Debug: CI test found: pr: 21320, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/875afa02fabe1dad5aa3d1e9bff89d493a369fd0", "Debug: CI test found: pr: 21321, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/a55277b88966d7449222c21a663b7dd9d3d330bb", "Debug: CI test found: pr: 21324, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/b9df4a2b208f586838ecf19648169406cf8c71e9", "Debug: merged PR without CI test: 21325", "Debug: CI test found: pr: 21327, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/44ddfb922f1434411763a9a0d92d4778f75054f8", "Debug: CI test found: pr: 21328, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/5e034d4d32ce2a0374c9613cf2660d146a35e830", "Debug: merged PR without CI test: 21329", "Debug: CI test found: pr: 21330, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/4df52c20f4ddc6249c114c4476b50ec9b640ec20", "Debug: CI test found: pr: 21331, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/5dd57a00d5c48e0553062e8eb39357c5f36df20b", "Debug: merged PR without CI test: 21332", "Debug: CI test found: pr: 21333, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/e0c311b1aa146852b992c1501d032a6908033c25", "Debug: CI test found: pr: 21334, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/55caae6a787ab328d7bc52adfd92aefecf789ec9", "Debug: CI test found: pr: 21335, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/f1d467af2589d129ccd6bba9ed7eaa0b77e568a2", "Debug: merged PR without CI test: 21337", "Debug: CI test found: pr: 21341, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/17f8d8f9b4bfaf0ea191409030c511cd713f64eb", "Debug: CI test found: pr: 21342, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/38ac3ab10aaad96ece4805ca29354e0006a51719", "Debug: CI test found: pr: 21347, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/4f8c9645dfaad98b544e0ba3fdc9258513d8669f", "Debug: CI test found: pr: 21349, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/502e2b4b9e1dd54a6ac29e7609c2d5e8aa220384" ``` With this patch: ``` "Debug: CI test found: pr: 21299, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/472a52d22b9f505a4c284e7ad020ea1b3728466d", "Debug: CI test found: pr: 21300, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/cf35602cbc1bffcb5ab01153af153d0bf4e5a7e9", "Debug: CI test found: pr: 21301, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/13b7b8bd7362d198e123a67b8dfdc1c558df5b21", "Debug: CI test found: pr: 21302, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/dfa4876c417e2a9935d58100d44d94bb41cd5bfb", "Debug: CI test found: pr: 21304, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/01f6c450b655a8ce233cb5feeaddb4ec8a5610f7", "Debug: CI test found: pr: 21305, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/547f97d5714b6e1efb8c64fd60b001c13c8880d0", "Debug: CI test found: pr: 21310, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/0078bbb232ce7dc6f6bf30bba8b8b26645f58b26", "Debug: CI test found: pr: 21312, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/df8a8240d33a04f66a0ffd756fac2d35b52274da", "Debug: CI test found: pr: 21313, context: github-actions: https://api.github.com/repos/systemd/systemd/check-runs/4191612395", "Debug: CI test found: pr: 21314, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/a942a2784005212c34bba790fd7d4688d3bc098c", "Debug: CI test found: pr: 21316, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/3fec0e6cbfbfa17e018d88efbdf2e7a9231f364b", "Debug: CI test found: pr: 21318, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/db4f0788c51b7ec70369604a8a327e682c98405c", "Debug: CI test found: pr: 21320, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/875afa02fabe1dad5aa3d1e9bff89d493a369fd0", "Debug: CI test found: pr: 21321, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/a55277b88966d7449222c21a663b7dd9d3d330bb", "Debug: CI test found: pr: 21324, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/b9df4a2b208f586838ecf19648169406cf8c71e9", "Debug: CI test found: pr: 21325, context: github-actions: https://api.github.com/repos/systemd/systemd/check-runs/4191237494", "Debug: CI test found: pr: 21327, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/44ddfb922f1434411763a9a0d92d4778f75054f8", "Debug: CI test found: pr: 21328, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/5e034d4d32ce2a0374c9613cf2660d146a35e830", "Debug: CI test found: pr: 21329, context: github-actions: https://api.github.com/repos/systemd/systemd/check-runs/4192198481", "Debug: CI test found: pr: 21330, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/4df52c20f4ddc6249c114c4476b50ec9b640ec20", "Debug: CI test found: pr: 21331, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/5dd57a00d5c48e0553062e8eb39357c5f36df20b", "Debug: CI test found: pr: 21332, context: github-actions: https://api.github.com/repos/systemd/systemd/check-runs/4192365458", "Debug: CI test found: pr: 21333, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/e0c311b1aa146852b992c1501d032a6908033c25", "Debug: CI test found: pr: 21334, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/55caae6a787ab328d7bc52adfd92aefecf789ec9", "Debug: CI test found: pr: 21335, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/f1d467af2589d129ccd6bba9ed7eaa0b77e568a2", "Debug: CI test found: pr: 21337, context: github-actions: https://api.github.com/repos/systemd/systemd/check-runs/4197451714", "Debug: CI test found: pr: 21341, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/17f8d8f9b4bfaf0ea191409030c511cd713f64eb", "Debug: CI test found: pr: 21342, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/38ac3ab10aaad96ece4805ca29354e0006a51719", "Debug: CI test found: pr: 21347, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/4f8c9645dfaad98b544e0ba3fdc9258513d8669f", "Debug: CI test found: pr: 21349, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/502e2b4b9e1dd54a6ac29e7609c2d5e8aa220384" ``` Co-authored-by: Naveen <172697+naveensrinivasan@users.noreply.github.com>
2021-11-15 03:03:18 +03:00
prSuccessStatus, err := prHasSuccessStatus(pr, c)
if err != nil {
return checker.CreateRuntimeErrorResult(CheckCITests, err)
}
if prSuccessStatus {
totalTested++
foundCI = true
continue
}
// Github Check Runs.
CI-Test: stop assuming either "statuses" or "check runs" are used (#1259) Projects with a lot of different CI services use both and the check should take that into account so as not to report that PRs like https://github.com/systemd/systemd/pull/21329 with 28 successful, 4 failing, and 2 neutral checks were merged without any tests. Without this patch `scorecard` says that 5 out 30 PRs were merged without running tests: ``` "Debug: CI test found: pr: 21299, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/472a52d22b9f505a4c284e7ad020ea1b3728466d", "Debug: CI test found: pr: 21300, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/cf35602cbc1bffcb5ab01153af153d0bf4e5a7e9", "Debug: CI test found: pr: 21301, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/13b7b8bd7362d198e123a67b8dfdc1c558df5b21", "Debug: CI test found: pr: 21302, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/dfa4876c417e2a9935d58100d44d94bb41cd5bfb", "Debug: CI test found: pr: 21304, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/01f6c450b655a8ce233cb5feeaddb4ec8a5610f7", "Debug: CI test found: pr: 21305, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/547f97d5714b6e1efb8c64fd60b001c13c8880d0", "Debug: CI test found: pr: 21310, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/0078bbb232ce7dc6f6bf30bba8b8b26645f58b26", "Debug: CI test found: pr: 21312, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/df8a8240d33a04f66a0ffd756fac2d35b52274da", "Debug: merged PR without CI test: 21313", "Debug: CI test found: pr: 21314, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/a942a2784005212c34bba790fd7d4688d3bc098c", "Debug: CI test found: pr: 21316, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/3fec0e6cbfbfa17e018d88efbdf2e7a9231f364b", "Debug: CI test found: pr: 21318, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/db4f0788c51b7ec70369604a8a327e682c98405c", "Debug: CI test found: pr: 21320, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/875afa02fabe1dad5aa3d1e9bff89d493a369fd0", "Debug: CI test found: pr: 21321, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/a55277b88966d7449222c21a663b7dd9d3d330bb", "Debug: CI test found: pr: 21324, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/b9df4a2b208f586838ecf19648169406cf8c71e9", "Debug: merged PR without CI test: 21325", "Debug: CI test found: pr: 21327, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/44ddfb922f1434411763a9a0d92d4778f75054f8", "Debug: CI test found: pr: 21328, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/5e034d4d32ce2a0374c9613cf2660d146a35e830", "Debug: merged PR without CI test: 21329", "Debug: CI test found: pr: 21330, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/4df52c20f4ddc6249c114c4476b50ec9b640ec20", "Debug: CI test found: pr: 21331, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/5dd57a00d5c48e0553062e8eb39357c5f36df20b", "Debug: merged PR without CI test: 21332", "Debug: CI test found: pr: 21333, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/e0c311b1aa146852b992c1501d032a6908033c25", "Debug: CI test found: pr: 21334, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/55caae6a787ab328d7bc52adfd92aefecf789ec9", "Debug: CI test found: pr: 21335, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/f1d467af2589d129ccd6bba9ed7eaa0b77e568a2", "Debug: merged PR without CI test: 21337", "Debug: CI test found: pr: 21341, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/17f8d8f9b4bfaf0ea191409030c511cd713f64eb", "Debug: CI test found: pr: 21342, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/38ac3ab10aaad96ece4805ca29354e0006a51719", "Debug: CI test found: pr: 21347, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/4f8c9645dfaad98b544e0ba3fdc9258513d8669f", "Debug: CI test found: pr: 21349, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/502e2b4b9e1dd54a6ac29e7609c2d5e8aa220384" ``` With this patch: ``` "Debug: CI test found: pr: 21299, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/472a52d22b9f505a4c284e7ad020ea1b3728466d", "Debug: CI test found: pr: 21300, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/cf35602cbc1bffcb5ab01153af153d0bf4e5a7e9", "Debug: CI test found: pr: 21301, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/13b7b8bd7362d198e123a67b8dfdc1c558df5b21", "Debug: CI test found: pr: 21302, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/dfa4876c417e2a9935d58100d44d94bb41cd5bfb", "Debug: CI test found: pr: 21304, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/01f6c450b655a8ce233cb5feeaddb4ec8a5610f7", "Debug: CI test found: pr: 21305, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/547f97d5714b6e1efb8c64fd60b001c13c8880d0", "Debug: CI test found: pr: 21310, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/0078bbb232ce7dc6f6bf30bba8b8b26645f58b26", "Debug: CI test found: pr: 21312, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/df8a8240d33a04f66a0ffd756fac2d35b52274da", "Debug: CI test found: pr: 21313, context: github-actions: https://api.github.com/repos/systemd/systemd/check-runs/4191612395", "Debug: CI test found: pr: 21314, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/a942a2784005212c34bba790fd7d4688d3bc098c", "Debug: CI test found: pr: 21316, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/3fec0e6cbfbfa17e018d88efbdf2e7a9231f364b", "Debug: CI test found: pr: 21318, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/db4f0788c51b7ec70369604a8a327e682c98405c", "Debug: CI test found: pr: 21320, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/875afa02fabe1dad5aa3d1e9bff89d493a369fd0", "Debug: CI test found: pr: 21321, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/a55277b88966d7449222c21a663b7dd9d3d330bb", "Debug: CI test found: pr: 21324, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/b9df4a2b208f586838ecf19648169406cf8c71e9", "Debug: CI test found: pr: 21325, context: github-actions: https://api.github.com/repos/systemd/systemd/check-runs/4191237494", "Debug: CI test found: pr: 21327, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/44ddfb922f1434411763a9a0d92d4778f75054f8", "Debug: CI test found: pr: 21328, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/5e034d4d32ce2a0374c9613cf2660d146a35e830", "Debug: CI test found: pr: 21329, context: github-actions: https://api.github.com/repos/systemd/systemd/check-runs/4192198481", "Debug: CI test found: pr: 21330, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/4df52c20f4ddc6249c114c4476b50ec9b640ec20", "Debug: CI test found: pr: 21331, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/5dd57a00d5c48e0553062e8eb39357c5f36df20b", "Debug: CI test found: pr: 21332, context: github-actions: https://api.github.com/repos/systemd/systemd/check-runs/4192365458", "Debug: CI test found: pr: 21333, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/e0c311b1aa146852b992c1501d032a6908033c25", "Debug: CI test found: pr: 21334, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/55caae6a787ab328d7bc52adfd92aefecf789ec9", "Debug: CI test found: pr: 21335, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/f1d467af2589d129ccd6bba9ed7eaa0b77e568a2", "Debug: CI test found: pr: 21337, context: github-actions: https://api.github.com/repos/systemd/systemd/check-runs/4197451714", "Debug: CI test found: pr: 21341, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/17f8d8f9b4bfaf0ea191409030c511cd713f64eb", "Debug: CI test found: pr: 21342, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/38ac3ab10aaad96ece4805ca29354e0006a51719", "Debug: CI test found: pr: 21347, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/4f8c9645dfaad98b544e0ba3fdc9258513d8669f", "Debug: CI test found: pr: 21349, context: ci/semaphoreci/pr: Debian autopkgtest (LXC): https://api.github.com/repos/systemd/systemd/statuses/502e2b4b9e1dd54a6ac29e7609c2d5e8aa220384" ``` Co-authored-by: Naveen <172697+naveensrinivasan@users.noreply.github.com>
2021-11-15 03:03:18 +03:00
prCheckSuccessful, err := prHasSuccessfulCheck(pr, c)
if err != nil {
return checker.CreateRuntimeErrorResult(CheckCITests, err)
}
if prCheckSuccessful {
totalTested++
foundCI = true
}
if !foundCI {
c.Dlogger.Debug(&checker.LogMessage{
Text: fmt.Sprintf("merged PR without CI test: %d", pr.Number),
})
}
}
if totalMerged == 0 {
return checker.CreateInconclusiveResult(CheckCITests, "no pull request found")
}
reason := fmt.Sprintf("%d out of %d merged PRs checked by a CI test", totalTested, totalMerged)
return checker.CreateProportionalScoreResult(CheckCITests, reason, totalTested, totalMerged)
}
// PR has a status marked 'success' and a CI-related context.
func prHasSuccessStatus(pr *clients.PullRequest, c *checker.CheckRequest) (bool, error) {
statuses, err := c.RepoClient.ListStatuses(pr.HeadSHA)
if err != nil {
return false, sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("Client.Repositories.ListStatuses: %v", err))
}
for _, status := range statuses {
if status.State != success {
continue
}
if isTest(status.Context) || isTest(status.TargetURL) {
c.Dlogger.Debug(&checker.LogMessage{
Path: status.URL,
Type: checker.FileTypeURL,
Text: fmt.Sprintf("CI test found: pr: %d, context: %s", pr.Number,
status.Context),
})
return true, nil
}
}
return false, nil
}
// PR has a successful CI-related check.
func prHasSuccessfulCheck(pr *clients.PullRequest, c *checker.CheckRequest) (bool, error) {
crs, err := c.RepoClient.ListCheckRunsForRef(pr.HeadSHA)
if err != nil {
return false, sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("Client.Checks.ListCheckRunsForRef: %v", err))
}
for _, cr := range crs {
if cr.Status != "completed" {
continue
}
if cr.Conclusion != success {
continue
}
if isTest(cr.App.Slug) {
c.Dlogger.Debug(&checker.LogMessage{
Path: cr.URL,
Type: checker.FileTypeURL,
Text: fmt.Sprintf("CI test found: pr: %d, context: %s", pr.Number,
cr.App.Slug),
})
return true, nil
}
}
return false, nil
}
// isTest returns true if the given string is a CI test.
func isTest(s string) bool {
l := strings.ToLower(s)
// Add more patterns here!
2021-04-29 05:54:07 +03:00
for _, pattern := range []string{
"appveyor", "buildkite", "circleci", "e2e", "github-actions", "jenkins",
"mergeable", "packit-as-a-service", "semaphoreci", "test", "travis-ci",
"flutter-dashboard", "Cirrus CI",
2021-04-29 05:54:07 +03:00
} {
if strings.Contains(l, pattern) {
return true
}
}
return false
}