diff options
author | Michael Muré <batolettre@gmail.com> | 2020-04-04 11:59:53 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-04-04 12:42:08 +0200 |
commit | 903549cadf40ede3771053781eb6e9fd31aaa64e (patch) | |
tree | 58df795ebf4bc2f5517c2537135bef2bb2a77c10 /bridge/gitlab/iterator/note.go | |
parent | f4ca533fe10f7fa893e1953f8c8d9ed3e783486c (diff) | |
download | git-bug-903549cadf40ede3771053781eb6e9fd31aaa64e.tar.gz |
gitlab: fix iterator (paginate with first index 1) and avoid the trailing API call
Diffstat (limited to 'bridge/gitlab/iterator/note.go')
-rw-r--r-- | bridge/gitlab/iterator/note.go | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/bridge/gitlab/iterator/note.go b/bridge/gitlab/iterator/note.go index 486ca94e..a1e0544c 100644 --- a/bridge/gitlab/iterator/note.go +++ b/bridge/gitlab/iterator/note.go @@ -7,10 +7,11 @@ import ( ) type noteIterator struct { - issue int - page int - index int - cache []*gitlab.Note + issue int + page int + lastPage bool + index int + cache []*gitlab.Note } func newNoteIterator() *noteIterator { @@ -39,10 +40,14 @@ func (in *noteIterator) Value() *gitlab.Note { } func (in *noteIterator) getNext(ctx context.Context, conf config) (bool, error) { + if in.lastPage { + return false, nil + } + ctx, cancel := context.WithTimeout(ctx, conf.timeout) defer cancel() - notes, _, err := conf.gc.Notes.ListIssueNotes( + notes, resp, err := conf.gc.Notes.ListIssueNotes( conf.project, in.issue, &gitlab.ListIssueNotesOptions{ @@ -61,6 +66,10 @@ func (in *noteIterator) getNext(ctx context.Context, conf config) (bool, error) return false, err } + if resp.TotalPages == in.page { + in.lastPage = true + } + if len(notes) == 0 { return false, nil } @@ -75,6 +84,7 @@ func (in *noteIterator) getNext(ctx context.Context, conf config) (bool, error) func (in *noteIterator) Reset(issue int) { in.issue = issue in.index = -1 - in.page = -1 + in.page = 1 + in.lastPage = false in.cache = nil } |