Skip to content

Commit

Permalink
Bug fixes (gitlab.go): pagination, labels (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
gruen authored Sep 14, 2020
1 parent 4c5c189 commit 8baf787
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions internal/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 8baf787

Please sign in to comment.