1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 "net/http"
12 "net/url"
13 )
14
15
16 type TaskStep struct {
17 Name *string `json:"name,omitempty"`
18 Status *string `json:"status,omitempty"`
19 Conclusion *string `json:"conclusion,omitempty"`
20 Number *int64 `json:"number,omitempty"`
21 StartedAt *Timestamp `json:"started_at,omitempty"`
22 CompletedAt *Timestamp `json:"completed_at,omitempty"`
23 }
24
25
26 type WorkflowJob struct {
27 ID *int64 `json:"id,omitempty"`
28 RunID *int64 `json:"run_id,omitempty"`
29 RunURL *string `json:"run_url,omitempty"`
30 NodeID *string `json:"node_id,omitempty"`
31 HeadSHA *string `json:"head_sha,omitempty"`
32 URL *string `json:"url,omitempty"`
33 HTMLURL *string `json:"html_url,omitempty"`
34 Status *string `json:"status,omitempty"`
35 Conclusion *string `json:"conclusion,omitempty"`
36 StartedAt *Timestamp `json:"started_at,omitempty"`
37 CompletedAt *Timestamp `json:"completed_at,omitempty"`
38 Name *string `json:"name,omitempty"`
39 Steps []*TaskStep `json:"steps,omitempty"`
40 CheckRunURL *string `json:"check_run_url,omitempty"`
41
42 Labels []string `json:"labels,omitempty"`
43 RunnerID *int64 `json:"runner_id,omitempty"`
44 RunnerName *string `json:"runner_name,omitempty"`
45 RunnerGroupID *int64 `json:"runner_group_id,omitempty"`
46 RunnerGroupName *string `json:"runner_group_name,omitempty"`
47 }
48
49
50 type Jobs struct {
51 TotalCount *int `json:"total_count,omitempty"`
52 Jobs []*WorkflowJob `json:"jobs,omitempty"`
53 }
54
55
56 type ListWorkflowJobsOptions struct {
57
58
59
60
61
62
63 Filter string `url:"filter,omitempty"`
64 ListOptions
65 }
66
67
68
69
70 func (s *ActionsService) ListWorkflowJobs(ctx context.Context, owner, repo string, runID int64, opts *ListWorkflowJobsOptions) (*Jobs, *Response, error) {
71 u := fmt.Sprintf("repos/%s/%s/actions/runs/%v/jobs", owner, repo, runID)
72 u, err := addOptions(u, opts)
73 if err != nil {
74 return nil, nil, err
75 }
76
77 req, err := s.client.NewRequest("GET", u, nil)
78 if err != nil {
79 return nil, nil, err
80 }
81
82 jobs := new(Jobs)
83 resp, err := s.client.Do(ctx, req, &jobs)
84 if err != nil {
85 return nil, resp, err
86 }
87
88 return jobs, resp, nil
89 }
90
91
92
93
94 func (s *ActionsService) GetWorkflowJobByID(ctx context.Context, owner, repo string, jobID int64) (*WorkflowJob, *Response, error) {
95 u := fmt.Sprintf("repos/%v/%v/actions/jobs/%v", owner, repo, jobID)
96
97 req, err := s.client.NewRequest("GET", u, nil)
98 if err != nil {
99 return nil, nil, err
100 }
101
102 job := new(WorkflowJob)
103 resp, err := s.client.Do(ctx, req, job)
104 if err != nil {
105 return nil, resp, err
106 }
107
108 return job, resp, nil
109 }
110
111
112
113
114 func (s *ActionsService) GetWorkflowJobLogs(ctx context.Context, owner, repo string, jobID int64, followRedirects bool) (*url.URL, *Response, error) {
115 u := fmt.Sprintf("repos/%v/%v/actions/jobs/%v/logs", owner, repo, jobID)
116
117 resp, err := s.client.roundTripWithOptionalFollowRedirect(ctx, u, followRedirects)
118 if err != nil {
119 return nil, nil, err
120 }
121 defer resp.Body.Close()
122
123 if resp.StatusCode != http.StatusFound {
124 return nil, newResponse(resp), fmt.Errorf("unexpected status code: %s", resp.Status)
125 }
126
127 parsedURL, err := url.Parse(resp.Header.Get("Location"))
128 return parsedURL, newResponse(resp), err
129 }
130
View as plain text