mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-07-03 00:27:05 +02:00
update as requested
This commit is contained in:
56
README.md
56
README.md
@ -222,62 +222,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
### Get all the issues for JQL with Pagination
|
### Get all the issues for JQL with Pagination
|
||||||
Jira API has limit on maxResults it can return. YOu may have a usecase where you need to get all issues for given JQL.
|
Jira API has limit on maxResults it can return. You may have a usecase where you need to get all issues for given JQL.
|
||||||
This example shows reference implementation of GetAllIssues function which does pagination on Jira API to get all the issues for given JQL
|
This example shows reference implementation of GetAllIssues function which does pagination on Jira API to get all the issues for given JQL
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
jira "github.com/andygrunwald/go-jira"
|
|
||||||
)
|
|
||||||
|
|
||||||
//GetAllIssues takes a jira client and returns all issues for given JQL
|
|
||||||
func GetAllIssues(client *jira.Client, searchString string) ([]jira.Issue, error) {
|
|
||||||
last := 0
|
|
||||||
var issues []jira.Issue = nil
|
|
||||||
for {
|
|
||||||
opt := &jira.SearchOptions{
|
|
||||||
MaxResults: 100,
|
|
||||||
StartAt: last,
|
|
||||||
}
|
|
||||||
|
|
||||||
chunk, resp, err := client.Issue.Search(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 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return issues, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
jiraClient, _ := jira.NewClient(nil, "https://issues.apache.org/jira/")
|
|
||||||
|
|
||||||
// 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.
|
|
||||||
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)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
please look at examples/pagination/main.go
|
||||||
|
|
||||||
```
|
```
|
||||||
### Call a not implemented API endpoint
|
### Call a not implemented API endpoint
|
||||||
|
@ -6,13 +6,16 @@ import (
|
|||||||
jira "github.com/andygrunwald/go-jira"
|
jira "github.com/andygrunwald/go-jira"
|
||||||
)
|
)
|
||||||
|
|
||||||
//GetAllIssues takes a jira client and returns all issues for given JQL
|
// 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) {
|
func GetAllIssues(client *jira.Client, searchString string) ([]jira.Issue, error) {
|
||||||
last := 0
|
last := 0
|
||||||
var issues []jira.Issue = nil
|
var issues []jira.Issue
|
||||||
for {
|
for {
|
||||||
opt := &jira.SearchOptions{
|
opt := &jira.SearchOptions{
|
||||||
MaxResults: 100,
|
MaxResults: 1000, // Max results can go upto 1000
|
||||||
StartAt: last,
|
StartAt: last,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,25 +24,25 @@ func GetAllIssues(client *jira.Client, searchString string) ([]jira.Issue, error
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
total := resp.Total
|
|
||||||
if issues == nil {
|
if issues == nil {
|
||||||
|
total := resp.Total
|
||||||
issues = make([]jira.Issue, 0, total)
|
issues = make([]jira.Issue, 0, total)
|
||||||
}
|
}
|
||||||
issues = append(issues, chunk...)
|
issues = append(issues, chunk...)
|
||||||
last = resp.StartAt + len(chunk)
|
last = resp.StartAt + len(chunk)
|
||||||
if last >= total {
|
if last >= total {
|
||||||
break
|
return issues, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return issues, nil
|
return issues, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
jiraClient, _ := jira.NewClient(nil, "https://issues.apache.org/jira/")
|
jiraClient, err := jira.NewClient(nil, "https://issues.apache.org/jira/")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
|
||||||
jql := "project = Mesos and type = Bug and Status NOT IN (Resolved)"
|
jql := "project = Mesos and type = Bug and Status NOT IN (Resolved)"
|
||||||
fmt.Printf("Usecase: Running a JQL query '%s'\n", jql)
|
fmt.Printf("Usecase: Running a JQL query '%s'\n", jql)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user