mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-07-03 00:27:05 +02:00
Merge pull request #104 from shdunning/ExpandProjects
adds ability to list projects with query params
This commit is contained in:
19
project.go
19
project.go
@ -2,6 +2,8 @@ package jira
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/google/go-querystring/query"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProjectService handles projects for the JIRA instance / API.
|
// ProjectService handles projects for the JIRA instance / API.
|
||||||
@ -21,6 +23,7 @@ type ProjectList []struct {
|
|||||||
AvatarUrls AvatarUrls `json:"avatarUrls" structs:"avatarUrls"`
|
AvatarUrls AvatarUrls `json:"avatarUrls" structs:"avatarUrls"`
|
||||||
ProjectTypeKey string `json:"projectTypeKey" structs:"projectTypeKey"`
|
ProjectTypeKey string `json:"projectTypeKey" structs:"projectTypeKey"`
|
||||||
ProjectCategory ProjectCategory `json:"projectCategory,omitempty" structs:"projectsCategory,omitempty"`
|
ProjectCategory ProjectCategory `json:"projectCategory,omitempty" structs:"projectsCategory,omitempty"`
|
||||||
|
IssueTypes []IssueType `json:"issueTypes,omitempty" structs:"issueTypes,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProjectCategory represents a single project category
|
// ProjectCategory represents a single project category
|
||||||
@ -73,12 +76,28 @@ type ProjectComponent struct {
|
|||||||
//
|
//
|
||||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getAllProjects
|
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getAllProjects
|
||||||
func (s *ProjectService) GetList() (*ProjectList, *Response, error) {
|
func (s *ProjectService) GetList() (*ProjectList, *Response, error) {
|
||||||
|
return s.ListWithOptions(&GetQueryOptions{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetList gets all projects form JIRA with optional query params, like &GetQueryOptions{Expand: "issueTypes"} to get
|
||||||
|
// a list of all projects and their supported issuetypes
|
||||||
|
//
|
||||||
|
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getAllProjects
|
||||||
|
func (s *ProjectService) ListWithOptions(options *GetQueryOptions) (*ProjectList, *Response, error) {
|
||||||
apiEndpoint := "rest/api/2/project"
|
apiEndpoint := "rest/api/2/project"
|
||||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options != nil {
|
||||||
|
q, err := query.Values(options)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
req.URL.RawQuery = q.Encode()
|
||||||
|
}
|
||||||
|
|
||||||
projectList := new(ProjectList)
|
projectList := new(ProjectList)
|
||||||
resp, err := s.client.Do(req, projectList)
|
resp, err := s.client.Do(req, projectList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -31,6 +31,31 @@ func TestProjectService_GetList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProjectService_ListWithOptions(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
testAPIEdpoint := "/rest/api/2/project"
|
||||||
|
|
||||||
|
raw, err := ioutil.ReadFile("./mocks/all_projects.json")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err.Error())
|
||||||
|
}
|
||||||
|
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
testMethod(t, r, "GET")
|
||||||
|
testRequestURL(t, r, "/rest/api/2/project?expand=issueTypes")
|
||||||
|
fmt.Fprint(w, string(raw))
|
||||||
|
})
|
||||||
|
|
||||||
|
projects, _, err := testClient.Project.ListWithOptions(&GetQueryOptions{Expand: "issueTypes"})
|
||||||
|
if projects == nil {
|
||||||
|
t.Error("Expected project list. Project list is nil")
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error given: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestProjectService_Get(t *testing.T) {
|
func TestProjectService_Get(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
Reference in New Issue
Block a user