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
Initial import of the rickub CLI as a standalone public project 1a1d430Unverified · on main · Olivier Girardot · 9h ago
models.go · 367 lines · 10.1 KBGo Blame HistoryRaw
  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
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
package api

// Types mirror the schemas of the rickub JSON API (`/api/v1`). Clients must
// ignore unknown JSON fields (additive changes may appear within v1), which
// json unmarshalling does by default.

// User is the identity that owns the presented PAT.
type User struct {
	Handle        string `json:"handle"`
	DisplayName   string `json:"display_name"`
	Email         string `json:"email"`
	EmailVerified bool   `json:"email_verified"`
	Superadmin    bool   `json:"superadmin"`
}

// Repo is a repository.
type Repo struct {
	Owner           string `json:"owner"`
	Name            string `json:"name"`
	FullName        string `json:"full_name"`
	Visibility      string `json:"visibility"`
	Description     string `json:"description"`
	DefaultBranch   string `json:"default_branch"`
	Fork            bool   `json:"fork"`
	ForkedFromOwner string `json:"forked_from_owner"`
	ForkedFromName  string `json:"forked_from_name"`
	CreatedAt       string `json:"created_at"`
	URL             string `json:"url"`
}

// RepoCreate is the create-repo request body.
type RepoCreate struct {
	Owner       string `json:"owner,omitempty"`
	Name        string `json:"name"`
	Visibility  string `json:"visibility,omitempty"`
	Description string `json:"description,omitempty"`
}

// RepoUpdate is the patch-repo request body.
type RepoUpdate struct {
	Visibility    *string `json:"visibility,omitempty"`
	Description   *string `json:"description,omitempty"`
	DefaultBranch *string `json:"default_branch,omitempty"`
}

// Collaborator is a repo collaborator grant.
type Collaborator struct {
	Handle      string `json:"handle"`
	DisplayName string `json:"display_name"`
	Permission  string `json:"permission"`
}

// MergeRequest is a merge request (a.k.a. pull request).
type MergeRequest struct {
	Number     int    `json:"number"`
	Title      string `json:"title"`
	Body       string `json:"body"`
	State      string `json:"state"`
	Author     string `json:"author"`
	BaseBranch string `json:"base_branch"`
	HeadBranch string `json:"head_branch"`
	HeadOwner  string `json:"head_owner"`
	HeadRepo   string `json:"head_repo"`
	CrossRepo  bool   `json:"cross_repo"`
	MergeSHA   string `json:"merge_sha"`
	CreatedAt  string `json:"created_at"`
	MergedAt   string `json:"merged_at"`
	URL        string `json:"url"`
}

// MergeRequestDetail adds comments/reviewers/assignees/reviews.
type MergeRequestDetail struct {
	MergeRequest
	Comments  []Comment `json:"comments"`
	Reviewers []Subject `json:"reviewers"`
	Assignees []Subject `json:"assignees"`
	Reviews   []Review  `json:"reviews"`
}

// MergeRequestCreate is the open-MR request body.
type MergeRequestCreate struct {
	Base      string `json:"base"`
	Head      string `json:"head"`
	Title     string `json:"title"`
	Body      string `json:"body,omitempty"`
	HeadOwner string `json:"head_owner,omitempty"`
	HeadRepo  string `json:"head_repo,omitempty"`
}

// Comment is an MR comment.
type Comment struct {
	Author    string `json:"author"`
	Body      string `json:"body"`
	CreatedAt string `json:"created_at"`
}

// Subject is a reviewer/assignee (user or team).
type Subject struct {
	Type  string `json:"type"`
	Name  string `json:"name"`
	Label string `json:"label"`
}

// Review is a review verdict.
type Review struct {
	Reviewer  string `json:"reviewer"`
	Verdict   string `json:"verdict"`
	UpdatedAt string `json:"updated_at"`
}

// RunStep is a single step's status.
type RunStep struct {
	Ordinal int    `json:"ordinal"`
	Name    string `json:"name"`
	Status  string `json:"status"`
}

// RunJob is a job with its steps.
type RunJob struct {
	Name   string    `json:"name"`
	Status string    `json:"status"`
	Steps  []RunStep `json:"steps"`
}

// Run is a workflow run.
type Run struct {
	Number          int      `json:"number"`
	Workflow        string   `json:"workflow"`
	Event           string   `json:"event"`
	Branch          string   `json:"branch"`
	Status          string   `json:"status"`
	HeadSHA         string   `json:"head_sha"`
	SecretsWithheld bool     `json:"secrets_withheld"`
	CreatedAt       string   `json:"created_at"`
	UpdatedAt       string   `json:"updated_at"`
	URL             string   `json:"url"`
	Jobs            []RunJob `json:"jobs"`
}

// RunLogsJob is one job's accumulated log.
type RunLogsJob struct {
	Name   string `json:"name"`
	Status string `json:"status"`
	Log    string `json:"log"`
}

// RunLogs is the accumulated logs for a run.
type RunLogs struct {
	Number int          `json:"number"`
	Status string       `json:"status"`
	Jobs   []RunLogsJob `json:"jobs"`
}

// DispatchResult is the response of an actions dispatch.
type DispatchResult struct {
	Dispatched int   `json:"dispatched"`
	Runs       []Run `json:"runs"`
}

// Org is basic org info.
type Org struct {
	Handle      string `json:"handle"`
	DisplayName string `json:"display_name"`
	CreatedAt   string `json:"created_at"`
}

// OrgMember is an org membership.
type OrgMember struct {
	Handle      string `json:"handle"`
	DisplayName string `json:"display_name"`
	Role        string `json:"role"`
}

// Team is an org team.
type Team struct {
	Slug        string `json:"slug"`
	Name        string `json:"name"`
	Description string `json:"description"`
	SubTeam     bool   `json:"sub_team"`
}

// Ref is a branch or tag.
type Ref struct {
	Name string `json:"name"`
	SHA  string `json:"sha"`
}

// Refs is the ref inventory.
type Refs struct {
	Branches      []Ref  `json:"branches"`
	Tags          []Ref  `json:"tags"`
	DefaultBranch string `json:"default_branch"`
}

// TreeEntry is one entry in a directory listing.
type TreeEntry struct {
	Name string `json:"name"`
	Type string `json:"type"` // blob | tree
	Mode string `json:"mode"`
	SHA  string `json:"sha"`
	Size int    `json:"size"`
}

// Blob is a file's content.
type Blob struct {
	Path      string `json:"path"`
	Size      int    `json:"size"`
	IsBinary  bool   `json:"is_binary"`
	Truncated bool   `json:"truncated"`
	Content   string `json:"content"`
}

// Contents is a dir listing or file.
type Contents struct {
	Type    string      `json:"type"` // dir | file
	Ref     string      `json:"ref"`
	Path    string      `json:"path"`
	Entries []TreeEntry `json:"entries"`
	File    *Blob       `json:"file"`
}

// Commit is a commit summary.
type Commit struct {
	SHA     string `json:"sha"`
	Short   string `json:"short"`
	Author  string `json:"author"`
	Date    string `json:"date"`
	Subject string `json:"subject"`
}

// DiffFile is one file's diff.
type DiffFile struct {
	Path      string `json:"path"`
	Status    string `json:"status"`
	Additions int    `json:"additions"`
	Deletions int    `json:"deletions"`
	Patch     string `json:"patch"`
}

// CommitDetail is a single commit's metadata + diff.
type CommitDetail struct {
	SHA         string     `json:"sha"`
	Short       string     `json:"short"`
	AuthorName  string     `json:"author_name"`
	AuthorEmail string     `json:"author_email"`
	AuthorDate  string     `json:"author_date"`
	Subject     string     `json:"subject"`
	Body        string     `json:"body"`
	Parents     []string   `json:"parents"`
	Files       []DiffFile `json:"files"`
	Truncated   bool       `json:"truncated"`
}

// Comparison is a base...head comparison.
type Comparison struct {
	MergeBase string     `json:"merge_base"`
	AheadBy   int        `json:"ahead_by"`
	BehindBy  int        `json:"behind_by"`
	Commits   []Commit   `json:"commits"`
	Files     []DiffFile `json:"files"`
	Truncated bool       `json:"truncated"`
}

// Page is the pagination envelope shared by list responses.
type Page struct {
	Page    int  `json:"page"`
	PerPage int  `json:"per_page"`
	HasNext bool `json:"has_next"`
}

// RepoPage is a page of repositories.
type RepoPage struct {
	Page
	Items []Repo `json:"items"`
}

// MergeRequestPage is a page of merge requests.
type MergeRequestPage struct {
	Page
	Items []MergeRequest `json:"items"`
}

// RunPage is a page of runs.
type RunPage struct {
	Page
	Items []Run `json:"items"`
}

// CommitPage is a page of commits.
type CommitPage struct {
	Page
	Items []Commit `json:"items"`
}

// --- issues / labels / milestones ---------------------------------------------

// Label is a repo label.
type Label struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Color string `json:"color"`
}

// Milestone is a repo milestone with progress counts.
type Milestone struct {
	ID          string  `json:"id"`
	Title       string  `json:"title"`
	Description string  `json:"description"`
	State       string  `json:"state"`
	DueOn       *string `json:"due_on,omitempty"`
	CreatedAt   string  `json:"created_at"`
	OpenCount   int     `json:"open_issues"`
	ClosedCount int     `json:"closed_issues"`
}

// Issue is an issue list row.
type Issue struct {
	Number    int        `json:"number"`
	Title     string     `json:"title"`
	State     string     `json:"state"`
	Author    string     `json:"author"`
	Labels    []Label    `json:"labels"`
	Milestone *Milestone `json:"milestone,omitempty"`
	CreatedAt string     `json:"created_at"`
	ClosedAt  *string    `json:"closed_at,omitempty"`
	URL       string     `json:"url"`
}

// Assignee is a user assigned to an issue.
type Assignee struct {
	Handle      string `json:"handle"`
	DisplayName string `json:"display_name,omitempty"`
}

// IssueDetail adds body, comments, and assignees.
type IssueDetail struct {
	Issue
	Body      string     `json:"body"`
	Comments  []Comment  `json:"comments"`
	Assignees []Assignee `json:"assignees"`
}

// IssuePage is a page of issues.
type IssuePage struct {
	Page
	Items []Issue `json:"items"`
}

// --- device flow (web login) --------------------------------------------------

// DeviceCodeStart is the /device/code response: where to approve and how often
// to poll.
type DeviceCodeStart struct {
	DeviceCode              string `json:"device_code"`
	UserCode                string `json:"user_code"`
	VerificationURL         string `json:"verification_url"`
	VerificationURIComplete string `json:"verification_uri_complete"`
	ExpiresIn               int    `json:"expires_in"`
	Interval                int    `json:"interval"`
}

// DeviceToken is the successful /device/token poll: a freshly minted PAT.
type DeviceToken struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	Scope       string `json:"scope"`
}