Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠️ Add ProjectPackageVersions to raw data collection #4104

Merged
merged 13 commits into from
May 30, 2024
12 changes: 12 additions & 0 deletions checker/raw_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ type Package struct {
Runs []Run
}

type PackageProvenance struct {
Commit string
IsVerified bool
}
type ProjectPackages struct {
raghavkaul marked this conversation as resolved.
Show resolved Hide resolved
System string
Name string
Version string
SLSAProvenance PackageProvenance
raghavkaul marked this conversation as resolved.
Show resolved Hide resolved
}

// DependencyUseType represents a type of dependency use.
type DependencyUseType string

Expand Down Expand Up @@ -287,6 +298,7 @@ type BinaryArtifactData struct {
// for the Signed-Releases check.
type SignedReleasesData struct {
Releases []clients.Release
Packages []ProjectPackages
}

// DependencyUpdateToolData contains the raw results
Expand Down
4 changes: 0 additions & 4 deletions checks/raw/code_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ func CodeReview(c clients.RepoClient) (checker.CodeReviewData, error) {

changesets := getChangesets(commits)

if err != nil {
return checker.CodeReviewData{}, fmt.Errorf("%w", err)
}

return checker.CodeReviewData{
DefaultBranchChangesets: changesets,
}, nil
Expand Down
25 changes: 25 additions & 0 deletions checks/raw/signed_releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,32 @@ func SignedReleases(c *checker.CheckRequest) (checker.SignedReleasesData, error)
return checker.SignedReleasesData{}, fmt.Errorf("%w", err)
}

versions, err := c.ProjectClient.GetProjectPackageVersions(c.Ctx, c.Repo.Host(), c.Repo.Path())
if err != nil {
return checker.SignedReleasesData{}, fmt.Errorf("GetProjectPackageVersions: %w", err)
}

pkgs := []checker.ProjectPackages{}
for _, v := range versions.Versions {
prov := checker.PackageProvenance{}

if len(v.SLSAProvenances) > 0 {
prov = checker.PackageProvenance{
Commit: v.SLSAProvenances[0].Commit,
IsVerified: v.SLSAProvenances[0].Verified,
}
}

pkgs = append(pkgs, checker.ProjectPackages{
System: v.VersionKey.System,
Name: v.VersionKey.Name,
Version: v.VersionKey.Version,
SLSAProvenance: prov,
})
}

return checker.SignedReleasesData{
Releases: releases,
Packages: pkgs,
}, nil
}
30 changes: 27 additions & 3 deletions checks/signed_releases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package checks

import (
"context"
"errors"
"fmt"
"testing"
Expand All @@ -24,6 +25,7 @@ import (
"github.com/ossf/scorecard/v5/checker"
"github.com/ossf/scorecard/v5/clients"
mockrepo "github.com/ossf/scorecard/v5/clients/mockclients"
"github.com/ossf/scorecard/v5/internal/packageclient"
scut "github.com/ossf/scorecard/v5/utests"
)

Expand Down Expand Up @@ -435,8 +437,8 @@ func TestSignedRelease(t *testing.T) {

ctrl := gomock.NewController(t)

mockRepo := mockrepo.NewMockRepoClient(ctrl)
mockRepo.EXPECT().ListReleases().DoAndReturn(
mockRepoC := mockrepo.NewMockRepoClient(ctrl)
mockRepoC.EXPECT().ListReleases().DoAndReturn(
func() ([]clients.Release, error) {
if tt.err != nil {
return nil, tt.err
Expand All @@ -445,8 +447,30 @@ func TestSignedRelease(t *testing.T) {
},
).MinTimes(1)

mockRepo := mockrepo.NewMockRepo(ctrl)
mockRepo.EXPECT().Host().DoAndReturn(
func() string {
return ""
},
).AnyTimes()
mockRepo.EXPECT().Path().DoAndReturn(
func() string {
return ""
},
).AnyTimes()

mockPkgC := mockrepo.NewMockProjectPackageClient(ctrl)
mockPkgC.EXPECT().GetProjectPackageVersions(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(
func(ctx context.Context, host, project string) (*packageclient.ProjectPackageVersions, error) {
v := packageclient.ProjectPackageVersions{}
return &v, nil
},
).AnyTimes()

req := checker.CheckRequest{
RepoClient: mockRepo,
RepoClient: mockRepoC,
Repo: mockRepo,
ProjectClient: mockPkgC,
}
req.Dlogger = &scut.TestDetailLogger{}
res := SignedReleases(&req)
Expand Down
5 changes: 5 additions & 0 deletions clients/githubrepo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,8 @@ func MakeGithubRepo(input string) (clients.Repo, error) {
}
return &repo, nil
}

// Path() implements RepoClient.Path.
func (r *repoURL) Path() string {
return fmt.Sprintf("%s/%s", r.owner, r.repo)
}
5 changes: 5 additions & 0 deletions clients/gitlabrepo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ func (r *repoURL) Metadata() []string {
return r.metadata
}

// Path() implements RepoClient.Path.
func (r *repoURL) Path() string {
return fmt.Sprintf("%s/%s", r.owner, r.project)
}

// MakeGitlabRepo takes input of forms in parse and returns and implementation
// of clients.Repo interface.
func MakeGitlabRepo(input string) (clients.Repo, error) {
Expand Down
5 changes: 5 additions & 0 deletions clients/localdir/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func (r *repoLocal) AppendMetadata(m ...string) {
r.metadata = append(r.metadata, m...)
}

// Path() implements RepoClient.Path.
func (r *repoLocal) Path() string {
return r.path
}

// MakeLocalDirRepo returns an implementation of clients.Repo interface.
func MakeLocalDirRepo(pathfn string) (clients.Repo, error) {
p := path.Clean(pathfn)
Expand Down
65 changes: 65 additions & 0 deletions clients/mockclients/projectpackageclient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions clients/mockclients/repo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions clients/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ package clients

// Repo interface uniquely identifies a repo.
type Repo interface {
// Path returns the specifier of the repository within its forge
Path() string
// URI returns the fully qualified address of the repository
URI() string
// Host returns the web domain of the repository
Host() string
// String returns a string representation of the repository URI
String() string
// IsValid returns whether the repository provided is a real URI
IsValid() error
raghavkaul marked this conversation as resolved.
Show resolved Hide resolved
Metadata() []string
AppendMetadata(metadata ...string)
Expand Down
Loading