1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13
14 type Workflow struct {
15 ID *int64 `json:"id,omitempty"`
16 NodeID *string `json:"node_id,omitempty"`
17 Name *string `json:"name,omitempty"`
18 Path *string `json:"path,omitempty"`
19 State *string `json:"state,omitempty"`
20 CreatedAt *Timestamp `json:"created_at,omitempty"`
21 UpdatedAt *Timestamp `json:"updated_at,omitempty"`
22 URL *string `json:"url,omitempty"`
23 HTMLURL *string `json:"html_url,omitempty"`
24 BadgeURL *string `json:"badge_url,omitempty"`
25 }
26
27
28 type Workflows struct {
29 TotalCount *int `json:"total_count,omitempty"`
30 Workflows []*Workflow `json:"workflows,omitempty"`
31 }
32
33
34 type WorkflowUsage struct {
35 Billable *WorkflowEnvironment `json:"billable,omitempty"`
36 }
37
38
39 type WorkflowEnvironment struct {
40 Ubuntu *WorkflowBill `json:"UBUNTU,omitempty"`
41 MacOS *WorkflowBill `json:"MACOS,omitempty"`
42 Windows *WorkflowBill `json:"WINDOWS,omitempty"`
43 }
44
45
46 type WorkflowBill struct {
47 TotalMS *int64 `json:"total_ms,omitempty"`
48 }
49
50
51 type CreateWorkflowDispatchEventRequest struct {
52
53
54
55 Ref string `json:"ref"`
56
57
58
59 Inputs map[string]interface{} `json:"inputs,omitempty"`
60 }
61
62
63
64
65 func (s *ActionsService) ListWorkflows(ctx context.Context, owner, repo string, opts *ListOptions) (*Workflows, *Response, error) {
66 u := fmt.Sprintf("repos/%s/%s/actions/workflows", owner, repo)
67 u, err := addOptions(u, opts)
68 if err != nil {
69 return nil, nil, err
70 }
71
72 req, err := s.client.NewRequest("GET", u, nil)
73 if err != nil {
74 return nil, nil, err
75 }
76
77 workflows := new(Workflows)
78 resp, err := s.client.Do(ctx, req, &workflows)
79 if err != nil {
80 return nil, resp, err
81 }
82
83 return workflows, resp, nil
84 }
85
86
87
88
89 func (s *ActionsService) GetWorkflowByID(ctx context.Context, owner, repo string, workflowID int64) (*Workflow, *Response, error) {
90 u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v", owner, repo, workflowID)
91
92 return s.getWorkflow(ctx, u)
93 }
94
95
96
97
98 func (s *ActionsService) GetWorkflowByFileName(ctx context.Context, owner, repo, workflowFileName string) (*Workflow, *Response, error) {
99 u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v", owner, repo, workflowFileName)
100
101 return s.getWorkflow(ctx, u)
102 }
103
104 func (s *ActionsService) getWorkflow(ctx context.Context, url string) (*Workflow, *Response, error) {
105 req, err := s.client.NewRequest("GET", url, nil)
106 if err != nil {
107 return nil, nil, err
108 }
109
110 workflow := new(Workflow)
111 resp, err := s.client.Do(ctx, req, workflow)
112 if err != nil {
113 return nil, resp, err
114 }
115
116 return workflow, resp, nil
117 }
118
119
120
121
122 func (s *ActionsService) GetWorkflowUsageByID(ctx context.Context, owner, repo string, workflowID int64) (*WorkflowUsage, *Response, error) {
123 u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/timing", owner, repo, workflowID)
124
125 return s.getWorkflowUsage(ctx, u)
126 }
127
128
129
130
131 func (s *ActionsService) GetWorkflowUsageByFileName(ctx context.Context, owner, repo, workflowFileName string) (*WorkflowUsage, *Response, error) {
132 u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/timing", owner, repo, workflowFileName)
133
134 return s.getWorkflowUsage(ctx, u)
135 }
136
137 func (s *ActionsService) getWorkflowUsage(ctx context.Context, url string) (*WorkflowUsage, *Response, error) {
138 req, err := s.client.NewRequest("GET", url, nil)
139 if err != nil {
140 return nil, nil, err
141 }
142
143 workflowUsage := new(WorkflowUsage)
144 resp, err := s.client.Do(ctx, req, workflowUsage)
145 if err != nil {
146 return nil, resp, err
147 }
148
149 return workflowUsage, resp, nil
150 }
151
152
153
154
155 func (s *ActionsService) CreateWorkflowDispatchEventByID(ctx context.Context, owner, repo string, workflowID int64, event CreateWorkflowDispatchEventRequest) (*Response, error) {
156 u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/dispatches", owner, repo, workflowID)
157
158 return s.createWorkflowDispatchEvent(ctx, u, &event)
159 }
160
161
162
163
164 func (s *ActionsService) CreateWorkflowDispatchEventByFileName(ctx context.Context, owner, repo, workflowFileName string, event CreateWorkflowDispatchEventRequest) (*Response, error) {
165 u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/dispatches", owner, repo, workflowFileName)
166
167 return s.createWorkflowDispatchEvent(ctx, u, &event)
168 }
169
170 func (s *ActionsService) createWorkflowDispatchEvent(ctx context.Context, url string, event *CreateWorkflowDispatchEventRequest) (*Response, error) {
171 req, err := s.client.NewRequest("POST", url, event)
172 if err != nil {
173 return nil, err
174 }
175
176 return s.client.Do(ctx, req, nil)
177 }
178
179
180
181
182 func (s *ActionsService) EnableWorkflowByID(ctx context.Context, owner, repo string, workflowID int64) (*Response, error) {
183 u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/enable", owner, repo, workflowID)
184 return s.doNewPutRequest(ctx, u)
185 }
186
187
188
189
190 func (s *ActionsService) EnableWorkflowByFileName(ctx context.Context, owner, repo, workflowFileName string) (*Response, error) {
191 u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/enable", owner, repo, workflowFileName)
192 return s.doNewPutRequest(ctx, u)
193 }
194
195
196
197
198 func (s *ActionsService) DisableWorkflowByID(ctx context.Context, owner, repo string, workflowID int64) (*Response, error) {
199 u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/disable", owner, repo, workflowID)
200 return s.doNewPutRequest(ctx, u)
201 }
202
203
204
205
206 func (s *ActionsService) DisableWorkflowByFileName(ctx context.Context, owner, repo, workflowFileName string) (*Response, error) {
207 u := fmt.Sprintf("repos/%v/%v/actions/workflows/%v/disable", owner, repo, workflowFileName)
208 return s.doNewPutRequest(ctx, u)
209 }
210
211 func (s *ActionsService) doNewPutRequest(ctx context.Context, url string) (*Response, error) {
212 req, err := s.client.NewRequest("PUT", url, nil)
213 if err != nil {
214 return nil, err
215 }
216
217 return s.client.Do(ctx, req, nil)
218 }
219
View as plain text