mirror of
https://github.com/interviewstreet/go-jira.git
synced 2024-11-28 08:39:03 +02:00
Add support for 'fields' API
This commit is contained in:
parent
ab73d577bb
commit
433e65c477
44
field.go
Normal file
44
field.go
Normal file
@ -0,0 +1,44 @@
|
||||
package jira
|
||||
|
||||
// PriorityService handles priorities for the JIRA instance / API.
|
||||
//
|
||||
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-Priority
|
||||
type FieldService struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
// Priority represents a priority of a JIRA issue.
|
||||
// Typical types are "Normal", "Moderate", "Urgent", ...
|
||||
type Field struct {
|
||||
ID string `json:"id,omitempty" structs:"id,omitempty"`
|
||||
Key string `json:"key,omitempty" structs:"key,omitempty"`
|
||||
Name string `json:"name,omitempty" structs:"name,omitempty"`
|
||||
Custom bool `json:"custom,omitempty" structs:"custom,omitempty"`
|
||||
Navigable bool `json:"navigable,omitempty" structs:"navigable,omitempty"`
|
||||
Searchable bool `json:"searchable,omitempty" structs:"searchable,omitempty"`
|
||||
ClauseNames []string `json:"clauseNames,omitempty" structs:"clauseNames,omitempty"`
|
||||
Schema FieldSchema `json:"schema,omitempty" structs:"schema,omitempty"`
|
||||
}
|
||||
|
||||
type FieldSchema struct {
|
||||
Type string `json:"type,omitempty" structs:"type,omitempty"`
|
||||
System string `json:"system,omitempty" structs:"system,omitempty"`
|
||||
}
|
||||
|
||||
// GetList gets all fields from JIRA
|
||||
//
|
||||
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-priority-get
|
||||
func (s *FieldService) GetList() ([]Field, *Response, error) {
|
||||
apiEndpoint := "rest/api/2/field"
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
fieldList := []Field{}
|
||||
resp, err := s.client.Do(req, &fieldList)
|
||||
if err != nil {
|
||||
return nil, resp, NewJiraError(resp, err)
|
||||
}
|
||||
return fieldList, resp, nil
|
||||
}
|
32
field_test.go
Normal file
32
field_test.go
Normal file
@ -0,0 +1,32 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFieldService_GetList(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
testAPIEdpoint := "/rest/api/2/field"
|
||||
|
||||
raw, err := ioutil.ReadFile("./mocks/all_fields.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))
|
||||
})
|
||||
|
||||
fields, _, err := testClient.Field.GetList()
|
||||
if fields == nil {
|
||||
t.Error("Expected priority list. Priority list is nil")
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
2
jira.go
2
jira.go
@ -36,6 +36,7 @@ type Client struct {
|
||||
Group *GroupService
|
||||
Version *VersionService
|
||||
Priority *PriorityService
|
||||
Field *FieldService
|
||||
}
|
||||
|
||||
// NewClient returns a new JIRA API client.
|
||||
@ -73,6 +74,7 @@ func NewClient(httpClient *http.Client, baseURL string) (*Client, error) {
|
||||
c.Group = &GroupService{client: c}
|
||||
c.Version = &VersionService{client: c}
|
||||
c.Priority = &PriorityService{client: c}
|
||||
c.Field = &FieldService{client: c}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
33
mocks/all_fields.json
Normal file
33
mocks/all_fields.json
Normal file
@ -0,0 +1,33 @@
|
||||
[
|
||||
{
|
||||
"id": "description",
|
||||
"name": "Description",
|
||||
"custom": false,
|
||||
"orderable": true,
|
||||
"navigable": true,
|
||||
"searchable": true,
|
||||
"clauseNames": [
|
||||
"description"
|
||||
],
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"system": "description"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "summary",
|
||||
"key": "summary",
|
||||
"name": "Summary",
|
||||
"custom": false,
|
||||
"orderable": true,
|
||||
"navigable": true,
|
||||
"searchable": true,
|
||||
"clauseNames": [
|
||||
"summary"
|
||||
],
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"system": "summary"
|
||||
}
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue
Block a user