mirror of
https://github.com/ossf/scorecard.git
synced 2024-09-11 00:45:36 +03:00
Update Packaging
check to use new APIs (#796)
Co-authored-by: Azeem Shaikh <azeems@google.com>
This commit is contained in:
parent
1bee125ab3
commit
30bb11965a
@ -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
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user