Skip to content

Commit

Permalink
Fix pagination for PRs having >100 checks (#59)
Browse files Browse the repository at this point in the history
* Fix pagination for PRs having >100 checks

* Add a unit test

* address code review

* more tidy

* tidy

* cleaner logic
  • Loading branch information
markrmullan authored Jan 29, 2023
1 parent a231533 commit 09af7a8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion internal/validators/status/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (sv *statusValidator) listCheckRunsForRef(ctx context.Context) ([]*github.C
return nil, err
}
runResults = append(runResults, cr.CheckRuns...)
if cr.GetTotal() < maxCheckRunsPerPage {
if cr.GetTotal() <= len(runResults) {
break
}
page++
Expand Down
14 changes: 4 additions & 10 deletions internal/validators/status/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func Test_statusValidator_Validate(t *testing.T) {
}
}

func Test_statusValidator_listStatues(t *testing.T) {
func Test_statusValidator_listStatuses(t *testing.T) {
type fields struct {
repo string
owner string
Expand Down Expand Up @@ -785,9 +785,7 @@ func Test_statusValidator_listStatues(t *testing.T) {
}, nil, nil
},
ListCheckRunsForRefFunc: func(ctx context.Context, owner, repo, ref string, opts *github.ListCheckRunsOptions) (*github.ListCheckRunsResults, *github.Response, error) {
max := min(opts.ListOptions.Page*opts.ListOptions.PerPage, len(checkRuns))
sts := checkRuns[(opts.ListOptions.Page-1)*opts.ListOptions.PerPage : max]
l := len(sts)
l := len(checkRuns)
return &github.ListCheckRunsResults{
CheckRuns: checkRuns,
Total: &l,
Expand Down Expand Up @@ -840,9 +838,7 @@ func Test_statusValidator_listStatues(t *testing.T) {
}, nil, nil
},
ListCheckRunsForRefFunc: func(ctx context.Context, owner, repo, ref string, opts *github.ListCheckRunsOptions) (*github.ListCheckRunsResults, *github.Response, error) {
max := min(opts.ListOptions.Page*opts.ListOptions.PerPage, len(checkRuns))
sts := checkRuns[(opts.ListOptions.Page-1)*opts.ListOptions.PerPage : max]
l := len(sts)
l := len(checkRuns)
return &github.ListCheckRunsResults{
CheckRuns: checkRuns,
Total: &l,
Expand Down Expand Up @@ -895,9 +891,7 @@ func Test_statusValidator_listStatues(t *testing.T) {
}, nil, nil
},
ListCheckRunsForRefFunc: func(ctx context.Context, owner, repo, ref string, opts *github.ListCheckRunsOptions) (*github.ListCheckRunsResults, *github.Response, error) {
max := min(opts.ListOptions.Page*opts.ListOptions.PerPage, len(checkRuns))
sts := checkRuns[(opts.ListOptions.Page-1)*opts.ListOptions.PerPage : max]
l := len(sts)
l := len(checkRuns)
return &github.ListCheckRunsResults{
CheckRuns: checkRuns,
Total: &l,
Expand Down

0 comments on commit 09af7a8

Please sign in to comment.