...

Source file src/github.com/xanzy/go-gitlab/types.go

Documentation: github.com/xanzy/go-gitlab

     1  //
     2  // Copyright 2021, Sander van Harmelen
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    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  // Ptr is a helper that returns a pointer to v.
    32  func Ptr[T any](v T) *T {
    33  	return &v
    34  }
    35  
    36  // AccessControlValue represents an access control value within GitLab,
    37  // used for managing access to certain project features.
    38  //
    39  // GitLab API docs: https://docs.gitlab.com/ee/api/projects.html
    40  type AccessControlValue string
    41  
    42  // List of available access control values.
    43  //
    44  // GitLab API docs: https://docs.gitlab.com/ee/api/projects.html
    45  const (
    46  	DisabledAccessControl AccessControlValue = "disabled"
    47  	EnabledAccessControl  AccessControlValue = "enabled"
    48  	PrivateAccessControl  AccessControlValue = "private"
    49  	PublicAccessControl   AccessControlValue = "public"
    50  )
    51  
    52  // AccessControl is a helper routine that allocates a new AccessControlValue
    53  // to store v and returns a pointer to it.
    54  //
    55  // Deprecated: Please use Ptr instead.
    56  func AccessControl(v AccessControlValue) *AccessControlValue {
    57  	return Ptr(v)
    58  }
    59  
    60  // AccessLevelValue represents a permission level within GitLab.
    61  //
    62  // GitLab API docs: https://docs.gitlab.com/ee/user/permissions.html
    63  type AccessLevelValue int
    64  
    65  // List of available access levels
    66  //
    67  // GitLab API docs: https://docs.gitlab.com/ee/user/permissions.html
    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  	// Deprecated: Renamed to MaintainerPermissions in GitLab 11.0.
    79  	MasterPermissions AccessLevelValue = 40
    80  	// Deprecated: Renamed to OwnerPermissions.
    81  	OwnerPermission AccessLevelValue = 50
    82  )
    83  
    84  // AccessLevel is a helper routine that allocates a new AccessLevelValue
    85  // to store v and returns a pointer to it.
    86  //
    87  // Deprecated: Please use Ptr instead.
    88  func AccessLevel(v AccessLevelValue) *AccessLevelValue {
    89  	return Ptr(v)
    90  }
    91  
    92  // UserIDValue represents a user ID value within GitLab.
    93  type UserIDValue string
    94  
    95  // List of available user ID values.
    96  const (
    97  	UserIDAny  UserIDValue = "Any"
    98  	UserIDNone UserIDValue = "None"
    99  )
   100  
   101  // ApproverIDsValue represents an approver ID value within GitLab.
   102  type ApproverIDsValue struct {
   103  	value interface{}
   104  }
   105  
   106  // ApproverIDs is a helper routine that creates a new ApproverIDsValue.
   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  // EncodeValues implements the query.Encoder interface
   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  // MarshalJSON implements the json.Marshaler interface
   132  func (a ApproverIDsValue) MarshalJSON() ([]byte, error) {
   133  	return json.Marshal(a.value)
   134  }
   135  
   136  // UnmarshalJSON implements the json.Unmarshaler interface
   137  func (a *ApproverIDsValue) UnmarshalJSON(bytes []byte) error {
   138  	return json.Unmarshal(bytes, a.value)
   139  }
   140  
   141  // AssigneeIDValue represents an assignee ID value within GitLab.
   142  type AssigneeIDValue struct {
   143  	value interface{}
   144  }
   145  
   146  // AssigneeID is a helper routine that creates a new AssigneeIDValue.
   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  // EncodeValues implements the query.Encoder interface
   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  // MarshalJSON implements the json.Marshaler interface
   168  func (a AssigneeIDValue) MarshalJSON() ([]byte, error) {
   169  	return json.Marshal(a.value)
   170  }
   171  
   172  // UnmarshalJSON implements the json.Unmarshaler interface
   173  func (a *AssigneeIDValue) UnmarshalJSON(bytes []byte) error {
   174  	return json.Unmarshal(bytes, a.value)
   175  }
   176  
   177  // ReviewerIDValue represents a reviewer ID value within GitLab.
   178  type ReviewerIDValue struct {
   179  	value interface{}
   180  }
   181  
   182  // ReviewerID is a helper routine that creates a new ReviewerIDValue.
   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  // EncodeValues implements the query.Encoder interface
   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  // MarshalJSON implements the json.Marshaler interface
   204  func (a ReviewerIDValue) MarshalJSON() ([]byte, error) {
   205  	return json.Marshal(a.value)
   206  }
   207  
   208  // UnmarshalJSON implements the json.Unmarshaler interface
   209  func (a *ReviewerIDValue) UnmarshalJSON(bytes []byte) error {
   210  	return json.Unmarshal(bytes, a.value)
   211  }
   212  
   213  // AvailabilityValue represents an availability value within GitLab.
   214  type AvailabilityValue string
   215  
   216  // List of available availability values.
   217  //
   218  // Undocummented, see code at:
   219  // https://gitlab.com/gitlab-org/gitlab-foss/-/blob/master/app/models/user_status.rb#L22
   220  const (
   221  	NotSet AvailabilityValue = "not_set"
   222  	Busy   AvailabilityValue = "busy"
   223  )
   224  
   225  // Availability is a helper routine that allocates a new AvailabilityValue
   226  // to store v and returns a pointer to it.
   227  //
   228  // Deprecated: Please use Ptr instead.
   229  func Availability(v AvailabilityValue) *AvailabilityValue {
   230  	return Ptr(v)
   231  }
   232  
   233  // BuildStateValue represents a GitLab build state.
   234  type BuildStateValue string
   235  
   236  // These constants represent all valid build states.
   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  // BuildState is a helper routine that allocates a new BuildStateValue
   252  // to store v and returns a pointer to it.
   253  //
   254  // Deprecated: Please use Ptr instead.
   255  func BuildState(v BuildStateValue) *BuildStateValue {
   256  	return Ptr(v)
   257  }
   258  
   259  // DeploymentApprovalStatus represents a Gitlab deployment approval status.
   260  type DeploymentApprovalStatus string
   261  
   262  // These constants represent all valid deployment approval statuses.
   263  const (
   264  	DeploymentApprovalStatusApproved DeploymentApprovalStatus = "approved"
   265  	DeploymentApprovalStatusRejected DeploymentApprovalStatus = "rejected"
   266  )
   267  
   268  // DeploymentStatusValue represents a Gitlab deployment status.
   269  type DeploymentStatusValue string
   270  
   271  // These constants represent all valid deployment statuses.
   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  // DeploymentStatus is a helper routine that allocates a new
   281  // DeploymentStatusValue to store v and returns a pointer to it.
   282  //
   283  // Deprecated: Please use Ptr instead.
   284  func DeploymentStatus(v DeploymentStatusValue) *DeploymentStatusValue {
   285  	return Ptr(v)
   286  }
   287  
   288  // EventTypeValue represents actions type for contribution events
   289  type EventTypeValue string
   290  
   291  // List of available action type
   292  //
   293  // GitLab API docs: https://docs.gitlab.com/ee/user/profile/contributions_calendar.html#user-contribution-events
   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  // EventTargetTypeValue represents actions type value for contribution events
   309  type EventTargetTypeValue string
   310  
   311  // List of available action type
   312  //
   313  // GitLab API docs: https://docs.gitlab.com/ee/api/events.html#target-types
   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  // FileActionValue represents the available actions that can be performed on a file.
   325  //
   326  // GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#create-a-commit-with-multiple-files-and-actions
   327  type FileActionValue string
   328  
   329  // The available file actions.
   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  // FileAction is a helper routine that allocates a new FileActionValue value
   339  // to store v and returns a pointer to it.
   340  //
   341  // Deprecated: Please use Ptr instead.
   342  func FileAction(v FileActionValue) *FileActionValue {
   343  	return Ptr(v)
   344  }
   345  
   346  // GenericPackageSelectValue represents a generic package select value.
   347  type GenericPackageSelectValue string
   348  
   349  // The available generic package select values.
   350  const (
   351  	SelectPackageFile GenericPackageSelectValue = "package_file"
   352  )
   353  
   354  // GenericPackageSelect is a helper routine that allocates a new
   355  // GenericPackageSelectValue value to store v and returns a pointer to it.
   356  //
   357  // Deprecated: Please use Ptr instead.
   358  func GenericPackageSelect(v GenericPackageSelectValue) *GenericPackageSelectValue {
   359  	return Ptr(v)
   360  }
   361  
   362  // GenericPackageStatusValue represents a generic package status.
   363  type GenericPackageStatusValue string
   364  
   365  // The available generic package statuses.
   366  const (
   367  	PackageDefault GenericPackageStatusValue = "default"
   368  	PackageHidden  GenericPackageStatusValue = "hidden"
   369  )
   370  
   371  // GenericPackageStatus is a helper routine that allocates a new
   372  // GenericPackageStatusValue value to store v and returns a pointer to it.
   373  //
   374  // Deprecated: Please use Ptr instead.
   375  func GenericPackageStatus(v GenericPackageStatusValue) *GenericPackageStatusValue {
   376  	return Ptr(v)
   377  }
   378  
   379  // ISOTime represents an ISO 8601 formatted date.
   380  type ISOTime time.Time
   381  
   382  // ISO 8601 date format
   383  const iso8601 = "2006-01-02"
   384  
   385  // ParseISOTime parses an ISO 8601 formatted date.
   386  func ParseISOTime(s string) (ISOTime, error) {
   387  	t, err := time.Parse(iso8601, s)
   388  	return ISOTime(t), err
   389  }
   390  
   391  // MarshalJSON implements the json.Marshaler interface.
   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  		// ISO 8901 uses 4 digits for the years.
   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  // UnmarshalJSON implements the json.Unmarshaler interface.
   411  func (t *ISOTime) UnmarshalJSON(data []byte) error {
   412  	// Ignore null, like in the main JSON package.
   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  // EncodeValues implements the query.Encoder interface.
   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  // String implements the Stringer interface.
   433  func (t ISOTime) String() string {
   434  	return time.Time(t).Format(iso8601)
   435  }
   436  
   437  // Labels represents a list of labels.
   438  type Labels []string
   439  
   440  // LabelOptions is a custom type with specific marshaling characteristics.
   441  type LabelOptions []string
   442  
   443  // MarshalJSON implements the json.Marshaler interface.
   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  // UnmarshalJSON implements the json.Unmarshaler interface.
   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  // EncodeValues implements the query.EncodeValues interface
   461  func (l *LabelOptions) EncodeValues(key string, v *url.Values) error {
   462  	v.Set(key, strings.Join(*l, ","))
   463  	return nil
   464  }
   465  
   466  // LinkTypeValue represents a release link type.
   467  type LinkTypeValue string
   468  
   469  // List of available release link types.
   470  //
   471  // GitLab API docs:
   472  // https://docs.gitlab.com/ee/api/releases/links.html#create-a-release-link
   473  const (
   474  	ImageLinkType   LinkTypeValue = "image"
   475  	OtherLinkType   LinkTypeValue = "other"
   476  	PackageLinkType LinkTypeValue = "package"
   477  	RunbookLinkType LinkTypeValue = "runbook"
   478  )
   479  
   480  // LinkType is a helper routine that allocates a new LinkType value
   481  // to store v and returns a pointer to it.
   482  //
   483  // Deprecated: Please use Ptr instead.
   484  func LinkType(v LinkTypeValue) *LinkTypeValue {
   485  	return Ptr(v)
   486  }
   487  
   488  // LicenseApprovalStatusValue describe the approval statuses of a license.
   489  //
   490  // GitLab API docs: https://docs.gitlab.com/ee/api/managed_licenses.html
   491  type LicenseApprovalStatusValue string
   492  
   493  // List of available license approval statuses.
   494  const (
   495  	LicenseApproved    LicenseApprovalStatusValue = "approved"
   496  	LicenseBlacklisted LicenseApprovalStatusValue = "blacklisted"
   497  	LicenseAllowed     LicenseApprovalStatusValue = "allowed"
   498  	LicenseDenied      LicenseApprovalStatusValue = "denied"
   499  )
   500  
   501  // LicenseApprovalStatus is a helper routine that allocates a new license
   502  // approval status value to store v and returns a pointer to it.
   503  //
   504  // Deprecated: Please use Ptr instead.
   505  func LicenseApprovalStatus(v LicenseApprovalStatusValue) *LicenseApprovalStatusValue {
   506  	return Ptr(v)
   507  }
   508  
   509  // MergeMethodValue represents a project merge type within GitLab.
   510  //
   511  // GitLab API docs: https://docs.gitlab.com/ee/api/projects.html#project-merge-method
   512  type MergeMethodValue string
   513  
   514  // List of available merge type
   515  //
   516  // GitLab API docs: https://docs.gitlab.com/ee/api/projects.html#project-merge-method
   517  const (
   518  	NoFastForwardMerge MergeMethodValue = "merge"
   519  	FastForwardMerge   MergeMethodValue = "ff"
   520  	RebaseMerge        MergeMethodValue = "rebase_merge"
   521  )
   522  
   523  // MergeMethod is a helper routine that allocates a new MergeMethod
   524  // to store v and returns a pointer to it.
   525  //
   526  // Deprecated: Please use Ptr instead.
   527  func MergeMethod(v MergeMethodValue) *MergeMethodValue {
   528  	return Ptr(v)
   529  }
   530  
   531  // NoteTypeValue represents the type of a Note.
   532  type NoteTypeValue string
   533  
   534  // List of available note types.
   535  const (
   536  	DiffNote       NoteTypeValue = "DiffNote"
   537  	DiscussionNote NoteTypeValue = "DiscussionNote"
   538  	GenericNote    NoteTypeValue = "Note"
   539  	LegacyDiffNote NoteTypeValue = "LegacyDiffNote"
   540  )
   541  
   542  // NoteType is a helper routine that allocates a new NoteTypeValue to
   543  // store v and returns a pointer to it.
   544  //
   545  // Deprecated: Please use Ptr instead.
   546  func NoteType(v NoteTypeValue) *NoteTypeValue {
   547  	return Ptr(v)
   548  }
   549  
   550  // NotificationLevelValue represents a notification level.
   551  type NotificationLevelValue int
   552  
   553  // String implements the fmt.Stringer interface.
   554  func (l NotificationLevelValue) String() string {
   555  	return notificationLevelNames[l]
   556  }
   557  
   558  // MarshalJSON implements the json.Marshaler interface.
   559  func (l NotificationLevelValue) MarshalJSON() ([]byte, error) {
   560  	return json.Marshal(l.String())
   561  }
   562  
   563  // UnmarshalJSON implements the json.Unmarshaler interface.
   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  		// No action needed.
   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  // List of valid notification levels.
   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  // NotificationLevel is a helper routine that allocates a new NotificationLevelValue
   613  // to store v and returns a pointer to it.
   614  //
   615  // Deprecated: Please use Ptr instead.
   616  func NotificationLevel(v NotificationLevelValue) *NotificationLevelValue {
   617  	return Ptr(v)
   618  }
   619  
   620  // ProjectCreationLevelValue represents a project creation level within GitLab.
   621  //
   622  // GitLab API docs: https://docs.gitlab.com/ee/api/
   623  type ProjectCreationLevelValue string
   624  
   625  // List of available project creation levels.
   626  //
   627  // GitLab API docs: https://docs.gitlab.com/ee/api/
   628  const (
   629  	NoOneProjectCreation      ProjectCreationLevelValue = "noone"
   630  	MaintainerProjectCreation ProjectCreationLevelValue = "maintainer"
   631  	DeveloperProjectCreation  ProjectCreationLevelValue = "developer"
   632  )
   633  
   634  // ProjectCreationLevel is a helper routine that allocates a new ProjectCreationLevelValue
   635  // to store v and returns a pointer to it.
   636  // Please use Ptr instead.
   637  func ProjectCreationLevel(v ProjectCreationLevelValue) *ProjectCreationLevelValue {
   638  	return Ptr(v)
   639  }
   640  
   641  // SharedRunnersSettingValue determines whether shared runners are enabled for a
   642  // group’s subgroups and projects.
   643  //
   644  // GitLab API docs:
   645  // https://docs.gitlab.com/ee/api/groups.html#options-for-shared_runners_setting
   646  type SharedRunnersSettingValue string
   647  
   648  // List of available shared runner setting levels.
   649  //
   650  // GitLab API docs:
   651  // https://docs.gitlab.com/ee/api/groups.html#options-for-shared_runners_setting
   652  const (
   653  	EnabledSharedRunnersSettingValue                  SharedRunnersSettingValue = "enabled"
   654  	DisabledAndOverridableSharedRunnersSettingValue   SharedRunnersSettingValue = "disabled_and_overridable"
   655  	DisabledAndUnoverridableSharedRunnersSettingValue SharedRunnersSettingValue = "disabled_and_unoverridable"
   656  
   657  	// Deprecated: DisabledWithOverrideSharedRunnersSettingValue is deprecated in favor of DisabledAndOverridableSharedRunnersSettingValue
   658  	DisabledWithOverrideSharedRunnersSettingValue SharedRunnersSettingValue = "disabled_with_override"
   659  )
   660  
   661  // SharedRunnersSetting is a helper routine that allocates a new SharedRunnersSettingValue
   662  // to store v and returns a pointer to it.
   663  //
   664  // Deprecated: Please use Ptr instead.
   665  func SharedRunnersSetting(v SharedRunnersSettingValue) *SharedRunnersSettingValue {
   666  	return Ptr(v)
   667  }
   668  
   669  // SubGroupCreationLevelValue represents a sub group creation level within GitLab.
   670  //
   671  // GitLab API docs: https://docs.gitlab.com/ee/api/
   672  type SubGroupCreationLevelValue string
   673  
   674  // List of available sub group creation levels.
   675  //
   676  // GitLab API docs: https://docs.gitlab.com/ee/api/
   677  const (
   678  	OwnerSubGroupCreationLevelValue      SubGroupCreationLevelValue = "owner"
   679  	MaintainerSubGroupCreationLevelValue SubGroupCreationLevelValue = "maintainer"
   680  )
   681  
   682  // SubGroupCreationLevel is a helper routine that allocates a new SubGroupCreationLevelValue
   683  // to store v and returns a pointer to it.
   684  //
   685  // Deprecated: Please use Ptr instead.
   686  func SubGroupCreationLevel(v SubGroupCreationLevelValue) *SubGroupCreationLevelValue {
   687  	return Ptr(v)
   688  }
   689  
   690  // SquashOptionValue represents a squash optional level within GitLab.
   691  //
   692  // GitLab API docs: https://docs.gitlab.com/ee/api/projects.html#create-project
   693  type SquashOptionValue string
   694  
   695  // List of available squash options.
   696  //
   697  // GitLab API docs: https://docs.gitlab.com/ee/api/projects.html#create-project
   698  const (
   699  	SquashOptionNever      SquashOptionValue = "never"
   700  	SquashOptionAlways     SquashOptionValue = "always"
   701  	SquashOptionDefaultOff SquashOptionValue = "default_off"
   702  	SquashOptionDefaultOn  SquashOptionValue = "default_on"
   703  )
   704  
   705  // SquashOption is a helper routine that allocates a new SquashOptionValue
   706  // to store s and returns a pointer to it.
   707  //
   708  // Deprecated: Please use Ptr instead.
   709  func SquashOption(s SquashOptionValue) *SquashOptionValue {
   710  	return Ptr(s)
   711  }
   712  
   713  // TasksCompletionStatus represents tasks of the issue/merge request.
   714  type TasksCompletionStatus struct {
   715  	Count          int `json:"count"`
   716  	CompletedCount int `json:"completed_count"`
   717  }
   718  
   719  // TodoAction represents the available actions that can be performed on a todo.
   720  //
   721  // GitLab API docs: https://docs.gitlab.com/ee/api/todos.html
   722  type TodoAction string
   723  
   724  // The available todo actions.
   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  // TodoTargetType represents the available target that can be linked to a todo.
   735  //
   736  // GitLab API docs: https://docs.gitlab.com/ee/api/todos.html
   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  // UploadType represents the available upload types.
   747  type UploadType string
   748  
   749  // The available upload types.
   750  const (
   751  	UploadAvatar UploadType = "avatar"
   752  	UploadFile   UploadType = "file"
   753  )
   754  
   755  // VariableTypeValue represents a variable type within GitLab.
   756  //
   757  // GitLab API docs: https://docs.gitlab.com/ee/api/
   758  type VariableTypeValue string
   759  
   760  // List of available variable types.
   761  //
   762  // GitLab API docs: https://docs.gitlab.com/ee/api/
   763  const (
   764  	EnvVariableType  VariableTypeValue = "env_var"
   765  	FileVariableType VariableTypeValue = "file"
   766  )
   767  
   768  // VariableType is a helper routine that allocates a new VariableTypeValue
   769  // to store v and returns a pointer to it.
   770  //
   771  // Deprecated: Please use Ptr instead.
   772  func VariableType(v VariableTypeValue) *VariableTypeValue {
   773  	return Ptr(v)
   774  }
   775  
   776  // VisibilityValue represents a visibility level within GitLab.
   777  //
   778  // GitLab API docs: https://docs.gitlab.com/ee/api/
   779  type VisibilityValue string
   780  
   781  // List of available visibility levels.
   782  //
   783  // GitLab API docs: https://docs.gitlab.com/ee/api/
   784  const (
   785  	PrivateVisibility  VisibilityValue = "private"
   786  	InternalVisibility VisibilityValue = "internal"
   787  	PublicVisibility   VisibilityValue = "public"
   788  )
   789  
   790  // Visibility is a helper routine that allocates a new VisibilityValue
   791  // to store v and returns a pointer to it.
   792  //
   793  // Deprecated: Please use Ptr instead.
   794  func Visibility(v VisibilityValue) *VisibilityValue {
   795  	return Ptr(v)
   796  }
   797  
   798  // WikiFormatValue represents the available wiki formats.
   799  //
   800  // GitLab API docs: https://docs.gitlab.com/ee/api/wikis.html
   801  type WikiFormatValue string
   802  
   803  // The available wiki formats.
   804  const (
   805  	WikiFormatMarkdown WikiFormatValue = "markdown"
   806  	WikiFormatRDoc     WikiFormatValue = "rdoc"
   807  	WikiFormatASCIIDoc WikiFormatValue = "asciidoc"
   808  	WikiFormatOrg      WikiFormatValue = "org"
   809  )
   810  
   811  // WikiFormat is a helper routine that allocates a new WikiFormatValue
   812  // to store v and returns a pointer to it.
   813  //
   814  // Deprecated: Please use Ptr instead.
   815  func WikiFormat(v WikiFormatValue) *WikiFormatValue {
   816  	return Ptr(v)
   817  }
   818  
   819  // Bool is a helper routine that allocates a new bool value
   820  // to store v and returns a pointer to it.
   821  //
   822  // Deprecated: Please use Ptr instead.
   823  func Bool(v bool) *bool {
   824  	return Ptr(v)
   825  }
   826  
   827  // Int is a helper routine that allocates a new int value
   828  // to store v and returns a pointer to it.
   829  //
   830  // Deprecated: Please use Ptr instead.
   831  func Int(v int) *int {
   832  	return Ptr(v)
   833  }
   834  
   835  // String is a helper routine that allocates a new string value
   836  // to store v and returns a pointer to it.
   837  //
   838  // Deprecated: Please use Ptr instead.
   839  func String(v string) *string {
   840  	return Ptr(v)
   841  }
   842  
   843  // Time is a helper routine that allocates a new time.Time value
   844  // to store v and returns a pointer to it.
   845  //
   846  // Deprecated: Please use Ptr instead.
   847  func Time(v time.Time) *time.Time {
   848  	return Ptr(v)
   849  }
   850  
   851  // BoolValue is a boolean value with advanced json unmarshaling features.
   852  type BoolValue bool
   853  
   854  // UnmarshalJSON allows 1, 0, "true", and "false" to be considered as boolean values
   855  // Needed for:
   856  // https://gitlab.com/gitlab-org/gitlab-ce/issues/50122
   857  // https://gitlab.com/gitlab-org/gitlab/-/issues/233941
   858  // https://github.com/gitlabhq/terraform-provider-gitlab/issues/348
   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