mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-08-06 22:13:02 +02:00
feat: Add StatusCategory GetList
This commit is contained in:
2
jira.go
2
jira.go
@ -38,6 +38,7 @@ type Client struct {
|
||||
Priority *PriorityService
|
||||
Field *FieldService
|
||||
Resolution *ResolutionService
|
||||
StatusCategory *StatusCategoryService
|
||||
}
|
||||
|
||||
// NewClient returns a new JIRA API client.
|
||||
@ -77,6 +78,7 @@ func NewClient(httpClient *http.Client, baseURL string) (*Client, error) {
|
||||
c.Priority = &PriorityService{client: c}
|
||||
c.Field = &FieldService{client: c}
|
||||
c.Resolution = &ResolutionService{client: c}
|
||||
c.StatusCategory = &StatusCategoryService{client: c}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
@ -121,6 +121,9 @@ func TestNewClient_WithServices(t *testing.T) {
|
||||
if c.Resolution == nil {
|
||||
t.Error("No ResolutionService provided")
|
||||
}
|
||||
if c.StatusCategory == nil {
|
||||
t.Error("No StatusCategoryService provided")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckResponse(t *testing.T) {
|
||||
|
30
mocks/all_statuscategories.json
Normal file
30
mocks/all_statuscategories.json
Normal file
@ -0,0 +1,30 @@
|
||||
[
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/statuscategory/1",
|
||||
"id": 1,
|
||||
"key": "undefined",
|
||||
"colorName": "medium-gray",
|
||||
"name": "No Category"
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/statuscategory/2",
|
||||
"id": 2,
|
||||
"key": "new",
|
||||
"colorName": "blue-gray",
|
||||
"name": "To Do"
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/statuscategory/4",
|
||||
"id": 4,
|
||||
"key": "indeterminate",
|
||||
"colorName": "yellow",
|
||||
"name": "In Progress"
|
||||
},
|
||||
{
|
||||
"self": "https://issues.apache.org/jira/rest/api/2/statuscategory/3",
|
||||
"id": 3,
|
||||
"key": "done",
|
||||
"colorName": "green",
|
||||
"name": "Done"
|
||||
}
|
||||
]
|
@ -1,5 +1,12 @@
|
||||
package jira
|
||||
|
||||
// StatusCategoryService handles status categories for the JIRA instance / API.
|
||||
//
|
||||
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-Statuscategory
|
||||
type StatusCategoryService struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
// StatusCategory represents the category a status belongs to.
|
||||
// Those categories can be user defined in every JIRA instance.
|
||||
type StatusCategory struct {
|
||||
@ -17,3 +24,21 @@ const (
|
||||
StatusCategoryToDo = "new"
|
||||
StatusCategoryUndefined = "undefined"
|
||||
)
|
||||
|
||||
// GetList gets all status categories from JIRA
|
||||
//
|
||||
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-statuscategory-get
|
||||
func (s *StatusCategoryService) GetList() ([]StatusCategory, *Response, error) {
|
||||
apiEndpoint := "rest/api/2/statuscategory"
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
statusCategoryList := []StatusCategory{}
|
||||
resp, err := s.client.Do(req, &statusCategoryList)
|
||||
if err != nil {
|
||||
return nil, resp, NewJiraError(resp, err)
|
||||
}
|
||||
return statusCategoryList, resp, nil
|
||||
}
|
||||
|
32
statuscategory_test.go
Normal file
32
statuscategory_test.go
Normal file
@ -0,0 +1,32 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStatusCategoryService_GetList(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
testAPIEdpoint := "/rest/api/2/statuscategory"
|
||||
|
||||
raw, err := ioutil.ReadFile("./mocks/all_statuscategories.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, testAPIEdpoint)
|
||||
fmt.Fprint(w, string(raw))
|
||||
})
|
||||
|
||||
statusCategory, _, err := testClient.StatusCategory.GetList()
|
||||
if statusCategory == nil {
|
||||
t.Error("Expected statusCategory list. StatusCategory list is nil")
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user