diff options
author | Amine <hilalyamine@gmail.com> | 2019-10-02 15:39:24 +0200 |
---|---|---|
committer | Amine <hilalyamine@gmail.com> | 2019-10-02 15:39:24 +0200 |
commit | 312bc58c540902901ca9ad7238b4cf85eefb9d24 (patch) | |
tree | 772940e0b78a8838fcc7840c0f40d8cd0f456385 | |
parent | 8498deaa194f7ad3d69787d89e26feb280986d5c (diff) | |
download | git-bug-312bc58c540902901ca9ad7238b4cf85eefb9d24.tar.gz |
bridge/gitlab: iterator now query all label events when NextLabelEvent() i called, and sort them by ID
-rw-r--r-- | bridge/gitlab/iterator.go | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/bridge/gitlab/iterator.go b/bridge/gitlab/iterator.go index d5425cee..aef68faa 100644 --- a/bridge/gitlab/iterator.go +++ b/bridge/gitlab/iterator.go @@ -224,40 +224,39 @@ func (i *iterator) NoteValue() *gitlab.Note { return i.note.cache[i.note.index] } -func (i *iterator) getNextLabelEvents() bool { +func (i *iterator) getLabelEvents() bool { ctx, cancel := context.WithTimeout(i.ctx, defaultTimeout) defer cancel() - labelEvents, _, err := i.gc.ResourceLabelEvents.ListIssueLabelEvents( - i.project, - i.IssueValue().IID, - &gitlab.ListLabelEventsOptions{ - ListOptions: gitlab.ListOptions{ - Page: i.labelEvent.page, - PerPage: i.capacity, + hasNextPage := true + for hasNextPage { + labelEvents, _, err := i.gc.ResourceLabelEvents.ListIssueLabelEvents( + i.project, + i.IssueValue().IID, + &gitlab.ListLabelEventsOptions{ + ListOptions: gitlab.ListOptions{ + Page: i.labelEvent.page, + PerPage: i.capacity, + }, }, - }, - gitlab.WithContext(ctx), - ) - - if err != nil { - i.err = err - return false - } - - if len(labelEvents) == 0 { - i.labelEvent.page = 1 - i.labelEvent.index = -1 - i.labelEvent.cache = nil - return false + gitlab.WithContext(ctx), + ) + if err != nil { + i.err = err + return false + } + + i.labelEvent.page++ + hasNextPage = len(labelEvents) != 0 + i.labelEvent.cache = append(i.labelEvent.cache, labelEvents...) } - i.labelEvent.cache = labelEvents - i.labelEvent.page++ + i.labelEvent.page = 1 i.labelEvent.index = 0 - sort.Sort(i.labelEvent) - return true + + // if the label events list is empty return false + return len(i.labelEvent.cache) != 0 } // because Gitlab @@ -271,7 +270,7 @@ func (i *iterator) NextLabelEvent() bool { } if len(i.labelEvent.cache) == 0 { - return i.getNextLabelEvents() + return i.getLabelEvents() } // move cursor index @@ -280,7 +279,7 @@ func (i *iterator) NextLabelEvent() bool { return true } - return i.getNextLabelEvents() + return false } func (i *iterator) LabelEventValue() *gitlab.LabelEvent { |