-
-
Notifications
You must be signed in to change notification settings - Fork 472
/
Copy pathmain.go
56 lines (46 loc) · 1.25 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"context"
"fmt"
jira "github.com/andygrunwald/go-jira/v2/cloud"
)
// GetAllIssues will implement pagination of api and get all the issues.
// Jira API has limitation as to maxResults it can return at one time.
// You may have usecase where you need to get all the issues according to jql
// This is where this example comes in.
func GetAllIssues(client *jira.Client, searchString string) ([]jira.Issue, error) {
last := 0
var issues []jira.Issue
for {
opt := &jira.SearchOptions{
MaxResults: 1000, // Max results can go up to 1000
StartAt: last,
}
chunk, resp, err := client.Issue.Search(context.Background(), searchString, opt)
if err != nil {
return nil, err
}
total := resp.Total
if issues == nil {
issues = make([]jira.Issue, 0, total)
}
issues = append(issues, chunk...)
last = resp.StartAt len(chunk)
if last >= total {
return issues, nil
}
}
}
func main() {
jiraClient, err := jira.NewClient("https://issues.apache.org/jira/", nil)
if err != nil {
panic(err)
}
jql := "project = Mesos and type = Bug and Status NOT IN (Resolved)"
fmt.Printf("Usecase: Running a JQL query '%s'\n", jql)
issues, err := GetAllIssues(jiraClient, jql)
if err != nil {
panic(err)
}
fmt.Println(issues)
}