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/issue.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/issue.go')
-rw-r--r-- | bridge/gitlab/iterator/issue.go | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/bridge/gitlab/iterator/issue.go b/bridge/gitlab/iterator/issue.go deleted file mode 100644 index 9361b496..00000000 --- a/bridge/gitlab/iterator/issue.go +++ /dev/null @@ -1,89 +0,0 @@ -package iterator - -import ( - "context" - - "github.com/xanzy/go-gitlab" -) - -type issueIterator struct { - page int - lastPage bool - index int - cache []*gitlab.Issue -} - -func newIssueIterator() *issueIterator { - ii := &issueIterator{} - ii.Reset() - return ii -} - -func (ii *issueIterator) Next(ctx context.Context, conf config) (bool, error) { - // first query - if ii.cache == nil { - return ii.getNext(ctx, conf) - } - - // move cursor index - if ii.index < len(ii.cache)-1 { - ii.index++ - return true, nil - } - - return ii.getNext(ctx, conf) -} - -func (ii *issueIterator) Value() *gitlab.Issue { - return ii.cache[ii.index] -} - -func (ii *issueIterator) getNext(ctx context.Context, conf config) (bool, error) { - if ii.lastPage { - return false, nil - } - - ctx, cancel := context.WithTimeout(ctx, conf.timeout) - defer cancel() - - issues, resp, err := conf.gc.Issues.ListProjectIssues( - conf.project, - &gitlab.ListProjectIssuesOptions{ - ListOptions: gitlab.ListOptions{ - Page: ii.page, - PerPage: conf.capacity, - }, - Scope: gitlab.String("all"), - UpdatedAfter: &conf.since, - Sort: gitlab.String("asc"), - }, - gitlab.WithContext(ctx), - ) - - if err != nil { - ii.Reset() - return false, err - } - - if resp.TotalPages == ii.page { - ii.lastPage = true - } - - // if repository doesn't have any issues - if len(issues) == 0 { - return false, nil - } - - ii.cache = issues - ii.index = 0 - ii.page++ - - return true, nil -} - -func (ii *issueIterator) Reset() { - ii.index = -1 - ii.page = 1 - ii.lastPage = false - ii.cache = nil -} |