mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-08-06 22:13:02 +02:00
feat(context): Add support for context package
This commit is contained in:
34
version.go
34
version.go
@ -1,6 +1,7 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@ -27,12 +28,12 @@ type Version struct {
|
||||
StartDate string `json:"startDate,omitempty" structs:"startDate,omitempty"`
|
||||
}
|
||||
|
||||
// Get gets version info from JIRA
|
||||
// GetWithContext gets version info from JIRA
|
||||
//
|
||||
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-version-id-get
|
||||
func (s *VersionService) Get(versionID int) (*Version, *Response, error) {
|
||||
func (s *VersionService) GetWithContext(ctx context.Context, versionID int) (*Version, *Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("/rest/api/2/version/%v", versionID)
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -45,12 +46,17 @@ func (s *VersionService) Get(versionID int) (*Version, *Response, error) {
|
||||
return version, resp, nil
|
||||
}
|
||||
|
||||
// Create creates a version in JIRA.
|
||||
// Get wraps GetWithContext using the background context.
|
||||
func (s *VersionService) Get(versionID int) (*Version, *Response, error) {
|
||||
return s.GetWithContext(context.Background(), versionID)
|
||||
}
|
||||
|
||||
// CreateWithContext creates a version in JIRA.
|
||||
//
|
||||
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-version-post
|
||||
func (s *VersionService) Create(version *Version) (*Version, *Response, error) {
|
||||
func (s *VersionService) CreateWithContext(ctx context.Context, version *Version) (*Version, *Response, error) {
|
||||
apiEndpoint := "/rest/api/2/version"
|
||||
req, err := s.client.NewRequest("POST", apiEndpoint, version)
|
||||
req, err := s.client.NewRequestWithContext(ctx, "POST", apiEndpoint, version)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -75,12 +81,17 @@ func (s *VersionService) Create(version *Version) (*Version, *Response, error) {
|
||||
return responseVersion, resp, nil
|
||||
}
|
||||
|
||||
// Update updates a version from a JSON representation.
|
||||
// Create wraps CreateWithContext using the background context.
|
||||
func (s *VersionService) Create(version *Version) (*Version, *Response, error) {
|
||||
return s.CreateWithContext(context.Background(), version)
|
||||
}
|
||||
|
||||
// UpdateWithContext updates a version from a JSON representation.
|
||||
//
|
||||
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-version-id-put
|
||||
func (s *VersionService) Update(version *Version) (*Version, *Response, error) {
|
||||
func (s *VersionService) UpdateWithContext(ctx context.Context, version *Version) (*Version, *Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("rest/api/2/version/%v", version.ID)
|
||||
req, err := s.client.NewRequest("PUT", apiEndpoint, version)
|
||||
req, err := s.client.NewRequestWithContext(ctx, "PUT", apiEndpoint, version)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -95,3 +106,8 @@ func (s *VersionService) Update(version *Version) (*Version, *Response, error) {
|
||||
ret := *version
|
||||
return &ret, resp, nil
|
||||
}
|
||||
|
||||
// Update wraps UpdateWithContext using the background context.
|
||||
func (s *VersionService) Update(version *Version) (*Version, *Response, error) {
|
||||
return s.UpdateWithContext(context.Background(), version)
|
||||
}
|
||||
|
Reference in New Issue
Block a user