2018-06-13 03:27:42 +02:00
|
|
|
package jira
|
|
|
|
|
2020-05-03 15:38:32 +02:00
|
|
|
import "context"
|
|
|
|
|
2020-05-14 17:18:31 +02:00
|
|
|
// FieldService handles fields for the Jira instance / API.
|
2018-06-13 03:27:42 +02:00
|
|
|
//
|
2020-05-14 17:18:31 +02:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-Field
|
2018-06-13 03:27:42 +02:00
|
|
|
type FieldService struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
2020-05-14 17:18:31 +02:00
|
|
|
// Field represents a field of a Jira issue.
|
2018-06-13 03:27:42 +02:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2021-01-09 11:02:16 +02:00
|
|
|
// FieldSchema represents a schema of a Jira field.
|
|
|
|
// Documentation: https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-fields/#api-rest-api-2-field-get
|
2018-06-13 03:27:42 +02:00
|
|
|
type FieldSchema struct {
|
2021-01-09 11:02:16 +02:00
|
|
|
Type string `json:"type,omitempty" structs:"type,omitempty"`
|
|
|
|
Items string `json:"items,omitempty" structs:"items,omitempty"`
|
|
|
|
Custom string `json:"custom,omitempty" structs:"custom,omitempty"`
|
|
|
|
System string `json:"system,omitempty" structs:"system,omitempty"`
|
|
|
|
CustomID int64 `json:"customId,omitempty" structs:"customId,omitempty"`
|
2018-06-13 03:27:42 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 17:18:31 +02:00
|
|
|
// GetListWithContext gets all fields from Jira
|
2018-06-13 03:27:42 +02:00
|
|
|
//
|
2020-05-14 17:18:31 +02:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-field-get
|
2020-05-03 15:38:32 +02:00
|
|
|
func (s *FieldService) GetListWithContext(ctx context.Context) ([]Field, *Response, error) {
|
2018-06-13 03:27:42 +02:00
|
|
|
apiEndpoint := "rest/api/2/field"
|
2020-05-03 15:38:32 +02:00
|
|
|
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
2018-06-13 03:27:42 +02:00
|
|
|
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
|
|
|
|
}
|
2020-05-03 15:38:32 +02:00
|
|
|
|
|
|
|
// GetList wraps GetListWithContext using the background context.
|
|
|
|
func (s *FieldService) GetList() ([]Field, *Response, error) {
|
|
|
|
return s.GetListWithContext(context.Background())
|
|
|
|
}
|