-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.go
More file actions
656 lines (583 loc) · 20.8 KB
/
types.go
File metadata and controls
656 lines (583 loc) · 20.8 KB
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
package forges
import "time"
// ForgeType identifies which forge software a domain runs.
type ForgeType string
const (
GitHub ForgeType = "github"
GitLab ForgeType = "gitlab"
Gitea ForgeType = "gitea"
Forgejo ForgeType = "forgejo"
Bitbucket ForgeType = "bitbucket"
Unknown ForgeType = "unknown"
)
// User holds normalized user/org metadata.
type User struct {
Login string `json:"login"`
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
AvatarURL string `json:"avatar_url,omitempty"`
HTMLURL string `json:"html_url,omitempty"`
IsOrg bool `json:"is_org,omitempty"`
}
// Repository holds normalized metadata about a source code repository,
// independent of which forge hosts it.
type Repository struct {
FullName string `json:"full_name"`
Owner string `json:"owner"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Homepage string `json:"homepage,omitempty"`
HTMLURL string `json:"html_url"`
CloneURL string `json:"clone_url,omitempty"`
SSHURL string `json:"ssh_url,omitempty"`
Language string `json:"language,omitempty"`
License string `json:"license,omitempty"` // SPDX identifier
DefaultBranch string `json:"default_branch,omitempty"`
Fork bool `json:"fork"`
Archived bool `json:"archived"`
Private bool `json:"private"`
MirrorURL string `json:"mirror_url,omitempty"`
SourceName string `json:"source_name,omitempty"` // fork parent full name
Size int `json:"size"`
StargazersCount int `json:"stargazers_count"`
ForksCount int `json:"forks_count"`
OpenIssuesCount int `json:"open_issues_count"`
SubscribersCount int `json:"subscribers_count"`
HasIssues bool `json:"has_issues"`
PullRequestsEnabled bool `json:"pull_requests_enabled"`
Topics []string `json:"topics,omitempty"`
LogoURL string `json:"logo_url,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
PushedAt time.Time `json:"pushed_at,omitzero"`
}
// Tag represents a git tag.
type Tag struct {
Name string `json:"name"`
Commit string `json:"commit"` // SHA
}
// ArchivedFilter controls how archived repositories are handled in list operations.
type ArchivedFilter int
const (
ArchivedInclude ArchivedFilter = iota
ArchivedExclude
ArchivedOnly
)
// ForkFilter controls how forked repositories are handled in list operations.
type ForkFilter int
const (
ForkInclude ForkFilter = iota
ForkExclude
ForkOnly
)
// Visibility selects the visibility level for a new or edited repository.
type Visibility int
const (
VisibilityDefault Visibility = iota
VisibilityPublic
VisibilityPrivate
VisibilityInternal
)
// ListRepoOpts configures a repo list call.
//
// Pagination: Page and PerPage control the API page size and starting page.
// Limit caps the total number of results returned across all pages. When
// Limit is 0 all results are returned. PerPage defaults to a backend-specific
// value (typically 30-50) when 0.
type ListRepoOpts struct {
Archived ArchivedFilter
Forks ForkFilter
Sort string
Order string
Limit int // max total results; 0 = unlimited
Page int // starting page; 0 or 1 = first page
PerPage int // results per API request; 0 = default
}
// CreateRepoOpts holds options for creating a repository.
type CreateRepoOpts struct {
Name string
Description string
Visibility Visibility
Init bool
DefaultBranch string
Readme bool
Gitignore string
License string
Owner string // org or group; empty = authenticated user
}
// EditRepoOpts holds options for editing a repository.
type EditRepoOpts struct {
Description *string
Homepage *string
Visibility Visibility
DefaultBranch *string
HasIssues *bool
HasPRs *bool
}
// ForkRepoOpts holds options for forking a repository.
type ForkRepoOpts struct {
Owner string // target owner/org; empty = authenticated user
Name string // new name; empty = keep original
}
// ListForksOpts holds options for listing forks of a repository.
type ListForksOpts struct {
Sort string // newest, oldest, stargazers, watchers
Limit int // max total results; 0 = unlimited
Page int // starting page; 0 or 1 = first page
PerPage int // results per API request; 0 = default
}
// SearchRepoOpts holds options for searching repositories.
type SearchRepoOpts struct {
Query string
Sort string
Order string
Limit int // max total results; 0 = unlimited
Page int // starting page; 0 or 1 = first page
PerPage int // results per API request; 0 = default
}
// Label represents an issue or pull request label.
type Label struct {
Name string `json:"name"`
Color string `json:"color,omitempty"`
Description string `json:"description,omitempty"`
}
// Milestone represents a project milestone.
type Milestone struct {
Title string `json:"title"`
Number int `json:"number"`
Description string `json:"description,omitempty"`
State string `json:"state"`
DueDate *time.Time `json:"due_date,omitempty"`
}
// Issue holds normalized metadata about an issue.
type Issue struct {
Number int `json:"number"`
Title string `json:"title"`
Body string `json:"body"`
State string `json:"state"` // "open" or "closed"
Author User `json:"author"`
Assignees []User `json:"assignees,omitempty"`
Labels []Label `json:"labels,omitempty"`
Milestone *Milestone `json:"milestone,omitempty"`
Comments int `json:"comments"`
Locked bool `json:"locked"`
HTMLURL string `json:"html_url"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ClosedAt *time.Time `json:"closed_at,omitempty"`
}
// Comment holds normalized metadata about an issue or PR comment.
type Comment struct {
ID int64 `json:"id"`
Body string `json:"body"`
Author User `json:"author"`
HTMLURL string `json:"html_url"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// CreateIssueOpts holds options for creating an issue.
type CreateIssueOpts struct {
Title string
Body string
Assignees []string
Labels []string
Milestone string
}
// ListIssueOpts holds options for listing issues.
type ListIssueOpts struct {
State string // open, closed, all
Labels []string
Assignee string
Author string
Sort string
Order string
Limit int // max total results; 0 = unlimited
Page int // starting page; 0 or 1 = first page
PerPage int // results per API request; 0 = default
}
// UpdateIssueOpts holds options for updating an issue.
type UpdateIssueOpts struct {
Title *string
Body *string
Assignees []string
Labels []string
Milestone *string
}
// PullRequest holds normalized metadata about a pull request (or merge request).
type PullRequest struct {
Number int `json:"number"`
Title string `json:"title"`
Body string `json:"body"`
State string `json:"state"` // "open", "closed", or "merged"
Draft bool `json:"draft"`
Author User `json:"author"`
Assignees []User `json:"assignees,omitempty"`
Reviewers []User `json:"reviewers,omitempty"`
Labels []Label `json:"labels,omitempty"`
Milestone *Milestone `json:"milestone,omitempty"`
Head string `json:"head"` // head branch
Base string `json:"base"` // base branch
Mergeable bool `json:"mergeable"`
Merged bool `json:"merged"`
MergedBy *User `json:"merged_by,omitempty"`
Comments int `json:"comments"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
ChangedFiles int `json:"changed_files"`
HTMLURL string `json:"html_url"`
DiffURL string `json:"diff_url,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
MergedAt *time.Time `json:"merged_at,omitempty"`
ClosedAt *time.Time `json:"closed_at,omitempty"`
}
// CreatePROpts holds options for creating a pull request.
type CreatePROpts struct {
Title string
Body string
Head string // source branch
Base string // target branch
Draft bool
Assignees []string
Labels []string
Milestone string
Reviewers []string
}
// ListPROpts holds options for listing pull requests.
type ListPROpts struct {
State string // open, closed, merged, all
Labels []string
Assignee string
Author string
Base string
Head string
Sort string
Order string
Limit int // max total results; 0 = unlimited
Page int // starting page; 0 or 1 = first page
PerPage int // results per API request; 0 = default
}
// UpdatePROpts holds options for updating a pull request.
type UpdatePROpts struct {
Title *string
Body *string
Base *string
Assignees []string
Labels []string
Milestone *string
Reviewers []string
}
// MergePROpts holds options for merging a pull request.
type MergePROpts struct {
Method string // merge, squash, rebase
Title string // commit title
Message string // commit message
Delete bool // delete branch after merge
}
// CreateLabelOpts holds options for creating a label.
type CreateLabelOpts struct {
Name string
Color string
Description string
}
// ListLabelOpts holds options for listing labels.
type ListLabelOpts struct {
Limit int // max total results; 0 = unlimited
Page int // starting page; 0 or 1 = first page
PerPage int // results per API request; 0 = default
}
// UpdateLabelOpts holds options for updating a label.
type UpdateLabelOpts struct {
Name *string
Color *string
Description *string
}
// CreateMilestoneOpts holds options for creating a milestone.
type CreateMilestoneOpts struct {
Title string
Description string
DueDate *time.Time
}
// ListMilestoneOpts holds options for listing milestones.
type ListMilestoneOpts struct {
State string // open, closed, all
Limit int // max total results; 0 = unlimited
Page int // starting page; 0 or 1 = first page
PerPage int // results per API request; 0 = default
}
// UpdateMilestoneOpts holds options for updating a milestone.
type UpdateMilestoneOpts struct {
Title *string
Description *string
State *string
DueDate *time.Time
}
// Release holds normalized metadata about a release.
type Release struct {
TagName string `json:"tag_name"`
Title string `json:"title"`
Body string `json:"body,omitempty"`
Draft bool `json:"draft"`
Prerelease bool `json:"prerelease"`
Target string `json:"target,omitempty"`
Author User `json:"author"`
Assets []ReleaseAsset `json:"assets,omitempty"`
TarballURL string `json:"tarball_url,omitempty"`
ZipballURL string `json:"zipball_url,omitempty"`
HTMLURL string `json:"html_url"`
CreatedAt time.Time `json:"created_at"`
PublishedAt time.Time `json:"published_at,omitzero"`
}
// ReleaseAsset holds metadata about a file attached to a release.
type ReleaseAsset struct {
ID int64 `json:"id"`
Name string `json:"name"`
Size int `json:"size"`
DownloadCount int `json:"download_count"`
DownloadURL string `json:"download_url"`
CreatedAt time.Time `json:"created_at"`
}
// CreateReleaseOpts holds options for creating a release.
type CreateReleaseOpts struct {
TagName string
Target string
Title string
Body string
Draft bool
Prerelease bool
GenerateNotes bool
}
// ListReleaseOpts holds options for listing releases.
type ListReleaseOpts struct {
Limit int // max total results; 0 = unlimited
Page int // starting page; 0 or 1 = first page
PerPage int // results per API request; 0 = default
}
// UpdateReleaseOpts holds options for updating a release.
type UpdateReleaseOpts struct {
TagName *string
Target *string
Title *string
Body *string
Draft *bool
Prerelease *bool
}
// Branch holds normalized metadata about a git branch.
type Branch struct {
Name string `json:"name"`
SHA string `json:"sha"`
Protected bool `json:"protected"`
Default bool `json:"default"`
}
// ListBranchOpts holds options for listing branches.
type ListBranchOpts struct {
Limit int // max total results; 0 = unlimited
Page int // starting page; 0 or 1 = first page
PerPage int // results per API request; 0 = default
}
// CIRun holds normalized metadata about a CI pipeline or workflow run.
type CIRun struct {
ID int64 `json:"id"`
Title string `json:"title"`
Status string `json:"status"` // queued, running, completed, failed, success, cancelled
Conclusion string `json:"conclusion"` // success, failure, cancelled, skipped (GitHub-specific)
Branch string `json:"branch"`
SHA string `json:"sha"`
Event string `json:"event,omitempty"` // push, pull_request, etc.
Author User `json:"author"`
HTMLURL string `json:"html_url"`
Jobs []CIJob `json:"jobs,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
FinishedAt *time.Time `json:"finished_at,omitempty"`
}
// CIJob holds normalized metadata about a CI job.
type CIJob struct {
ID int64 `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
Conclusion string `json:"conclusion,omitempty"`
HTMLURL string `json:"html_url,omitempty"`
StartedAt *time.Time `json:"started_at,omitempty"`
FinishedAt *time.Time `json:"finished_at,omitempty"`
}
// ListCIRunOpts holds options for listing CI runs.
type ListCIRunOpts struct {
Branch string
Status string
User string
Workflow string
Limit int // max total results; 0 = unlimited
Page int // starting page; 0 or 1 = first page
PerPage int // results per API request; 0 = default
}
// TriggerCIRunOpts holds options for triggering a CI run.
type TriggerCIRunOpts struct {
Workflow string
Branch string
Inputs map[string]string
}
// DeployKey holds normalized metadata about a deploy key.
type DeployKey struct {
ID int64 `json:"id"`
Title string `json:"title"`
Key string `json:"key"`
ReadOnly bool `json:"read_only"`
CreatedAt time.Time `json:"created_at"`
}
// CreateDeployKeyOpts holds options for adding a deploy key.
type CreateDeployKeyOpts struct {
Title string
Key string
ReadOnly bool
}
// ListDeployKeyOpts holds options for listing deploy keys.
type ListDeployKeyOpts struct {
Limit int // max total results; 0 = unlimited
Page int // starting page; 0 or 1 = first page
PerPage int // results per API request; 0 = default
}
// Secret holds normalized metadata about a repository secret.
type Secret struct {
Name string `json:"name"`
CreatedAt time.Time `json:"created_at,omitzero"`
UpdatedAt time.Time `json:"updated_at,omitzero"`
}
// SetSecretOpts holds options for creating or updating a secret.
type SetSecretOpts struct {
Name string
Value string
}
// ListSecretOpts holds options for listing secrets.
type ListSecretOpts struct {
Limit int // max total results; 0 = unlimited
Page int // starting page; 0 or 1 = first page
PerPage int // results per API request; 0 = default
}
// NotificationSubjectType identifies the kind of resource a notification is about.
type NotificationSubjectType string
const (
NotificationSubjectIssue NotificationSubjectType = "issue"
NotificationSubjectPullRequest NotificationSubjectType = "pull_request"
NotificationSubjectCommit NotificationSubjectType = "commit"
NotificationSubjectRelease NotificationSubjectType = "release"
NotificationSubjectRepository NotificationSubjectType = "repository"
NotificationSubjectDiscussion NotificationSubjectType = "discussion"
)
// Notification holds normalized metadata about a notification thread.
type Notification struct {
ID string `json:"id"`
Title string `json:"title"`
SubjectType NotificationSubjectType `json:"subject_type"`
Repo string `json:"repo"`
Unread bool `json:"unread"`
Reason string `json:"reason,omitempty"`
URL string `json:"url,omitempty"`
UpdatedAt time.Time `json:"updated_at"`
}
// ListNotificationOpts holds options for listing notifications.
type ListNotificationOpts struct {
Repo string // filter by repo (owner/repo)
Unread bool // only unread
Limit int // max total results; 0 = unlimited
Page int // starting page; 0 or 1 = first page
PerPage int // results per API request; 0 = default
}
// MarkNotificationOpts holds options for marking notifications as read.
type MarkNotificationOpts struct {
ID string // mark a single thread; empty = mark all
Repo string // mark all in a repo; empty = mark all
}
// ReviewState represents the state of a pull request review.
type ReviewState string
const (
ReviewApproved ReviewState = "approved"
ReviewChangesRequested ReviewState = "changes_requested"
ReviewCommented ReviewState = "commented"
ReviewDismissed ReviewState = "dismissed"
ReviewPending ReviewState = "pending"
)
// Review holds normalized metadata about a pull request review.
type Review struct {
ID int64 `json:"id"`
State ReviewState `json:"state"`
Body string `json:"body,omitempty"`
Author User `json:"author"`
HTMLURL string `json:"html_url,omitempty"`
SubmittedAt time.Time `json:"submitted_at,omitzero"`
}
// ListReviewOpts holds options for listing reviews.
type ListReviewOpts struct {
Limit int // max total results; 0 = unlimited
Page int // starting page; 0 or 1 = first page
PerPage int // results per API request; 0 = default
}
// SubmitReviewOpts holds options for submitting a review.
type SubmitReviewOpts struct {
State ReviewState // approved, changes_requested, or commented
Body string
}
// RateLimit holds normalized rate limit information for the current token.
type RateLimit struct {
Limit int `json:"limit"`
Remaining int `json:"remaining"`
Reset time.Time `json:"reset"`
}
// FileContent holds file content retrieved from a repository.
type FileContent struct {
Name string `json:"name"`
Path string `json:"path"`
Content []byte `json:"content"`
SHA string `json:"sha,omitempty"`
}
// FileEntry holds metadata about a directory entry in a repository.
type FileEntry struct {
Name string `json:"name"`
Path string `json:"path"`
Type string `json:"type"` // file, dir, symlink
Size int64 `json:"size"`
}
// Collaborator holds normalized metadata about a repository collaborator.
type Collaborator struct {
Login string `json:"login"`
Permission string `json:"permission"` // read, write, admin
}
// AddCollaboratorOpts holds options for adding a collaborator.
type AddCollaboratorOpts struct {
Permission string // pull, push, admin (GitHub/Gitea); guest, reporter, developer, maintainer, owner (GitLab)
}
// ListCollaboratorOpts holds options for listing collaborators.
type ListCollaboratorOpts struct {
Limit int // max total results; 0 = unlimited
Page int // starting page; 0 or 1 = first page
PerPage int // results per API request; 0 = default
}
// Contributor holds normalized metadata about a repository contributor.
type Contributor struct {
Login string `json:"login"`
Contributions int `json:"contributions"`
Email string `json:"email,omitempty"`
Name string `json:"name,omitempty"`
}
// CommitStatus holds normalized metadata about a commit status.
type CommitStatus struct {
State string `json:"state"` // success, failure, pending, error
Context string `json:"context"` // e.g. "my-check"
Description string `json:"description"` // short summary
TargetURL string `json:"target_url"` // link to details
Creator string `json:"creator"` // login of who created it
CreatedAt time.Time `json:"created_at"`
}
// SetCommitStatusOpts holds options for creating a commit status.
type SetCommitStatusOpts struct {
State string // success, failure, pending, error
Context string // e.g. "my-check"
Description string
TargetURL string
}
// Reaction holds normalized metadata about a comment reaction.
type Reaction struct {
ID int64 `json:"id"`
User string `json:"user"`
Content string `json:"content"` // +1, -1, laugh, hooray, confused, heart, rocket, eyes
}