-
Notifications
You must be signed in to change notification settings - Fork 30
/
task.go
84 lines (66 loc) · 2.27 KB
/
task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package jira
import (
"context"
"encoding/json"
"fmt"
"net/http"
)
type TaskService struct{ client *Client }
type TaskScheme struct {
Self string `json:"self"`
ID string `json:"id"`
Description string `json:"description"`
Status string `json:"status"`
Result string `json:"result"`
SubmittedBy int `json:"submittedBy"`
Progress int `json:"progress"`
ElapsedRuntime int `json:"elapsedRuntime"`
Submitted int64 `json:"submitted"`
Started int64 `json:"started"`
Finished int64 `json:"finished"`
LastUpdate int64 `json:"lastUpdate"`
}
// Returns the status of a long-running asynchronous task.
// When a task has finished, this operation returns the JSON blob applicable to the task.
// See the documentation of the operation that created the task for details.
// Task details are not permanently retained.
// As of September 2019, details are retained for 14 days although this period may change without notice.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/tasks#get-task
func (t *TaskService) Get(ctx context.Context, taskID string) (result *TaskScheme, response *Response, err error) {
if len(taskID) == 0 {
return nil, nil, fmt.Errorf("error, please provide a valid taskID value")
}
var endpoint = fmt.Sprintf("rest/api/3/task/%v", taskID)
request, err := t.client.newRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return
}
request.Header.Set("Accept", "application/json")
response, err = t.client.Do(request)
if err != nil {
return
}
result = new(TaskScheme)
if err = json.Unmarshal(response.BodyAsBytes, &result); err != nil {
return
}
return
}
// Cancels a task.
// Docs: https://app.gitbook.com/@ctreminiom/s/go-atlassian/jira-software-cloud/tasks#cancel-task
func (t *TaskService) Cancel(ctx context.Context, taskID string) (response *Response, err error) {
if len(taskID) == 0 {
return nil, fmt.Errorf("error, please provide a valid taskID value")
}
var endpoint = fmt.Sprintf("rest/api/3/task/%v/cancel", taskID)
request, err := t.client.newRequest(ctx, http.MethodPost, endpoint, nil)
if err != nil {
return
}
request.Header.Set("Accept", "application/json")
response, err = t.client.Do(request)
if err != nil {
return
}
return
}