forked from buildkite/go-buildkite
/
jobs.go
66 lines (56 loc) · 2.06 KB
/
jobs.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
package buildkite
import (
"fmt"
)
// JobsService handles communication with the job related
// methods of the buildkite API.
//
// buildkite API docs: https://buildkite.com/docs/api/jobs
type JobsService struct {
client *Client
}
// Job represents a job run during a build in buildkite
type Job struct {
ID *string `json:"id,omitempty"`
Type *string `json:"type,omitempty"`
Name *string `json:"name,omitempty"`
State *string `json:"state,omitempty"`
LogsURL *string `json:"logs_url,omitempty"`
RawLogsURL *string `json:"raw_log_url,omitempty"`
Command *string `json:"command,omitempty"`
ExitStatus *int `json:"exit_status,omitempty"`
ArtifactPaths *string `json:"artifact_paths,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
ScheduledAt *Timestamp `json:"scheduled_at,omitempty"`
RunnableAt *Timestamp `json:"runnable_at,omitempty"`
StartedAt *Timestamp `json:"started_at,omitempty"`
FinishedAt *Timestamp `json:"finished_at,omitempty"`
Agent Agent `json:"agent,omitempty"`
AgentQueryRules []string `json:"agent_query_rules,omitempty"`
WebURL string `json:"web_url"`
}
// JobUnblockOptions specifies the optional parameters to UnblockJob
type JobUnblockOptions struct {
Fields map[string]string `json:"fields,omitempty"`
}
// UnblockJob - unblock a job
//
// buildkite API docs: https://buildkite.com/docs/apis/rest-api/jobs#unblock-a-job
func (js *JobsService) UnblockJob(org string, pipeline string, buildNumber string, jobID string, opt *JobUnblockOptions) (*Job, *Response, error) {
var u string
u = fmt.Sprintf("v2/organizations/%s/pipelines/%s/builds/%s/jobs/%s/unblock", org, pipeline, buildNumber, jobID)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := js.client.NewRequest("PUT", u, opt)
if err != nil {
return nil, nil, err
}
job := new(Job)
resp, err := js.client.Do(req, job)
if err != nil {
return nil, resp, err
}
return job, resp, err
}