2019-10-13 18:56:07 +02:00
|
|
|
package jira
|
|
|
|
|
2019-10-17 07:35:19 +02:00
|
|
|
import (
|
2020-05-03 09:38:32 -04:00
|
|
|
"context"
|
2019-10-17 07:35:19 +02:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
)
|
2019-10-13 19:11:10 +02:00
|
|
|
|
2020-05-14 17:18:31 +02:00
|
|
|
// IssueLinkTypeService handles issue link types for the Jira instance / API.
|
2019-10-13 18:56:07 +02:00
|
|
|
//
|
2020-05-14 17:18:31 +02:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-group-Issue-link-types
|
2019-10-13 18:56:07 +02:00
|
|
|
type IssueLinkTypeService struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
2020-05-14 17:18:31 +02:00
|
|
|
// GetListWithContext gets all of the issue link types from Jira.
|
2019-10-13 18:56:07 +02:00
|
|
|
//
|
2020-05-14 17:18:31 +02:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issueLinkType-get
|
2020-05-03 09:38:32 -04:00
|
|
|
func (s *IssueLinkTypeService) GetListWithContext(ctx context.Context) ([]IssueLinkType, *Response, error) {
|
2019-10-13 18:56:07 +02:00
|
|
|
apiEndpoint := "rest/api/2/issueLinkType"
|
2020-05-03 09:38:32 -04:00
|
|
|
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
2019-10-13 18:56:07 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
linkTypeList := []IssueLinkType{}
|
|
|
|
resp, err := s.client.Do(req, &linkTypeList)
|
|
|
|
if err != nil {
|
|
|
|
return nil, resp, NewJiraError(resp, err)
|
|
|
|
}
|
|
|
|
return linkTypeList, resp, nil
|
|
|
|
}
|
2019-10-13 19:11:10 +02:00
|
|
|
|
2020-05-03 09:38:32 -04:00
|
|
|
// GetList wraps GetListWithContext using the background context.
|
|
|
|
func (s *IssueLinkTypeService) GetList() ([]IssueLinkType, *Response, error) {
|
|
|
|
return s.GetListWithContext(context.Background())
|
|
|
|
}
|
|
|
|
|
2020-05-14 17:18:31 +02:00
|
|
|
// GetWithContext gets info of a specific issue link type from Jira.
|
2019-10-13 19:11:10 +02:00
|
|
|
//
|
2020-05-14 17:18:31 +02:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issueLinkType-issueLinkTypeId-get
|
2020-05-03 09:38:32 -04:00
|
|
|
func (s *IssueLinkTypeService) GetWithContext(ctx context.Context, ID string) (*IssueLinkType, *Response, error) {
|
2019-10-13 19:11:10 +02:00
|
|
|
apiEndPoint := fmt.Sprintf("rest/api/2/issueLinkType/%s", ID)
|
2020-05-03 09:38:32 -04:00
|
|
|
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndPoint, nil)
|
2019-10-13 19:11:10 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
linkType := new(IssueLinkType)
|
|
|
|
resp, err := s.client.Do(req, linkType)
|
|
|
|
if err != nil {
|
|
|
|
return nil, resp, NewJiraError(resp, err)
|
|
|
|
}
|
|
|
|
return linkType, resp, nil
|
|
|
|
}
|
2019-10-17 07:35:19 +02:00
|
|
|
|
2020-05-03 09:38:32 -04:00
|
|
|
// Get wraps GetWithContext using the background context.
|
|
|
|
func (s *IssueLinkTypeService) Get(ID string) (*IssueLinkType, *Response, error) {
|
|
|
|
return s.GetWithContext(context.Background(), ID)
|
|
|
|
}
|
|
|
|
|
2020-05-14 17:18:31 +02:00
|
|
|
// CreateWithContext creates an issue link type in Jira.
|
2019-10-17 07:35:19 +02:00
|
|
|
//
|
2020-05-14 17:18:31 +02:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issueLinkType-post
|
2020-05-03 09:38:32 -04:00
|
|
|
func (s *IssueLinkTypeService) CreateWithContext(ctx context.Context, linkType *IssueLinkType) (*IssueLinkType, *Response, error) {
|
2019-10-17 07:35:19 +02:00
|
|
|
apiEndpoint := "/rest/api/2/issueLinkType"
|
2020-05-03 09:38:32 -04:00
|
|
|
req, err := s.client.NewRequestWithContext(ctx, "POST", apiEndpoint, linkType)
|
2019-10-17 07:35:19 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.client.Do(req, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
responseLinkType := new(IssueLinkType)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
data, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
style: Fix staticcheck (static analysis) errors for this library (#283)
* style: Fix staticcheck errors for "error strings should not be capitalized (ST1005)"
staticcheck is a static analysis tool for go.
It reports several "error strings should not be capitalized (ST1005)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "printf-style function with dynamic format ... (SA1006)"
staticcheck is a static analysis tool for go.
It reports several "printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "type X is unused (U1000)"
staticcheck is a static analysis tool for go.
It reports several "type X is unused (U1000)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "should use X instead (S1003 & SA6005)"
staticcheck is a static analysis tool for go.
It reports several
- should use !bytes.Contains(b, []byte(`"password":"bar"`)) instead (S1003)
- should use strings.EqualFold instead (SA6005)
messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "unnecessary use of fmt.Sprintf (S1039)"
staticcheck is a static analysis tool for go.
It report several "unnecessary use of fmt.Sprintf (S1039)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "this value of X is never used (SA4006)"
staticcheck is a static analysis tool for go.
It report several "this value of X is never used (SA4006)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "redundant return statement (S1023)"
staticcheck is a static analysis tool for go.
It report several "redundant return statement (S1023)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "possible nil pointer dereference (SA5011)"
staticcheck is a static analysis tool for go.
It report several
file.go:Line:character: possible nil pointer dereference (SA5011)
file.go:Line:character: this check suggests that the pointer can be nil
messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "this value of X is never used (SA4006)"
staticcheck is a static analysis tool for go.
It report several "this value of X is never used (SA4006)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
2020-05-02 23:08:01 +02:00
|
|
|
e := fmt.Errorf("could not read the returned data")
|
2019-10-17 07:35:19 +02:00
|
|
|
return nil, resp, NewJiraError(resp, e)
|
|
|
|
}
|
|
|
|
err = json.Unmarshal(data, responseLinkType)
|
|
|
|
if err != nil {
|
style: Fix staticcheck (static analysis) errors for this library (#283)
* style: Fix staticcheck errors for "error strings should not be capitalized (ST1005)"
staticcheck is a static analysis tool for go.
It reports several "error strings should not be capitalized (ST1005)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "printf-style function with dynamic format ... (SA1006)"
staticcheck is a static analysis tool for go.
It reports several "printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "type X is unused (U1000)"
staticcheck is a static analysis tool for go.
It reports several "type X is unused (U1000)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "should use X instead (S1003 & SA6005)"
staticcheck is a static analysis tool for go.
It reports several
- should use !bytes.Contains(b, []byte(`"password":"bar"`)) instead (S1003)
- should use strings.EqualFold instead (SA6005)
messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "unnecessary use of fmt.Sprintf (S1039)"
staticcheck is a static analysis tool for go.
It report several "unnecessary use of fmt.Sprintf (S1039)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "this value of X is never used (SA4006)"
staticcheck is a static analysis tool for go.
It report several "this value of X is never used (SA4006)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "redundant return statement (S1023)"
staticcheck is a static analysis tool for go.
It report several "redundant return statement (S1023)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "possible nil pointer dereference (SA5011)"
staticcheck is a static analysis tool for go.
It report several
file.go:Line:character: possible nil pointer dereference (SA5011)
file.go:Line:character: this check suggests that the pointer can be nil
messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "this value of X is never used (SA4006)"
staticcheck is a static analysis tool for go.
It report several "this value of X is never used (SA4006)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
2020-05-02 23:08:01 +02:00
|
|
|
e := fmt.Errorf("could no unmarshal the data into struct")
|
2019-10-17 07:35:19 +02:00
|
|
|
return nil, resp, NewJiraError(resp, e)
|
|
|
|
}
|
|
|
|
return linkType, resp, nil
|
|
|
|
}
|
2019-10-18 08:51:15 +02:00
|
|
|
|
2020-05-03 09:38:32 -04:00
|
|
|
// Create wraps CreateWithContext using the background context.
|
|
|
|
func (s *IssueLinkTypeService) Create(linkType *IssueLinkType) (*IssueLinkType, *Response, error) {
|
|
|
|
return s.CreateWithContext(context.Background(), linkType)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateWithContext updates an issue link type. The issue is found by key.
|
2019-10-18 08:51:15 +02:00
|
|
|
//
|
2020-05-14 17:18:31 +02:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issueLinkType-issueLinkTypeId-put
|
2020-05-03 09:38:32 -04:00
|
|
|
func (s *IssueLinkTypeService) UpdateWithContext(ctx context.Context, linkType *IssueLinkType) (*IssueLinkType, *Response, error) {
|
2019-10-18 08:51:15 +02:00
|
|
|
apiEndpoint := fmt.Sprintf("rest/api/2/issueLinkType/%s", linkType.ID)
|
2020-05-03 09:38:32 -04:00
|
|
|
req, err := s.client.NewRequestWithContext(ctx, "PUT", apiEndpoint, linkType)
|
2019-10-18 08:51:15 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
resp, err := s.client.Do(req, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, resp, NewJiraError(resp, err)
|
|
|
|
}
|
|
|
|
ret := *linkType
|
|
|
|
return &ret, resp, nil
|
|
|
|
}
|
2019-10-18 08:59:02 +02:00
|
|
|
|
2020-05-03 09:38:32 -04:00
|
|
|
// Update wraps UpdateWithContext using the background context.
|
|
|
|
func (s *IssueLinkTypeService) Update(linkType *IssueLinkType) (*IssueLinkType, *Response, error) {
|
|
|
|
return s.UpdateWithContext(context.Background(), linkType)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteWithContext deletes an issue link type based on provided ID.
|
2019-10-18 08:59:02 +02:00
|
|
|
//
|
2020-05-14 17:18:31 +02:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issueLinkType-issueLinkTypeId-delete
|
2020-05-03 09:38:32 -04:00
|
|
|
func (s *IssueLinkTypeService) DeleteWithContext(ctx context.Context, ID string) (*Response, error) {
|
2019-10-18 08:59:02 +02:00
|
|
|
apiEndpoint := fmt.Sprintf("rest/api/2/issueLinkType/%s", ID)
|
2020-05-03 09:38:32 -04:00
|
|
|
req, err := s.client.NewRequestWithContext(ctx, "DELETE", apiEndpoint, nil)
|
2019-10-18 08:59:02 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.client.Do(req, nil)
|
|
|
|
return resp, err
|
|
|
|
}
|
2020-05-03 09:38:32 -04:00
|
|
|
|
|
|
|
// Delete wraps DeleteWithContext using the background context.
|
|
|
|
func (s *IssueLinkTypeService) Delete(ID string) (*Response, error) {
|
|
|
|
return s.DeleteWithContext(context.Background(), ID)
|
|
|
|
}
|