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

🐛 Fix --local functionality #2342

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/scorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ func runEnabledChecks(ctx context.Context,

func getRepoCommitHash(r clients.RepoClient) (string, error) {
commits, err := r.ListCommits()

if err != nil && !errors.Is(err, clients.ErrUnsupportedFeature) {
if err != nil {
// allow --local repos to still process
if errors.Is(err, clients.ErrUnsupportedFeature) {
return "unknown", nil
}
return "", sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("ListCommits:%v", err.Error()))
}

Expand Down
46 changes: 46 additions & 0 deletions pkg/scorecard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
"github.com/golang/mock/gomock"

"github.com/ossf/scorecard/v4/clients"
"github.com/ossf/scorecard/v4/clients/localdir"
mockrepo "github.com/ossf/scorecard/v4/clients/mockclients"
"github.com/ossf/scorecard/v4/log"
)

func Test_getRepoCommitHash(t *testing.T) {
Expand Down Expand Up @@ -72,6 +74,50 @@ func Test_getRepoCommitHash(t *testing.T) {
}
}

func Test_getRepoCommitHashLocal(t *testing.T) {
t.Parallel()
tests := []struct {
name string
path string
want string
wantErr bool
}{
{
name: "local directory",
path: "testdata",
want: "unknown",
wantErr: false,
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
logger := log.NewLogger(log.DebugLevel)
localDirClient := localdir.CreateLocalDirClient(context.Background(), logger)
localRepo, err := localdir.MakeLocalDirRepo("testdata")
if err != nil {
t.Errorf("MakeLocalDirRepo: %v", err)
return
}
if err := localDirClient.InitRepo(localRepo, clients.HeadSHA); err != nil {
t.Errorf("InitRepo: %v", err)
return
}

got, err := getRepoCommitHash(localDirClient)
if (err != nil) != tt.wantErr {
t.Errorf("getRepoCommitHash() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("getRepoCommitHash() got = %v, want %v", got, tt.want)
}
})
}
}

func TestRunScorecards(t *testing.T) {
t.Parallel()
type args struct {
Expand Down