1
0
mirror of https://github.com/strongdm/comply synced 2024-11-22 07:34:54 +00:00

Bug fixes (gitlab.go): pagination, labels (#84)

This commit is contained in:
Michael E. Gruen 2020-09-14 14:11:09 -04:00 committed by GitHub
parent 4c5c18964b
commit 8baf787ed7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}