mirror of
https://github.com/ossf/scorecard.git
synced 2024-09-19 04:57:14 +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)
|
registerCheck(CheckPackaging, Packaging)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isGithubWorkflowFile(filename string) (bool, error) {
|
||||||
|
return strings.HasPrefix(strings.ToLower(filename), ".github/workflows"), nil
|
||||||
|
}
|
||||||
|
|
||||||
// Packaging runs Packaging check.
|
// Packaging runs Packaging check.
|
||||||
func Packaging(c *checker.CheckRequest) checker.CheckResult {
|
func Packaging(c *checker.CheckRequest) checker.CheckResult {
|
||||||
_, dc, _, err := c.Client.Repositories.GetContents(c.Ctx, c.Owner, c.Repo, ".github/workflows",
|
matchedFiles, err := c.RepoClient.ListFiles(isGithubWorkflowFile)
|
||||||
&github.RepositoryContentGetOptions{})
|
|
||||||
if err != nil {
|
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)
|
return checker.CreateRuntimeErrorResult(CheckPackaging, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range dc {
|
for _, fp := range matchedFiles {
|
||||||
fp := f.GetPath()
|
fc, err := c.RepoClient.GetFileContent(fp)
|
||||||
fo, _, _, err := c.Client.Repositories.GetContents(c.Ctx, c.Owner, c.Repo, fp, &github.RepositoryContentGetOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := sce.Create(sce.ErrScorecardInternal, fmt.Sprintf("Client.Repositories.GetContents: %v", err))
|
e := sce.Create(sce.ErrScorecardInternal, fmt.Sprintf("RepoClient.GetFileContent: %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))
|
|
||||||
return checker.CreateRuntimeErrorResult(CheckPackaging, e)
|
return checker.CreateRuntimeErrorResult(CheckPackaging, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isPackagingWorkflow(fc, fp, c) {
|
if !isPackagingWorkflow(string(fc), fp, c) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
// nolint: dupl
|
||||||
package e2e
|
package e2e
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -22,20 +23,24 @@ import (
|
|||||||
|
|
||||||
"github.com/ossf/scorecard/v2/checker"
|
"github.com/ossf/scorecard/v2/checker"
|
||||||
"github.com/ossf/scorecard/v2/checks"
|
"github.com/ossf/scorecard/v2/checks"
|
||||||
|
"github.com/ossf/scorecard/v2/clients/githubrepo"
|
||||||
scut "github.com/ossf/scorecard/v2/utests"
|
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() {
|
Context("E2E TEST:Validating use of packaging in CI/CD", func() {
|
||||||
It("Should return use of packaging in CI/CD", func() {
|
It("Should return use of packaging in CI/CD", func() {
|
||||||
dl := scut.TestDetailLogger{}
|
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{
|
req := checker.CheckRequest{
|
||||||
Ctx: context.Background(),
|
Ctx: context.Background(),
|
||||||
Client: ghClient,
|
Client: ghClient,
|
||||||
HTTPClient: httpClient,
|
HTTPClient: httpClient,
|
||||||
RepoClient: nil,
|
RepoClient: repoClient,
|
||||||
Owner: "apache",
|
Owner: "ossf-tests",
|
||||||
Repo: "orc",
|
Repo: "scorecard-check-packaging-e2e",
|
||||||
GraphClient: graphClient,
|
GraphClient: graphClient,
|
||||||
Dlogger: &dl,
|
Dlogger: &dl,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user