mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-04-27 12:22:19 +02:00
⚡ [PROJECTS] Add: Projects Pagination API
This commit is contained in:
parent
b2e847f538
commit
805b6b01bc
54
project.go
54
project.go
@ -3,6 +3,9 @@ package jira
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/google/go-querystring/query"
|
"github.com/google/go-querystring/query"
|
||||||
)
|
)
|
||||||
@ -27,6 +30,17 @@ type ProjectList []struct {
|
|||||||
IssueTypes []IssueType `json:"issueTypes,omitempty" structs:"issueTypes,omitempty"`
|
IssueTypes []IssueType `json:"issueTypes,omitempty" structs:"issueTypes,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ProjectSearchResult struct {
|
||||||
|
Projects ProjectList `json:"values,omitempty"`
|
||||||
|
IsLast bool `json:"isLast, omitempty"`
|
||||||
|
Self string `json:"self" structs:"self"`
|
||||||
|
NextPage string `json:"nextPage" structs:"nextPage"`
|
||||||
|
MaxResults int `json:"maxResults,omitempty"`
|
||||||
|
StartAt int `json:"startAt,omitempty"`
|
||||||
|
Total int `json:"total" structs:"total"`
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// ProjectCategory represents a single project category
|
// ProjectCategory represents a single project category
|
||||||
type ProjectCategory struct {
|
type ProjectCategory struct {
|
||||||
Self string `json:"self" structs:"self,omitempty"`
|
Self string `json:"self" structs:"self,omitempty"`
|
||||||
@ -93,6 +107,46 @@ func (s *ProjectService) GetList() (*ProjectList, *Response, error) {
|
|||||||
return s.GetListWithContext(context.Background())
|
return s.GetListWithContext(context.Background())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ProjectService) Search(options *SearchOptions) (ProjectSearchResult, *Response, error) {
|
||||||
|
return s.SearchWithContext(context.Background(), options)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ProjectService) SearchWithContext(ctx context.Context, options *SearchOptions) (ProjectSearchResult, *Response, error) {
|
||||||
|
u := url.URL{
|
||||||
|
Path: "rest/api/2/project/search",
|
||||||
|
}
|
||||||
|
uv := url.Values{}
|
||||||
|
|
||||||
|
if options != nil {
|
||||||
|
if options.StartAt != 0 {
|
||||||
|
uv.Add("startAt", strconv.Itoa(options.StartAt))
|
||||||
|
}
|
||||||
|
if options.MaxResults != 0 {
|
||||||
|
uv.Add("maxResults", strconv.Itoa(options.MaxResults))
|
||||||
|
}
|
||||||
|
if options.Expand != "" {
|
||||||
|
uv.Add("expand", options.Expand)
|
||||||
|
}
|
||||||
|
if strings.Join(options.Fields, ",") != "" {
|
||||||
|
uv.Add("fields", strings.Join(options.Fields, ","))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u.RawQuery = uv.Encode()
|
||||||
|
|
||||||
|
req, err := s.client.NewRequestWithContext(ctx, "GET", u.String(), nil)
|
||||||
|
if err != nil {
|
||||||
|
return ProjectSearchResult{}, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
v := new(ProjectSearchResult)
|
||||||
|
resp, err := s.client.Do(req, v)
|
||||||
|
if err != nil {
|
||||||
|
err = NewJiraError(resp, err)
|
||||||
|
}
|
||||||
|
return *v, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
// ListWithOptionsWithContext gets all projects form Jira with optional query params, like &GetQueryOptions{Expand: "issueTypes"} to get
|
// ListWithOptionsWithContext gets all projects form Jira with optional query params, like &GetQueryOptions{Expand: "issueTypes"} to get
|
||||||
// a list of all projects and their supported issuetypes
|
// a list of all projects and their supported issuetypes
|
||||||
//
|
//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user