From 09af7a82c1666d0e64d2bd8c01797a0bcfd3bb5d Mon Sep 17 00:00:00 2001 From: Mark Mullan Date: Sat, 28 Jan 2023 17:22:31 -0800 Subject: [PATCH] Fix pagination for PRs having >100 checks (#59) * Fix pagination for PRs having >100 checks * Add a unit test * address code review * more tidy * tidy * cleaner logic --- internal/validators/status/validator.go | 2 +- internal/validators/status/validator_test.go | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/internal/validators/status/validator.go b/internal/validators/status/validator.go index a1dceda..f84bc31 100644 --- a/internal/validators/status/validator.go +++ b/internal/validators/status/validator.go @@ -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++ diff --git a/internal/validators/status/validator_test.go b/internal/validators/status/validator_test.go index 748b3ef..35ffc89 100644 --- a/internal/validators/status/validator_test.go +++ b/internal/validators/status/validator_test.go @@ -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 @@ -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, @@ -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, @@ -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,