1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "bytes"
21 "encoding/json"
22 "errors"
23 "fmt"
24 "net/url"
25 "reflect"
26 "strconv"
27 "strings"
28 "time"
29 )
30
31
32 func Ptr[T any](v T) *T {
33 return &v
34 }
35
36
37
38
39
40 type AccessControlValue string
41
42
43
44
45 const (
46 DisabledAccessControl AccessControlValue = "disabled"
47 EnabledAccessControl AccessControlValue = "enabled"
48 PrivateAccessControl AccessControlValue = "private"
49 PublicAccessControl AccessControlValue = "public"
50 )
51
52
53
54
55
56 func AccessControl(v AccessControlValue) *AccessControlValue {
57 return Ptr(v)
58 }
59
60
61
62
63 type AccessLevelValue int
64
65
66
67
68 const (
69 NoPermissions AccessLevelValue = 0
70 MinimalAccessPermissions AccessLevelValue = 5
71 GuestPermissions AccessLevelValue = 10
72 ReporterPermissions AccessLevelValue = 20
73 DeveloperPermissions AccessLevelValue = 30
74 MaintainerPermissions AccessLevelValue = 40
75 OwnerPermissions AccessLevelValue = 50
76 AdminPermissions AccessLevelValue = 60
77
78
79 MasterPermissions AccessLevelValue = 40
80
81 OwnerPermission AccessLevelValue = 50
82 )
83
84
85
86
87
88 func AccessLevel(v AccessLevelValue) *AccessLevelValue {
89 return Ptr(v)
90 }
91
92
93 type UserIDValue string
94
95
96 const (
97 UserIDAny UserIDValue = "Any"
98 UserIDNone UserIDValue = "None"
99 )
100
101
102 type ApproverIDsValue struct {
103 value interface{}
104 }
105
106
107 func ApproverIDs(v interface{}) *ApproverIDsValue {
108 switch v.(type) {
109 case UserIDValue, []int:
110 return &ApproverIDsValue{value: v}
111 default:
112 panic("Unsupported value passed as approver ID")
113 }
114 }
115
116
117 func (a *ApproverIDsValue) EncodeValues(key string, v *url.Values) error {
118 switch value := a.value.(type) {
119 case UserIDValue:
120 v.Set(key, string(value))
121 case []int:
122 v.Del(key)
123 v.Del(key + "[]")
124 for _, id := range value {
125 v.Add(key+"[]", strconv.Itoa(id))
126 }
127 }
128 return nil
129 }
130
131
132 func (a ApproverIDsValue) MarshalJSON() ([]byte, error) {
133 return json.Marshal(a.value)
134 }
135
136
137 func (a *ApproverIDsValue) UnmarshalJSON(bytes []byte) error {
138 return json.Unmarshal(bytes, a.value)
139 }
140
141
142 type AssigneeIDValue struct {
143 value interface{}
144 }
145
146
147 func AssigneeID(v interface{}) *AssigneeIDValue {
148 switch v.(type) {
149 case UserIDValue, int:
150 return &AssigneeIDValue{value: v}
151 default:
152 panic("Unsupported value passed as assignee ID")
153 }
154 }
155
156
157 func (a *AssigneeIDValue) EncodeValues(key string, v *url.Values) error {
158 switch value := a.value.(type) {
159 case UserIDValue:
160 v.Set(key, string(value))
161 case int:
162 v.Set(key, strconv.Itoa(value))
163 }
164 return nil
165 }
166
167
168 func (a AssigneeIDValue) MarshalJSON() ([]byte, error) {
169 return json.Marshal(a.value)
170 }
171
172
173 func (a *AssigneeIDValue) UnmarshalJSON(bytes []byte) error {
174 return json.Unmarshal(bytes, a.value)
175 }
176
177
178 type ReviewerIDValue struct {
179 value interface{}
180 }
181
182
183 func ReviewerID(v interface{}) *ReviewerIDValue {
184 switch v.(type) {
185 case UserIDValue, int:
186 return &ReviewerIDValue{value: v}
187 default:
188 panic("Unsupported value passed as reviewer ID")
189 }
190 }
191
192
193 func (a *ReviewerIDValue) EncodeValues(key string, v *url.Values) error {
194 switch value := a.value.(type) {
195 case UserIDValue:
196 v.Set(key, string(value))
197 case int:
198 v.Set(key, strconv.Itoa(value))
199 }
200 return nil
201 }
202
203
204 func (a ReviewerIDValue) MarshalJSON() ([]byte, error) {
205 return json.Marshal(a.value)
206 }
207
208
209 func (a *ReviewerIDValue) UnmarshalJSON(bytes []byte) error {
210 return json.Unmarshal(bytes, a.value)
211 }
212
213
214 type AvailabilityValue string
215
216
217
218
219
220 const (
221 NotSet AvailabilityValue = "not_set"
222 Busy AvailabilityValue = "busy"
223 )
224
225
226
227
228
229 func Availability(v AvailabilityValue) *AvailabilityValue {
230 return Ptr(v)
231 }
232
233
234 type BuildStateValue string
235
236
237 const (
238 Created BuildStateValue = "created"
239 WaitingForResource BuildStateValue = "waiting_for_resource"
240 Preparing BuildStateValue = "preparing"
241 Pending BuildStateValue = "pending"
242 Running BuildStateValue = "running"
243 Success BuildStateValue = "success"
244 Failed BuildStateValue = "failed"
245 Canceled BuildStateValue = "canceled"
246 Skipped BuildStateValue = "skipped"
247 Manual BuildStateValue = "manual"
248 Scheduled BuildStateValue = "scheduled"
249 )
250
251
252
253
254
255 func BuildState(v BuildStateValue) *BuildStateValue {
256 return Ptr(v)
257 }
258
259
260 type DeploymentApprovalStatus string
261
262
263 const (
264 DeploymentApprovalStatusApproved DeploymentApprovalStatus = "approved"
265 DeploymentApprovalStatusRejected DeploymentApprovalStatus = "rejected"
266 )
267
268
269 type DeploymentStatusValue string
270
271
272 const (
273 DeploymentStatusCreated DeploymentStatusValue = "created"
274 DeploymentStatusRunning DeploymentStatusValue = "running"
275 DeploymentStatusSuccess DeploymentStatusValue = "success"
276 DeploymentStatusFailed DeploymentStatusValue = "failed"
277 DeploymentStatusCanceled DeploymentStatusValue = "canceled"
278 )
279
280
281
282
283
284 func DeploymentStatus(v DeploymentStatusValue) *DeploymentStatusValue {
285 return Ptr(v)
286 }
287
288
289 type EventTypeValue string
290
291
292
293
294 const (
295 CreatedEventType EventTypeValue = "created"
296 UpdatedEventType EventTypeValue = "updated"
297 ClosedEventType EventTypeValue = "closed"
298 ReopenedEventType EventTypeValue = "reopened"
299 PushedEventType EventTypeValue = "pushed"
300 CommentedEventType EventTypeValue = "commented"
301 MergedEventType EventTypeValue = "merged"
302 JoinedEventType EventTypeValue = "joined"
303 LeftEventType EventTypeValue = "left"
304 DestroyedEventType EventTypeValue = "destroyed"
305 ExpiredEventType EventTypeValue = "expired"
306 )
307
308
309 type EventTargetTypeValue string
310
311
312
313
314 const (
315 IssueEventTargetType EventTargetTypeValue = "issue"
316 MilestoneEventTargetType EventTargetTypeValue = "milestone"
317 MergeRequestEventTargetType EventTargetTypeValue = "merge_request"
318 NoteEventTargetType EventTargetTypeValue = "note"
319 ProjectEventTargetType EventTargetTypeValue = "project"
320 SnippetEventTargetType EventTargetTypeValue = "snippet"
321 UserEventTargetType EventTargetTypeValue = "user"
322 )
323
324
325
326
327 type FileActionValue string
328
329
330 const (
331 FileCreate FileActionValue = "create"
332 FileDelete FileActionValue = "delete"
333 FileMove FileActionValue = "move"
334 FileUpdate FileActionValue = "update"
335 FileChmod FileActionValue = "chmod"
336 )
337
338
339
340
341
342 func FileAction(v FileActionValue) *FileActionValue {
343 return Ptr(v)
344 }
345
346
347 type GenericPackageSelectValue string
348
349
350 const (
351 SelectPackageFile GenericPackageSelectValue = "package_file"
352 )
353
354
355
356
357
358 func GenericPackageSelect(v GenericPackageSelectValue) *GenericPackageSelectValue {
359 return Ptr(v)
360 }
361
362
363 type GenericPackageStatusValue string
364
365
366 const (
367 PackageDefault GenericPackageStatusValue = "default"
368 PackageHidden GenericPackageStatusValue = "hidden"
369 )
370
371
372
373
374
375 func GenericPackageStatus(v GenericPackageStatusValue) *GenericPackageStatusValue {
376 return Ptr(v)
377 }
378
379
380 type ISOTime time.Time
381
382
383 const iso8601 = "2006-01-02"
384
385
386 func ParseISOTime(s string) (ISOTime, error) {
387 t, err := time.Parse(iso8601, s)
388 return ISOTime(t), err
389 }
390
391
392 func (t ISOTime) MarshalJSON() ([]byte, error) {
393 if reflect.ValueOf(t).IsZero() {
394 return []byte(`null`), nil
395 }
396
397 if y := time.Time(t).Year(); y < 0 || y >= 10000 {
398
399 return nil, errors.New("json: ISOTime year outside of range [0,9999]")
400 }
401
402 b := make([]byte, 0, len(iso8601)+2)
403 b = append(b, '"')
404 b = time.Time(t).AppendFormat(b, iso8601)
405 b = append(b, '"')
406
407 return b, nil
408 }
409
410
411 func (t *ISOTime) UnmarshalJSON(data []byte) error {
412
413 if string(data) == "null" {
414 return nil
415 }
416
417 isotime, err := time.Parse(`"`+iso8601+`"`, string(data))
418 *t = ISOTime(isotime)
419
420 return err
421 }
422
423
424 func (t *ISOTime) EncodeValues(key string, v *url.Values) error {
425 if t == nil || (time.Time(*t)).IsZero() {
426 return nil
427 }
428 v.Add(key, t.String())
429 return nil
430 }
431
432
433 func (t ISOTime) String() string {
434 return time.Time(t).Format(iso8601)
435 }
436
437
438 type Labels []string
439
440
441 type LabelOptions []string
442
443
444 func (l *LabelOptions) MarshalJSON() ([]byte, error) {
445 if *l == nil {
446 return []byte(`null`), nil
447 }
448 return json.Marshal(strings.Join(*l, ","))
449 }
450
451
452 func (l *LabelOptions) UnmarshalJSON(data []byte) error {
453 type alias LabelOptions
454 if !bytes.HasPrefix(data, []byte("[")) {
455 data = []byte(fmt.Sprintf("[%s]", string(data)))
456 }
457 return json.Unmarshal(data, (*alias)(l))
458 }
459
460
461 func (l *LabelOptions) EncodeValues(key string, v *url.Values) error {
462 v.Set(key, strings.Join(*l, ","))
463 return nil
464 }
465
466
467 type LinkTypeValue string
468
469
470
471
472
473 const (
474 ImageLinkType LinkTypeValue = "image"
475 OtherLinkType LinkTypeValue = "other"
476 PackageLinkType LinkTypeValue = "package"
477 RunbookLinkType LinkTypeValue = "runbook"
478 )
479
480
481
482
483
484 func LinkType(v LinkTypeValue) *LinkTypeValue {
485 return Ptr(v)
486 }
487
488
489
490
491 type LicenseApprovalStatusValue string
492
493
494 const (
495 LicenseApproved LicenseApprovalStatusValue = "approved"
496 LicenseBlacklisted LicenseApprovalStatusValue = "blacklisted"
497 LicenseAllowed LicenseApprovalStatusValue = "allowed"
498 LicenseDenied LicenseApprovalStatusValue = "denied"
499 )
500
501
502
503
504
505 func LicenseApprovalStatus(v LicenseApprovalStatusValue) *LicenseApprovalStatusValue {
506 return Ptr(v)
507 }
508
509
510
511
512 type MergeMethodValue string
513
514
515
516
517 const (
518 NoFastForwardMerge MergeMethodValue = "merge"
519 FastForwardMerge MergeMethodValue = "ff"
520 RebaseMerge MergeMethodValue = "rebase_merge"
521 )
522
523
524
525
526
527 func MergeMethod(v MergeMethodValue) *MergeMethodValue {
528 return Ptr(v)
529 }
530
531
532 type NoteTypeValue string
533
534
535 const (
536 DiffNote NoteTypeValue = "DiffNote"
537 DiscussionNote NoteTypeValue = "DiscussionNote"
538 GenericNote NoteTypeValue = "Note"
539 LegacyDiffNote NoteTypeValue = "LegacyDiffNote"
540 )
541
542
543
544
545
546 func NoteType(v NoteTypeValue) *NoteTypeValue {
547 return Ptr(v)
548 }
549
550
551 type NotificationLevelValue int
552
553
554 func (l NotificationLevelValue) String() string {
555 return notificationLevelNames[l]
556 }
557
558
559 func (l NotificationLevelValue) MarshalJSON() ([]byte, error) {
560 return json.Marshal(l.String())
561 }
562
563
564 func (l *NotificationLevelValue) UnmarshalJSON(data []byte) error {
565 var raw interface{}
566 if err := json.Unmarshal(data, &raw); err != nil {
567 return err
568 }
569
570 switch raw := raw.(type) {
571 case float64:
572 *l = NotificationLevelValue(raw)
573 case string:
574 *l = notificationLevelTypes[raw]
575 case nil:
576
577 default:
578 return fmt.Errorf("json: cannot unmarshal %T into Go value of type %T", raw, *l)
579 }
580
581 return nil
582 }
583
584
585 const (
586 DisabledNotificationLevel NotificationLevelValue = iota
587 ParticipatingNotificationLevel
588 WatchNotificationLevel
589 GlobalNotificationLevel
590 MentionNotificationLevel
591 CustomNotificationLevel
592 )
593
594 var notificationLevelNames = [...]string{
595 "disabled",
596 "participating",
597 "watch",
598 "global",
599 "mention",
600 "custom",
601 }
602
603 var notificationLevelTypes = map[string]NotificationLevelValue{
604 "disabled": DisabledNotificationLevel,
605 "participating": ParticipatingNotificationLevel,
606 "watch": WatchNotificationLevel,
607 "global": GlobalNotificationLevel,
608 "mention": MentionNotificationLevel,
609 "custom": CustomNotificationLevel,
610 }
611
612
613
614
615
616 func NotificationLevel(v NotificationLevelValue) *NotificationLevelValue {
617 return Ptr(v)
618 }
619
620
621
622
623 type ProjectCreationLevelValue string
624
625
626
627
628 const (
629 NoOneProjectCreation ProjectCreationLevelValue = "noone"
630 MaintainerProjectCreation ProjectCreationLevelValue = "maintainer"
631 DeveloperProjectCreation ProjectCreationLevelValue = "developer"
632 )
633
634
635
636
637 func ProjectCreationLevel(v ProjectCreationLevelValue) *ProjectCreationLevelValue {
638 return Ptr(v)
639 }
640
641
642
643
644
645
646 type SharedRunnersSettingValue string
647
648
649
650
651
652 const (
653 EnabledSharedRunnersSettingValue SharedRunnersSettingValue = "enabled"
654 DisabledAndOverridableSharedRunnersSettingValue SharedRunnersSettingValue = "disabled_and_overridable"
655 DisabledAndUnoverridableSharedRunnersSettingValue SharedRunnersSettingValue = "disabled_and_unoverridable"
656
657
658 DisabledWithOverrideSharedRunnersSettingValue SharedRunnersSettingValue = "disabled_with_override"
659 )
660
661
662
663
664
665 func SharedRunnersSetting(v SharedRunnersSettingValue) *SharedRunnersSettingValue {
666 return Ptr(v)
667 }
668
669
670
671
672 type SubGroupCreationLevelValue string
673
674
675
676
677 const (
678 OwnerSubGroupCreationLevelValue SubGroupCreationLevelValue = "owner"
679 MaintainerSubGroupCreationLevelValue SubGroupCreationLevelValue = "maintainer"
680 )
681
682
683
684
685
686 func SubGroupCreationLevel(v SubGroupCreationLevelValue) *SubGroupCreationLevelValue {
687 return Ptr(v)
688 }
689
690
691
692
693 type SquashOptionValue string
694
695
696
697
698 const (
699 SquashOptionNever SquashOptionValue = "never"
700 SquashOptionAlways SquashOptionValue = "always"
701 SquashOptionDefaultOff SquashOptionValue = "default_off"
702 SquashOptionDefaultOn SquashOptionValue = "default_on"
703 )
704
705
706
707
708
709 func SquashOption(s SquashOptionValue) *SquashOptionValue {
710 return Ptr(s)
711 }
712
713
714 type TasksCompletionStatus struct {
715 Count int `json:"count"`
716 CompletedCount int `json:"completed_count"`
717 }
718
719
720
721
722 type TodoAction string
723
724
725 const (
726 TodoAssigned TodoAction = "assigned"
727 TodoMentioned TodoAction = "mentioned"
728 TodoBuildFailed TodoAction = "build_failed"
729 TodoMarked TodoAction = "marked"
730 TodoApprovalRequired TodoAction = "approval_required"
731 TodoDirectlyAddressed TodoAction = "directly_addressed"
732 )
733
734
735
736
737 type TodoTargetType string
738
739 const (
740 TodoTargetAlertManagement TodoTargetType = "AlertManagement::Alert"
741 TodoTargetDesignManagement TodoTargetType = "DesignManagement::Design"
742 TodoTargetIssue TodoTargetType = "Issue"
743 TodoTargetMergeRequest TodoTargetType = "MergeRequest"
744 )
745
746
747 type UploadType string
748
749
750 const (
751 UploadAvatar UploadType = "avatar"
752 UploadFile UploadType = "file"
753 )
754
755
756
757
758 type VariableTypeValue string
759
760
761
762
763 const (
764 EnvVariableType VariableTypeValue = "env_var"
765 FileVariableType VariableTypeValue = "file"
766 )
767
768
769
770
771
772 func VariableType(v VariableTypeValue) *VariableTypeValue {
773 return Ptr(v)
774 }
775
776
777
778
779 type VisibilityValue string
780
781
782
783
784 const (
785 PrivateVisibility VisibilityValue = "private"
786 InternalVisibility VisibilityValue = "internal"
787 PublicVisibility VisibilityValue = "public"
788 )
789
790
791
792
793
794 func Visibility(v VisibilityValue) *VisibilityValue {
795 return Ptr(v)
796 }
797
798
799
800
801 type WikiFormatValue string
802
803
804 const (
805 WikiFormatMarkdown WikiFormatValue = "markdown"
806 WikiFormatRDoc WikiFormatValue = "rdoc"
807 WikiFormatASCIIDoc WikiFormatValue = "asciidoc"
808 WikiFormatOrg WikiFormatValue = "org"
809 )
810
811
812
813
814
815 func WikiFormat(v WikiFormatValue) *WikiFormatValue {
816 return Ptr(v)
817 }
818
819
820
821
822
823 func Bool(v bool) *bool {
824 return Ptr(v)
825 }
826
827
828
829
830
831 func Int(v int) *int {
832 return Ptr(v)
833 }
834
835
836
837
838
839 func String(v string) *string {
840 return Ptr(v)
841 }
842
843
844
845
846
847 func Time(v time.Time) *time.Time {
848 return Ptr(v)
849 }
850
851
852 type BoolValue bool
853
854
855
856
857
858
859 func (t *BoolValue) UnmarshalJSON(b []byte) error {
860 switch string(b) {
861 case `"1"`:
862 *t = true
863 return nil
864 case `"0"`:
865 *t = false
866 return nil
867 case `"true"`:
868 *t = true
869 return nil
870 case `"false"`:
871 *t = false
872 return nil
873 default:
874 var v bool
875 err := json.Unmarshal(b, &v)
876 *t = BoolValue(v)
877 return err
878 }
879 }
880
View as plain text