Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created August 6, 2021 12:09
Show Gist options
  • Save percybolmer/b767f107ed0165726c34cc6fbef6cff7 to your computer and use it in GitHub Desktop.
Save percybolmer/b767f107ed0165726c34cc6fbef6cff7 to your computer and use it in GitHub Desktop.
// getIssues will query Jira API using the provided JQL string
func getIssues(client *jira.Client, jql string) ([]jira.Issue, error) {
// lastIssue is the index of the last issue returned
lastIssue := 0
// Make a loop through amount of issues
var result []jira.Issue
for {
// Add a Search option which accepts maximum amount (1000)
opt := &jira.SearchOptions{
MaxResults: 1000, // Max amount
StartAt: lastIssue, // Make sure we start grabbing issues from last checkpoint
}
issues, resp, err := client.Issue.Search(jql, opt)
if err != nil {
return nil, err
}
// Grab total amount from response
total := resp.Total
if issues == nil {
// init the issues array with the correct amount of length
result = make([]jira.Issue, 0, total)
}
// Append found issues to result
result = append(result, issues...)
// Update checkpoint index by using the response StartAt variable
lastIssue = resp.StartAt + len(issues)
// Check if we have reached the end of the issues
if lastIssue >= total {
break
}
}
for _, i := range result {
fmt.Printf("%s (%s/%s): %+v -> %s\n", i.Key, i.Fields.Type.Name, i.Fields.Priority.Name, i.Fields.Summary, i.Fields.Status.Name)
fmt.Printf("Assignee : %v\n", i.Fields.Assignee.DisplayName)
fmt.Printf("Reporter: %v\n", i.Fields.Reporter.DisplayName)
}
return result, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment