Skip to content

Commit

Permalink
feat: Add StatusCategory GetList
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiht committed Jun 26, 2018
1 parent 6223ddd commit 049a756
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
2 changes: 2 additions & 0 deletions jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Client struct {
Priority *PriorityService
Field *FieldService
Resolution *ResolutionService
StatusCategory *StatusCategoryService
}

// NewClient returns a new JIRA API client.
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions jira_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 30 additions & 0 deletions mocks/all_statuscategories.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
25 changes: 25 additions & 0 deletions statuscategory.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 changes: 32 additions & 0 deletions statuscategory_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 049a756

Please sign in to comment.