@@ -34,33 +34,26 @@ func init() {
3434 registerCheck (CheckPackaging , Packaging )
3535}
3636
37+ func isGithubWorkflowFile (filename string ) (bool , error ) {
38+ return strings .HasPrefix (strings .ToLower (filename ), ".github/workflows" ), nil
39+ }
40+
3741// Packaging runs Packaging check.
3842func Packaging (c * checker.CheckRequest ) checker.CheckResult {
39- _ , dc , _ , err := c .Client .Repositories .GetContents (c .Ctx , c .Owner , c .Repo , ".github/workflows" ,
40- & github.RepositoryContentGetOptions {})
43+ matchedFiles , err := c .RepoClient .ListFiles (isGithubWorkflowFile )
4144 if err != nil {
42- e := sce .Create (sce .ErrScorecardInternal , fmt .Sprintf ("Client.Repositories.GetContents : %v" , err ))
45+ e := sce .Create (sce .ErrScorecardInternal , fmt .Sprintf ("RepoClient.ListFiles : %v" , err ))
4346 return checker .CreateRuntimeErrorResult (CheckPackaging , e )
4447 }
4548
46- for _ , f := range dc {
47- fp := f .GetPath ()
48- fo , _ , _ , err := c .Client .Repositories .GetContents (c .Ctx , c .Owner , c .Repo , fp , & github.RepositoryContentGetOptions {})
49- if err != nil {
50- e := sce .Create (sce .ErrScorecardInternal , fmt .Sprintf ("Client.Repositories.GetContents: %v" , err ))
51- return checker .CreateRuntimeErrorResult (CheckPackaging , e )
52- }
53- if fo == nil {
54- // path is a directory, not a file. skip.
55- continue
56- }
57- fc , err := fo .GetContent ()
49+ for _ , fp := range matchedFiles {
50+ fc , err := c .RepoClient .GetFileContent (fp )
5851 if err != nil {
59- e := sce .Create (sce .ErrScorecardInternal , fmt .Sprintf ("fo.GetContent : %v" , err ))
52+ e := sce .Create (sce .ErrScorecardInternal , fmt .Sprintf ("RepoClient.GetFileContent : %v" , err ))
6053 return checker .CreateRuntimeErrorResult (CheckPackaging , e )
6154 }
6255
63- if ! isPackagingWorkflow (fc , fp , c ) {
56+ if ! isPackagingWorkflow (string ( fc ) , fp , c ) {
6457 continue
6558 }
6659
0 commit comments