rickub/clipublic Fork 0
main
Commits
Clone
git clone https://git.rickub.com/rickub/cli.git
git clone ssh://git@rickub.com/rickub/cli.git
models.go · 367 lines · 10.1 KBGo Blame HistoryRaw
Initial import of the rickub CLI as a standalone public project 1a1d430 Olivier Girardot 10h ago1package api
2
3// Types mirror the schemas of the rickub JSON API (`/api/v1`). Clients must
4// ignore unknown JSON fields (additive changes may appear within v1), which
5// json unmarshalling does by default.
6
7// User is the identity that owns the presented PAT.
8type User struct {
9 Handle string `json:"handle"`
10 DisplayName string `json:"display_name"`
11 Email string `json:"email"`
12 EmailVerified bool `json:"email_verified"`
13 Superadmin bool `json:"superadmin"`
14}
15
16// Repo is a repository.
17type Repo struct {
18 Owner string `json:"owner"`
19 Name string `json:"name"`
20 FullName string `json:"full_name"`
21 Visibility string `json:"visibility"`
22 Description string `json:"description"`
23 DefaultBranch string `json:"default_branch"`
24 Fork bool `json:"fork"`
25 ForkedFromOwner string `json:"forked_from_owner"`
26 ForkedFromName string `json:"forked_from_name"`
27 CreatedAt string `json:"created_at"`
28 URL string `json:"url"`
29}
30
31// RepoCreate is the create-repo request body.
32type RepoCreate struct {
33 Owner string `json:"owner,omitempty"`
34 Name string `json:"name"`
35 Visibility string `json:"visibility,omitempty"`
36 Description string `json:"description,omitempty"`
37}
38
39// RepoUpdate is the patch-repo request body.
40type RepoUpdate struct {
41 Visibility *string `json:"visibility,omitempty"`
42 Description *string `json:"description,omitempty"`
43 DefaultBranch *string `json:"default_branch,omitempty"`
44}
45
46// Collaborator is a repo collaborator grant.
47type Collaborator struct {
48 Handle string `json:"handle"`
49 DisplayName string `json:"display_name"`
50 Permission string `json:"permission"`
51}
52
53// MergeRequest is a merge request (a.k.a. pull request).
54type MergeRequest struct {
55 Number int `json:"number"`
56 Title string `json:"title"`
57 Body string `json:"body"`
58 State string `json:"state"`
59 Author string `json:"author"`
60 BaseBranch string `json:"base_branch"`
61 HeadBranch string `json:"head_branch"`
62 HeadOwner string `json:"head_owner"`
63 HeadRepo string `json:"head_repo"`
64 CrossRepo bool `json:"cross_repo"`
65 MergeSHA string `json:"merge_sha"`
66 CreatedAt string `json:"created_at"`
67 MergedAt string `json:"merged_at"`
68 URL string `json:"url"`
69}
70
71// MergeRequestDetail adds comments/reviewers/assignees/reviews.
72type MergeRequestDetail struct {
73 MergeRequest
74 Comments []Comment `json:"comments"`
75 Reviewers []Subject `json:"reviewers"`
76 Assignees []Subject `json:"assignees"`
77 Reviews []Review `json:"reviews"`
78}
79
80// MergeRequestCreate is the open-MR request body.
81type MergeRequestCreate struct {
82 Base string `json:"base"`
83 Head string `json:"head"`
84 Title string `json:"title"`
85 Body string `json:"body,omitempty"`
86 HeadOwner string `json:"head_owner,omitempty"`
87 HeadRepo string `json:"head_repo,omitempty"`
88}
89
90// Comment is an MR comment.
91type Comment struct {
92 Author string `json:"author"`
93 Body string `json:"body"`
94 CreatedAt string `json:"created_at"`
95}
96
97// Subject is a reviewer/assignee (user or team).
98type Subject struct {
99 Type string `json:"type"`
100 Name string `json:"name"`
101 Label string `json:"label"`
102}
103
104// Review is a review verdict.
105type Review struct {
106 Reviewer string `json:"reviewer"`
107 Verdict string `json:"verdict"`
108 UpdatedAt string `json:"updated_at"`
109}
110
111// RunStep is a single step's status.
112type RunStep struct {
113 Ordinal int `json:"ordinal"`
114 Name string `json:"name"`
115 Status string `json:"status"`
116}
117
118// RunJob is a job with its steps.
119type RunJob struct {
120 Name string `json:"name"`
121 Status string `json:"status"`
122 Steps []RunStep `json:"steps"`
123}
124
125// Run is a workflow run.
126type Run struct {
127 Number int `json:"number"`
128 Workflow string `json:"workflow"`
129 Event string `json:"event"`
130 Branch string `json:"branch"`
131 Status string `json:"status"`
132 HeadSHA string `json:"head_sha"`
133 SecretsWithheld bool `json:"secrets_withheld"`
134 CreatedAt string `json:"created_at"`
135 UpdatedAt string `json:"updated_at"`
136 URL string `json:"url"`
137 Jobs []RunJob `json:"jobs"`
138}
139
140// RunLogsJob is one job's accumulated log.
141type RunLogsJob struct {
142 Name string `json:"name"`
143 Status string `json:"status"`
144 Log string `json:"log"`
145}
146
147// RunLogs is the accumulated logs for a run.
148type RunLogs struct {
149 Number int `json:"number"`
150 Status string `json:"status"`
151 Jobs []RunLogsJob `json:"jobs"`
152}
153
154// DispatchResult is the response of an actions dispatch.
155type DispatchResult struct {
156 Dispatched int `json:"dispatched"`
157 Runs []Run `json:"runs"`
158}
159
160// Org is basic org info.
161type Org struct {
162 Handle string `json:"handle"`
163 DisplayName string `json:"display_name"`
164 CreatedAt string `json:"created_at"`
165}
166
167// OrgMember is an org membership.
168type OrgMember struct {
169 Handle string `json:"handle"`
170 DisplayName string `json:"display_name"`
171 Role string `json:"role"`
172}
173
174// Team is an org team.
175type Team struct {
176 Slug string `json:"slug"`
177 Name string `json:"name"`
178 Description string `json:"description"`
179 SubTeam bool `json:"sub_team"`
180}
181
182// Ref is a branch or tag.
183type Ref struct {
184 Name string `json:"name"`
185 SHA string `json:"sha"`
186}
187
188// Refs is the ref inventory.
189type Refs struct {
190 Branches []Ref `json:"branches"`
191 Tags []Ref `json:"tags"`
192 DefaultBranch string `json:"default_branch"`
193}
194
195// TreeEntry is one entry in a directory listing.
196type TreeEntry struct {
197 Name string `json:"name"`
198 Type string `json:"type"` // blob | tree
199 Mode string `json:"mode"`
200 SHA string `json:"sha"`
201 Size int `json:"size"`
202}
203
204// Blob is a file's content.
205type Blob struct {
206 Path string `json:"path"`
207 Size int `json:"size"`
208 IsBinary bool `json:"is_binary"`
209 Truncated bool `json:"truncated"`
210 Content string `json:"content"`
211}
212
213// Contents is a dir listing or file.
214type Contents struct {
215 Type string `json:"type"` // dir | file
216 Ref string `json:"ref"`
217 Path string `json:"path"`
218 Entries []TreeEntry `json:"entries"`
219 File *Blob `json:"file"`
220}
221
222// Commit is a commit summary.
223type Commit struct {
224 SHA string `json:"sha"`
225 Short string `json:"short"`
226 Author string `json:"author"`
227 Date string `json:"date"`
228 Subject string `json:"subject"`
229}
230
231// DiffFile is one file's diff.
232type DiffFile struct {
233 Path string `json:"path"`
234 Status string `json:"status"`
235 Additions int `json:"additions"`
236 Deletions int `json:"deletions"`
237 Patch string `json:"patch"`
238}
239
240// CommitDetail is a single commit's metadata + diff.
241type CommitDetail struct {
242 SHA string `json:"sha"`
243 Short string `json:"short"`
244 AuthorName string `json:"author_name"`
245 AuthorEmail string `json:"author_email"`
246 AuthorDate string `json:"author_date"`
247 Subject string `json:"subject"`
248 Body string `json:"body"`
249 Parents []string `json:"parents"`
250 Files []DiffFile `json:"files"`
251 Truncated bool `json:"truncated"`
252}
253
254// Comparison is a base...head comparison.
255type Comparison struct {
256 MergeBase string `json:"merge_base"`
257 AheadBy int `json:"ahead_by"`
258 BehindBy int `json:"behind_by"`
259 Commits []Commit `json:"commits"`
260 Files []DiffFile `json:"files"`
261 Truncated bool `json:"truncated"`
262}
263
264// Page is the pagination envelope shared by list responses.
265type Page struct {
266 Page int `json:"page"`
267 PerPage int `json:"per_page"`
268 HasNext bool `json:"has_next"`
269}
270
271// RepoPage is a page of repositories.
272type RepoPage struct {
273 Page
274 Items []Repo `json:"items"`
275}
276
277// MergeRequestPage is a page of merge requests.
278type MergeRequestPage struct {
279 Page
280 Items []MergeRequest `json:"items"`
281}
282
283// RunPage is a page of runs.
284type RunPage struct {
285 Page
286 Items []Run `json:"items"`
287}
288
289// CommitPage is a page of commits.
290type CommitPage struct {
291 Page
292 Items []Commit `json:"items"`
293}
294
295// --- issues / labels / milestones ---------------------------------------------
296
297// Label is a repo label.
298type Label struct {
299 ID string `json:"id"`
300 Name string `json:"name"`
301 Color string `json:"color"`
302}
303
304// Milestone is a repo milestone with progress counts.
305type Milestone struct {
306 ID string `json:"id"`
307 Title string `json:"title"`
308 Description string `json:"description"`
309 State string `json:"state"`
310 DueOn *string `json:"due_on,omitempty"`
311 CreatedAt string `json:"created_at"`
312 OpenCount int `json:"open_issues"`
313 ClosedCount int `json:"closed_issues"`
314}
315
316// Issue is an issue list row.
317type Issue struct {
318 Number int `json:"number"`
319 Title string `json:"title"`
320 State string `json:"state"`
321 Author string `json:"author"`
322 Labels []Label `json:"labels"`
323 Milestone *Milestone `json:"milestone,omitempty"`
324 CreatedAt string `json:"created_at"`
325 ClosedAt *string `json:"closed_at,omitempty"`
326 URL string `json:"url"`
327}
328
329// Assignee is a user assigned to an issue.
330type Assignee struct {
331 Handle string `json:"handle"`
332 DisplayName string `json:"display_name,omitempty"`
333}
334
335// IssueDetail adds body, comments, and assignees.
336type IssueDetail struct {
337 Issue
338 Body string `json:"body"`
339 Comments []Comment `json:"comments"`
340 Assignees []Assignee `json:"assignees"`
341}
342
343// IssuePage is a page of issues.
344type IssuePage struct {
345 Page
346 Items []Issue `json:"items"`
347}
348
349// --- device flow (web login) --------------------------------------------------
350
351// DeviceCodeStart is the /device/code response: where to approve and how often
352// to poll.
353type DeviceCodeStart struct {
354 DeviceCode string `json:"device_code"`
355 UserCode string `json:"user_code"`
356 VerificationURL string `json:"verification_url"`
357 VerificationURIComplete string `json:"verification_uri_complete"`
358 ExpiresIn int `json:"expires_in"`
359 Interval int `json:"interval"`
360}
361
362// DeviceToken is the successful /device/token poll: a freshly minted PAT.
363type DeviceToken struct {
364 AccessToken string `json:"access_token"`
365 TokenType string `json:"token_type"`
366 Scope string `json:"scope"`
367}