Skip to content

Commit

Permalink
🐛 Dependency-Update-Tool: ignore search commit data for repo clients …
Browse files Browse the repository at this point in the history
…which dont support it (#3756)

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 <[email protected]>
  • Loading branch information
spencerschrock authored Dec 29, 2023
1 parent 9b5de80 commit 69bb742
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)
}

for i := range commits {
Expand Down

0 comments on commit 69bb742

Please sign in to comment.