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 HeadBranch *string `json:"head_branch,omitempty"`
32 HeadSHA *string `json:"head_sha,omitempty"`
33 URL *string `json:"url,omitempty"`
34 HTMLURL *string `json:"html_url,omitempty"`
35 Status *string `json:"status,omitempty"`
36 Conclusion *string `json:"conclusion,omitempty"`
37 CreatedAt *Timestamp `json:"created_at,omitempty"`
38 StartedAt *Timestamp `json:"started_at,omitempty"`
39 CompletedAt *Timestamp `json:"completed_at,omitempty"`
40 Name *string `json:"name,omitempty"`
41 Steps []*TaskStep `json:"steps,omitempty"`
42 CheckRunURL *string `json:"check_run_url,omitempty"`
43
44 Labels []string `json:"labels,omitempty"`
45 RunnerID *int64 `json:"runner_id,omitempty"`
46 RunnerName *string `json:"runner_name,omitempty"`
47 RunnerGroupID *int64 `json:"runner_group_id,omitempty"`
48 RunnerGroupName *string `json:"runner_group_name,omitempty"`
49 RunAttempt *int64 `json:"run_attempt,omitempty"`
50 WorkflowName *string `json:"workflow_name,omitempty"`
51 }
52
53
54 type Jobs struct {
55 TotalCount *int `json:"total_count,omitempty"`
56 Jobs []*WorkflowJob `json:"jobs,omitempty"`
57 }
58
59
60 type ListWorkflowJobsOptions struct {
61
62
63
64
65
66
67 Filter string `url:"filter,omitempty"`
68 ListOptions
69 }
70
71
72
73
74 func (s *ActionsService) ListWorkflowJobs(ctx context.Context, owner, repo string, runID int64, opts *ListWorkflowJobsOptions) (*Jobs, *Response, error) {
75 u := fmt.Sprintf("repos/%s/%s/actions/runs/%v/jobs", owner, repo, runID)
76 u, err := addOptions(u, opts)
77 if err != nil {
78 return nil, nil, err
79 }
80
81 req, err := s.client.NewRequest("GET", u, nil)
82 if err != nil {
83 return nil, nil, err
84 }
85
86 jobs := new(Jobs)
87 resp, err := s.client.Do(ctx, req, &jobs)
88 if err != nil {
89 return nil, resp, err
90 }
91
92 return jobs, resp, nil
93 }
94
95
96
97
98 func (s *ActionsService) GetWorkflowJobByID(ctx context.Context, owner, repo string, jobID int64) (*WorkflowJob, *Response, error) {
99 u := fmt.Sprintf("repos/%v/%v/actions/jobs/%v", owner, repo, jobID)
100
101 req, err := s.client.NewRequest("GET", u, nil)
102 if err != nil {
103 return nil, nil, err
104 }
105
106 job := new(WorkflowJob)
107 resp, err := s.client.Do(ctx, req, job)
108 if err != nil {
109 return nil, resp, err
110 }
111
112 return job, resp, nil
113 }
114
115
116
117
118 func (s *ActionsService) GetWorkflowJobLogs(ctx context.Context, owner, repo string, jobID int64, followRedirects bool) (*url.URL, *Response, error) {
119 u := fmt.Sprintf("repos/%v/%v/actions/jobs/%v/logs", owner, repo, jobID)
120
121 resp, err := s.client.roundTripWithOptionalFollowRedirect(ctx, u, followRedirects)
122 if err != nil {
123 return nil, nil, err
124 }
125 defer resp.Body.Close()
126
127 if resp.StatusCode != http.StatusFound {
128 return nil, newResponse(resp), fmt.Errorf("unexpected status code: %s", resp.Status)
129 }
130
131 parsedURL, err := url.Parse(resp.Header.Get("Location"))
132 return parsedURL, newResponse(resp), err
133 }
134
View as plain text