From 8baf787ed7380bc73123ffcc4abcc83144301fa8 Mon Sep 17 00:00:00 2001 From: "Michael E. Gruen" Date: Mon, 14 Sep 2020 14:11:09 -0400 Subject: [PATCH] Bug fixes (gitlab.go): pagination, labels (#84) --- internal/gitlab/gitlab.go | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/internal/gitlab/gitlab.go b/internal/gitlab/gitlab.go index 049cc46..44b9e33 100644 --- a/internal/gitlab/gitlab.go +++ b/internal/gitlab/gitlab.go @@ -99,13 +99,33 @@ func getCfg(cfg map[string]interface{}, k string) (string, error) { return vS, nil } +func getProjectIssues(g *gitlabPlugin, options *gitlab.ListProjectIssuesOptions) ([]*gitlab.Issue, error) { + issues := []*gitlab.Issue{} + options.Page = 1 + + for { + pageIssues, resp, err := g.api().Issues.ListProjectIssues(g.reponame, options) + if err != nil { + return nil, errors.Wrap(err, "error retreiving issues from gitlab") + } + + issues = append(issues, pageIssues...) + + if resp.CurrentPage >= resp.TotalPages { + break + } + options.Page = resp.NextPage + } + + return issues, nil +} + func (g *gitlabPlugin) FindOpen() ([]*model.Ticket, error) { options := &gitlab.ListProjectIssuesOptions{ State: gitlab.String("opened"), } - issues, _, err := g.api().Issues.ListProjectIssues(g.reponame, options) - + issues, err := getProjectIssues(g, options) if err != nil { return nil, errors.Wrap(err, "error during FindOpen") } @@ -123,10 +143,9 @@ func (g *gitlabPlugin) FindByTagName(name string) ([]*model.Ticket, error) { Labels: []string{name}, } - issues, _, err := g.api().Issues.ListProjectIssues(g.reponame, options) - + issues, err := getProjectIssues(g, options) if err != nil { - return nil, errors.Wrap(err, "error during FindOpen") + return nil, errors.Wrap(err, "error during FindByTagName") } return toTickets(issues), nil @@ -169,6 +188,15 @@ func toTicket(i *gitlab.Issue) *model.Ticket { if l == "procedure" { t.SetBool("comply-procedure") } + + // seems redundant, but fixes a bug the other two labels introduce + // whereby open comply tickets aren't properly accounted for in the UI + if l == "comply-audit" { + t.SetBool("comply-audit") + } + if l == "comply-procedure" { + t.SetBool("comply-procedure") + } } return t }