1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2024-11-28 08:39:03 +02:00
go-jira/status.go

66 lines
2.0 KiB
Go
Raw Normal View History

2019-08-19 04:59:05 +02:00
package jira
import "context"
// StatusService handles staties for the Jira instance / API.
2019-08-19 04:59:05 +02:00
//
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-group-Workflow-statuses
2019-08-19 04:59:05 +02:00
type StatusService struct {
client *Client
}
// Status represents the current status of a Jira issue.
2019-08-19 04:59:05 +02:00
// Typical status are "Open", "In Progress", "Closed", ...
// Status can be user defined in every Jira instance.
2019-08-19 04:59:05 +02:00
type Status struct {
Self string `json:"self" structs:"self"`
Description string `json:"description" structs:"description"`
IconURL string `json:"iconUrl" structs:"iconUrl"`
Name string `json:"name" structs:"name"`
ID string `json:"id" structs:"id"`
StatusCategory StatusCategory `json:"statusCategory" structs:"statusCategory"`
}
// GetAllStatusesWithContext returns a list of all statuses associated with workflows.
2019-08-19 04:59:05 +02:00
//
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-status-get
func (s *StatusService) GetAllStatusesWithContext(ctx context.Context) ([]Status, *Response, error) {
2019-08-19 04:59:05 +02:00
apiEndpoint := "rest/api/2/status"
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
2019-08-19 04:59:05 +02:00
if err != nil {
return nil, nil, err
}
statusList := []Status{}
resp, err := s.client.Do(req, &statusList)
if err != nil {
return nil, resp, NewJiraError(resp, err)
}
return statusList, resp, nil
}
// GetAllStatuses wraps GetAllStatusesWithContext using the background context.
func (s *StatusService) GetAllStatuses() ([]Status, *Response, error) {
return s.GetAllStatusesWithContext(context.Background())
}
2021-09-04 15:36:50 +02:00
func (s *StatusService) Get(id string) (*Status, *Response, error) {
apiEndpoint := "rest/api/2/status/" + id
req, err := s.client.NewRequestWithContext(context.Background(), "GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
var status Status
resp, err := s.client.Do(req, &status)
if err != nil {
return nil, resp, NewJiraError(resp, err)
}
return &status, resp, nil
}