mirror of
				https://github.com/interviewstreet/go-jira.git
				synced 2025-10-30 23:47:46 +02:00 
			
		
		
		
	⚡ [PROJECTS] Add: Projects Pagination API
This commit is contained in:
		
							
								
								
									
										54
									
								
								project.go
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								project.go
									
									
									
									
									
								
							| @@ -3,6 +3,9 @@ package jira | ||||
| import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"net/url" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
|  | ||||
| 	"github.com/google/go-querystring/query" | ||||
| ) | ||||
| @@ -27,6 +30,17 @@ type ProjectList []struct { | ||||
| 	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 | ||||
| type ProjectCategory struct { | ||||
| 	Self        string `json:"self" structs:"self,omitempty"` | ||||
| @@ -93,6 +107,46 @@ func (s *ProjectService) GetList() (*ProjectList, *Response, error) { | ||||
| 	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 | ||||
| // a list of all projects and their supported issuetypes | ||||
| // | ||||
|   | ||||
		Reference in New Issue
	
	Block a user