Skip to content

Commit

Permalink
ignore search commit data for repo clients which dont support it
Browse files Browse the repository at this point in the history
The primary data is the configuration files and the search commit data
is just extra, so better to return some data than no data in this case.

Signed-off-by: Spencer Schrock <sschrock@google.com>
  • Loading branch information
spencerschrock committed Dec 29, 2023
1 parent c90e0bb commit 21031fb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
18 changes: 18 additions & 0 deletions checks/dependency_update_tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,21 @@ func TestDependencyUpdateTool(t *testing.T) {
})
}
}

func TestDependencyUpdateTool_noSearchCommits(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
mockRepo := mockrepo.NewMockRepoClient(ctrl)
files := []string{"README.md"}
mockRepo.EXPECT().ListFiles(gomock.Any()).Return(files, nil)
mockRepo.EXPECT().SearchCommits(gomock.Any()).Return(nil, clients.ErrUnsupportedFeature)
dl := scut.TestDetailLogger{}
c := &checker.CheckRequest{
RepoClient: mockRepo,
Dlogger: &dl,
}
got := DependencyUpdateTool(c)
if got.Error != nil {
t.Errorf("got: %v, wanted ErrUnsupportedFeature not to propagate", got.Error)
}
}
9 changes: 8 additions & 1 deletion checks/raw/dependency_update_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package raw

import (
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -42,7 +43,13 @@ func DependencyUpdateTool(c clients.RepoClient) (checker.DependencyUpdateToolDat

commits, err := c.SearchCommits(clients.SearchCommitsOptions{Author: "dependabot[bot]"})
if err != nil {
return checker.DependencyUpdateToolData{}, fmt.Errorf("%w", err)
// TODO https://github.com/ossf/scorecard/issues/1709
// some repo clients (e.g. local) don't currently have the ability to search commits,
// but some data is better than none.
if errors.Is(err, clients.ErrUnsupportedFeature) {
return checker.DependencyUpdateToolData{Tools: tools}, nil
}
return checker.DependencyUpdateToolData{}, fmt.Errorf("dependabot commit search: %w", err)

Check warning on line 52 in checks/raw/dependency_update_tool.go

View check run for this annotation

Codecov / codecov/patch

checks/raw/dependency_update_tool.go#L52

Added line #L52 was not covered by tests
}

for i := range commits {
Expand Down

0 comments on commit 21031fb

Please sign in to comment.