diff options
author | Matthias Simon <matthias.simon@nokia.com> | 2021-02-14 20:35:03 +0100 |
---|---|---|
committer | Matthias Simon <matthias.simon@nokia.com> | 2021-04-23 09:02:48 +0200 |
commit | aa4e225a80b37ce26f5f8c69041ee735f512b113 (patch) | |
tree | f34b7ff03f4cec4be4ed6eb3458d515452a92fe6 /bridge/gitlab/iterator/iterator.go | |
parent | a8f3b55986982db5f7c3918acaba2c214c919d11 (diff) | |
download | git-bug-aa4e225a80b37ce26f5f8c69041ee735f512b113.tar.gz |
gitlab: Add new iterator with state change events
Retrieving events is spread across various various Gitlab APIs. This
makes importing and sorting Gitlab events by time quite complicated.
This commit replaces the old iterators with a goroutine/channel-based
iterator, which merges the individual Gitlab API streams into a single
(sorted) event stream.
Diffstat (limited to 'bridge/gitlab/iterator/iterator.go')
-rw-r--r-- | bridge/gitlab/iterator/iterator.go | 138 |
1 files changed, 0 insertions, 138 deletions
diff --git a/bridge/gitlab/iterator/iterator.go b/bridge/gitlab/iterator/iterator.go deleted file mode 100644 index ee2090b0..00000000 --- a/bridge/gitlab/iterator/iterator.go +++ /dev/null @@ -1,138 +0,0 @@ -package iterator - -import ( - "context" - "time" - - "github.com/xanzy/go-gitlab" -) - -type Iterator struct { - // shared context - ctx context.Context - - // to pass to sub-iterators - conf config - - // sticky error - err error - - // issues iterator - issue *issueIterator - - // notes iterator - note *noteIterator - - // labelEvent iterator - labelEvent *labelEventIterator -} - -type config struct { - // gitlab api v4 client - gc *gitlab.Client - - timeout time.Duration - - // if since is given the iterator will query only the issues - // updated after this date - since time.Time - - // project id - project string - - // number of issues and notes to query at once - capacity int -} - -// NewIterator create a new iterator -func NewIterator(ctx context.Context, client *gitlab.Client, capacity int, projectID string, since time.Time) *Iterator { - return &Iterator{ - ctx: ctx, - conf: config{ - gc: client, - timeout: 60 * time.Second, - since: since, - project: projectID, - capacity: capacity, - }, - issue: newIssueIterator(), - note: newNoteIterator(), - labelEvent: newLabelEventIterator(), - } -} - -// Error return last encountered error -func (i *Iterator) Error() error { - return i.err -} - -func (i *Iterator) NextIssue() bool { - if i.err != nil { - return false - } - - if i.ctx.Err() != nil { - return false - } - - more, err := i.issue.Next(i.ctx, i.conf) - if err != nil { - i.err = err - return false - } - - // Also reset the other sub iterators as they would - // no longer be valid - i.note.Reset(i.issue.Value().IID) - i.labelEvent.Reset(i.issue.Value().IID) - - return more -} - -func (i *Iterator) IssueValue() *gitlab.Issue { - return i.issue.Value() -} - -func (i *Iterator) NextNote() bool { - if i.err != nil { - return false - } - - if i.ctx.Err() != nil { - return false - } - - more, err := i.note.Next(i.ctx, i.conf) - if err != nil { - i.err = err - return false - } - - return more -} - -func (i *Iterator) NoteValue() *gitlab.Note { - return i.note.Value() -} - -func (i *Iterator) NextLabelEvent() bool { - if i.err != nil { - return false - } - - if i.ctx.Err() != nil { - return false - } - - more, err := i.labelEvent.Next(i.ctx, i.conf) - if err != nil { - i.err = err - return false - } - - return more -} - -func (i *Iterator) LabelEventValue() *gitlab.LabelEvent { - return i.labelEvent.Value() -} |