aboutsummaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-07-14 15:54:48 +0200
committerAmine Hilaly <hilalyamine@gmail.com>2019-07-23 17:18:04 +0200
commit89227f92b5e900fb2d77680ca09966534ebd2bc1 (patch)
tree2dd40fc5d0ed8cc93dee36284cd1b52f21839171 /bridge
parentb512108ac76724f150184fff8c0499539e42dd9a (diff)
downloadgit-bug-89227f92b5e900fb2d77680ca09966534ebd2bc1.tar.gz
bridge/gitlab: add iterator LabelEvents
Diffstat (limited to 'bridge')
-rw-r--r--bridge/gitlab/iterator.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/bridge/gitlab/iterator.go b/bridge/gitlab/iterator.go
index bab35d95..f2fb0c2b 100644
--- a/bridge/gitlab/iterator.go
+++ b/bridge/gitlab/iterator.go
@@ -191,6 +191,58 @@ func (i *iterator) NoteValue() *gitlab.Note {
return i.note.cache[i.note.index]
}
+func (i *iterator) getNextLabelEvents() bool {
+ labelEvents, _, err := i.gc.ResourceLabelEvents.ListIssueLabelEvents(
+ i.project,
+ i.IssueValue().IID,
+ &gitlab.ListLabelEventsOptions{
+ ListOptions: gitlab.ListOptions{
+ Page: i.labelEvent.page,
+ PerPage: i.capacity,
+ },
+ },
+ )
+
+ 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
+ }
+
+ i.labelEvent.cache = labelEvents
+ i.labelEvent.page++
+ i.labelEvent.index = 0
+ return true
+}
+
+func (i *iterator) NextLabelEvent() bool {
+ if i.err != nil {
+ return false
+ }
+
+ if len(i.labelEvent.cache) == 0 {
+ return i.getNextLabelEvents()
+ }
+
+ // move cursor index
+ if i.labelEvent.index < min(i.capacity, len(i.labelEvent.cache))-1 {
+ i.labelEvent.index++
+ return true
+ }
+
+ return i.getNextLabelEvents()
+}
+
+func (i *iterator) LabelEventValue() *gitlab.LabelEvent {
+ return i.labelEvent.cache[i.labelEvent.index]
+}
+
func min(a, b int) int {
if a > b {
return b