diff --git a/checks/packaging.go b/checks/packaging.go index cf15f7c8..5c1dc266 100644 --- a/checks/packaging.go +++ b/checks/packaging.go @@ -34,33 +34,26 @@ func init() { registerCheck(CheckPackaging, Packaging) } +func isGithubWorkflowFile(filename string) (bool, error) { + return strings.HasPrefix(strings.ToLower(filename), ".github/workflows"), nil +} + // Packaging runs Packaging check. func Packaging(c *checker.CheckRequest) checker.CheckResult { - _, dc, _, err := c.Client.Repositories.GetContents(c.Ctx, c.Owner, c.Repo, ".github/workflows", - &github.RepositoryContentGetOptions{}) + matchedFiles, err := c.RepoClient.ListFiles(isGithubWorkflowFile) if err != nil { - e := sce.Create(sce.ErrScorecardInternal, fmt.Sprintf("Client.Repositories.GetContents: %v", err)) + e := sce.Create(sce.ErrScorecardInternal, fmt.Sprintf("RepoClient.ListFiles: %v", err)) return checker.CreateRuntimeErrorResult(CheckPackaging, e) } - for _, f := range dc { - fp := f.GetPath() - fo, _, _, err := c.Client.Repositories.GetContents(c.Ctx, c.Owner, c.Repo, fp, &github.RepositoryContentGetOptions{}) + for _, fp := range matchedFiles { + fc, err := c.RepoClient.GetFileContent(fp) if err != nil { - e := sce.Create(sce.ErrScorecardInternal, fmt.Sprintf("Client.Repositories.GetContents: %v", err)) - return checker.CreateRuntimeErrorResult(CheckPackaging, e) - } - if fo == nil { - // path is a directory, not a file. skip. - continue - } - fc, err := fo.GetContent() - if err != nil { - e := sce.Create(sce.ErrScorecardInternal, fmt.Sprintf("fo.GetContent: %v", err)) + e := sce.Create(sce.ErrScorecardInternal, fmt.Sprintf("RepoClient.GetFileContent: %v", err)) return checker.CreateRuntimeErrorResult(CheckPackaging, e) } - if !isPackagingWorkflow(fc, fp, c) { + if !isPackagingWorkflow(string(fc), fp, c) { continue } diff --git a/e2e/packaging_test.go b/e2e/packaging_test.go index e1e08198..c5c4223b 100644 --- a/e2e/packaging_test.go +++ b/e2e/packaging_test.go @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// nolint: dupl package e2e import ( @@ -22,20 +23,24 @@ import ( "github.com/ossf/scorecard/v2/checker" "github.com/ossf/scorecard/v2/checks" + "github.com/ossf/scorecard/v2/clients/githubrepo" scut "github.com/ossf/scorecard/v2/utests" ) -var _ = Describe("E2E TEST:Packaging", func() { +var _ = Describe("E2E TEST:"+checks.CheckPackaging, func() { Context("E2E TEST:Validating use of packaging in CI/CD", func() { It("Should return use of packaging in CI/CD", func() { dl := scut.TestDetailLogger{} + repoClient := githubrepo.CreateGithubRepoClient(context.Background(), ghClient, graphClient) + err := repoClient.InitRepo("ossf-tests", "scorecard-check-packaging-e2e") + Expect(err).Should(BeNil()) req := checker.CheckRequest{ Ctx: context.Background(), Client: ghClient, HTTPClient: httpClient, - RepoClient: nil, - Owner: "apache", - Repo: "orc", + RepoClient: repoClient, + Owner: "ossf-tests", + Repo: "scorecard-check-packaging-e2e", GraphClient: graphClient, Dlogger: &dl, }