2020-09-14 18:31:56 +00:00
|
|
|
package jira
|
|
|
|
|
2021-10-06 17:33:14 +00:00
|
|
|
import "context"
|
|
|
|
|
|
|
|
// ComponentService handles components for the Jira instance / API.//
|
|
|
|
// Jira API docs: https://docs.atlassian.com/software/jira/docs/api/REST/7.10.1/#api/2/component
|
2020-09-14 18:31:56 +00:00
|
|
|
type ComponentService struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
2021-10-06 17:33:14 +00:00
|
|
|
// CreateComponentOptions are passed to the ComponentService.Create function to create a new Jira component
|
2020-09-14 18:31:56 +00:00
|
|
|
type CreateComponentOptions struct {
|
|
|
|
Name string `json:"name,omitempty" structs:"name,omitempty"`
|
|
|
|
Description string `json:"description,omitempty" structs:"description,omitempty"`
|
|
|
|
Lead *User `json:"lead,omitempty" structs:"lead,omitempty"`
|
|
|
|
LeadUserName string `json:"leadUserName,omitempty" structs:"leadUserName,omitempty"`
|
|
|
|
AssigneeType string `json:"assigneeType,omitempty" structs:"assigneeType,omitempty"`
|
|
|
|
Assignee *User `json:"assignee,omitempty" structs:"assignee,omitempty"`
|
|
|
|
Project string `json:"project,omitempty" structs:"project,omitempty"`
|
|
|
|
ProjectID int `json:"projectId,omitempty" structs:"projectId,omitempty"`
|
|
|
|
}
|
|
|
|
|
2021-10-06 17:33:14 +00:00
|
|
|
// CreateWithContext creates a new Jira component based on the given options.
|
|
|
|
func (s *ComponentService) CreateWithContext(ctx context.Context, options *CreateComponentOptions) (*ProjectComponent, *Response, error) {
|
2020-09-14 18:31:56 +00:00
|
|
|
apiEndpoint := "rest/api/2/component"
|
2021-10-06 17:33:14 +00:00
|
|
|
req, err := s.client.NewRequestWithContext(ctx, "POST", apiEndpoint, options)
|
2020-09-14 18:31:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
component := new(ProjectComponent)
|
|
|
|
resp, err := s.client.Do(req, component)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, resp, NewJiraError(resp, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return component, resp, nil
|
|
|
|
}
|
2021-10-06 17:33:14 +00:00
|
|
|
|
|
|
|
// Create wraps CreateWithContext using the background context.
|
|
|
|
func (s *ComponentService) Create(options *CreateComponentOptions) (*ProjectComponent, *Response, error) {
|
|
|
|
return s.CreateWithContext(context.Background(), options)
|
|
|
|
}
|