Skip to content

Commit

Permalink
fix: use accessor on GitHub struct
Browse files Browse the repository at this point in the history
Wraps up nil check, easier to read.
  • Loading branch information
jamestelfer committed Oct 26, 2023
1 parent 9474644 commit 8a023ac
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/scm/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (g *Github) getSearchRepositories(ctx context.Context, search string) ([]*g
return nil, nil, err
}

if rr.IncompleteResults != nil && *rr.IncompleteResults {
if rr.GetIncompleteResults() {
// can occur when search times out on the server: for now, fail instead
// of handling the issue
return nil, nil, fmt.Errorf("search timed out on GitHub and was marked incomplete: try refining the search to return fewer results or be less complex")
Expand Down
52 changes: 52 additions & 0 deletions internal/scm/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,55 @@ func Test_GetSearchRepository_Incomplete(t *testing.T) {
assert.ErrorContains(t, err, "search timed out on GitHub and was marked incomplete")
assert.Len(t, repos, 0)
}

func Test_GetSearchRepository_TooManyResults(t *testing.T) {
transport := testTransport{
pathBodies: map[string]string{
"/search/repositories": `{
"total_count": 2054,
"incomplete_results": false,
"items": [
{
"id": 3,
"name": "search-repo1",
"full_name": "lindell/search-repo1",
"private": false,
"topics": [
"backend",
"go"
],
"owner": {
"login": "lindell",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/lindell/search-repo1",
"fork": true,
"archived": false,
"disabled": false,
"default_branch": "main",
"permissions": {
"admin": true,
"push": true,
"pull": true
},
"created_at": "2020-01-03T16:49:16Z"
}
]
}`,
},
}

gh, err := github.New(github.Config{
TransportMiddleware: transport.Wrapper,
RepoListing: github.RepositoryListing{
RepositorySearch: "search-string",
},
MergeTypes: []scm.MergeType{scm.MergeTypeMerge},
})
require.NoError(t, err)

repos, err := gh.GetRepositories(context.Background())
assert.ErrorContains(t, err, "only the first 1000 results will be returned")
assert.Len(t, repos, 0)
}

0 comments on commit 8a023ac

Please sign in to comment.