|
| 1 | +// Package request contains plain old Go types used in the Gin endpoint handlers |
| 2 | +// and Swaggo documentation for the HTTP request models, with Gin- and |
| 3 | +// Swaggo-specific Go tags. |
| 4 | +// |
| 5 | +// Copied from https://github.com/iver-wharf/wharf-api/blob/v5.0.0/pkg/model/request/request.go |
| 6 | +package request |
| 7 | + |
| 8 | +import ( |
| 9 | + "time" |
| 10 | +) |
| 11 | + |
| 12 | +// Reference doc about the Go tags: |
| 13 | +// TAG SOURCE DESCRIPTION |
| 14 | +// json:"foo" encoding/json Serializes field with the name "foo" |
| 15 | +// format:"date-time" swaggo/swag Swagger format |
| 16 | +// validate:"required" swaggo/swag Mark Swagger field as required/non-nullable |
| 17 | +// binding:"required" go-playground/validator Gin's Bind will error if nil or zero |
| 18 | +// |
| 19 | +// go-playground/validator uses the tag "validate" by default, but Gin overrides |
| 20 | +// changes that to "binding". |
| 21 | + |
| 22 | +// TokenSearch holds values used in verbatim searches for tokens. |
| 23 | +type TokenSearch struct { |
| 24 | + Token string `json:"token" format:"password"` |
| 25 | + UserName string `json:"userName"` |
| 26 | +} |
| 27 | + |
| 28 | +// Token specifies fields when creating a new token. |
| 29 | +type Token struct { |
| 30 | + Token string `json:"token" format:"password" validate:"required"` |
| 31 | + UserName string `json:"userName" validate:"required"` |
| 32 | + ProviderID uint `json:"providerId" minimum:"0"` |
| 33 | +} |
| 34 | + |
| 35 | +// TokenUpdate specifies fields when updating a token. |
| 36 | +type TokenUpdate struct { |
| 37 | + Token string `json:"token" format:"password" validate:"required"` |
| 38 | + UserName string `json:"userName" validate:"required"` |
| 39 | +} |
| 40 | + |
| 41 | +// Branch specifies fields when adding a new branch to a project. |
| 42 | +type Branch struct { |
| 43 | + Name string `json:"name" validate:"required"` |
| 44 | + Default bool `json:"default"` |
| 45 | +} |
| 46 | + |
| 47 | +// BranchUpdate specifies fields for a single branch. |
| 48 | +type BranchUpdate struct { |
| 49 | + Name string `json:"name" validate:"required"` |
| 50 | +} |
| 51 | + |
| 52 | +// BranchListUpdate specifies fields when resetting all branches for a project. |
| 53 | +type BranchListUpdate struct { |
| 54 | + DefaultBranch string `json:"defaultBranch" extensions:"x-nullable"` |
| 55 | + Branches []BranchUpdate `json:"branches"` |
| 56 | +} |
| 57 | + |
| 58 | +// LogOrStatusUpdate is a single log line, together with its timestamp of when |
| 59 | +// it was logged; or a build status update. |
| 60 | +// |
| 61 | +// The build status field takes precedence, and if set it will update the |
| 62 | +// build's status, while the message and the timestamp is ignored. |
| 63 | +type LogOrStatusUpdate struct { |
| 64 | + Message string `json:"message"` |
| 65 | + Timestamp time.Time `json:"timestamp" format:"date-time"` |
| 66 | + Status BuildStatus `json:"status" enums:",Scheduling,Running,Completed,Failed"` |
| 67 | +} |
| 68 | + |
| 69 | +// BuildStatus is an enum of different states for a build. |
| 70 | +type BuildStatus string |
| 71 | + |
| 72 | +const ( |
| 73 | + // BuildScheduling means the build has been registered, but no code |
| 74 | + // execution has begun yet. This is usually quite an ephemeral state. |
| 75 | + BuildScheduling BuildStatus = "Scheduling" |
| 76 | + // BuildRunning means the build is executing right now. The execution |
| 77 | + // engine has load in the target code paths and repositories. |
| 78 | + BuildRunning BuildStatus = "Running" |
| 79 | + // BuildCompleted means the build has finished execution successfully. |
| 80 | + BuildCompleted BuildStatus = "Completed" |
| 81 | + // BuildFailed means that something went wrong with the build. Could be a |
| 82 | + // misconfiguration in the .wharf-ci.yml file, or perhaps a scripting error |
| 83 | + // in some build step. |
| 84 | + BuildFailed BuildStatus = "Failed" |
| 85 | +) |
| 86 | + |
| 87 | +// BuildStatusUpdate allows you to update the status of a build. |
| 88 | +type BuildStatusUpdate struct { |
| 89 | + Status BuildStatus `json:"status" enums:"Scheduling,Running,Completed,Failed"` |
| 90 | +} |
| 91 | + |
| 92 | +// BuildInputs is a key-value object of input variables used when starting a new |
| 93 | +// build, where the key is the input variable name and the value is its string, |
| 94 | +// boolean, or numeric value. |
| 95 | +type BuildInputs map[string]interface{} |
| 96 | + |
| 97 | +// Project specifies fields when creating a new project. |
| 98 | +type Project struct { |
| 99 | + Name string `json:"name" validate:"required" binding:"required"` |
| 100 | + GroupName string `json:"groupName"` |
| 101 | + Description string `json:"description"` |
| 102 | + AvatarURL string `json:"avatarUrl"` |
| 103 | + TokenID uint `json:"tokenId" minimum:"0"` |
| 104 | + ProviderID uint `json:"providerId" minimum:"0"` |
| 105 | + BuildDefinition string `json:"buildDefinition"` |
| 106 | + GitURL string `json:"gitUrl"` |
| 107 | + RemoteProjectID string `json:"remoteProjectId"` |
| 108 | +} |
| 109 | + |
| 110 | +// ProjectUpdate specifies fields when updating a project. |
| 111 | +type ProjectUpdate struct { |
| 112 | + Name string `json:"name" validate:"required" binding:"required"` |
| 113 | + GroupName string `json:"groupName"` |
| 114 | + Description string `json:"description"` |
| 115 | + AvatarURL string `json:"avatarUrl"` |
| 116 | + TokenID uint `json:"tokenId" minimum:"0"` |
| 117 | + ProviderID uint `json:"providerId" minimum:"0"` |
| 118 | + BuildDefinition string `json:"buildDefinition"` |
| 119 | + GitURL string `json:"gitUrl"` |
| 120 | +} |
| 121 | + |
| 122 | +// ProjectOverridesUpdate specifies fields when updating a project's overrides. |
| 123 | +type ProjectOverridesUpdate struct { |
| 124 | + Description string `json:"description"` |
| 125 | + AvatarURL string `json:"avatarUrl"` |
| 126 | + GitURL string `json:"gitUrl"` |
| 127 | +} |
| 128 | + |
| 129 | +// ProviderName is an enum of different providers that are available over at |
| 130 | +// https://github.com/iver-wharf |
| 131 | +type ProviderName string |
| 132 | + |
| 133 | +const ( |
| 134 | + // ProviderAzureDevOps refers to the Azure DevOps provider plugin, |
| 135 | + // https://github.com/iver-wharf/wharf-provider-azuredevops |
| 136 | + ProviderAzureDevOps ProviderName = "azuredevops" |
| 137 | + // ProviderGitLab refers to the GitLab provider plugin, |
| 138 | + // https://github.com/iver-wharf/wharf-provider-gitlab |
| 139 | + ProviderGitLab ProviderName = "gitlab" |
| 140 | + // ProviderGitHub refers to the GitHub provider plugin, |
| 141 | + // https://github.com/iver-wharf/wharf-provider-github |
| 142 | + ProviderGitHub ProviderName = "github" |
| 143 | + // ProviderNameValues is a concatenated list of the different provider names |
| 144 | + // available. Useful in validation error messages. |
| 145 | + ProviderNameValues = ProviderAzureDevOps + ", " + ProviderGitLab + ", " + ProviderGitHub |
| 146 | +) |
| 147 | + |
| 148 | +// IsValid returns false if the underlying type is an unknown enum value. |
| 149 | +// ProviderGitHub.IsValid() // => true |
| 150 | +// (ProviderName("")).IsValid() // => false |
| 151 | +func (name ProviderName) IsValid() bool { |
| 152 | + return name == ProviderAzureDevOps || |
| 153 | + name == ProviderGitLab || |
| 154 | + name == ProviderGitHub |
| 155 | +} |
| 156 | + |
| 157 | +// ValidString returns the name as a string if valid, as well as the boolean |
| 158 | +// value true, or false if the name is invalid. |
| 159 | +// ProviderGitHub.ValidString() // => "github", true |
| 160 | +// (ProviderName("")).ValidString() // => "", false |
| 161 | +func (name ProviderName) ValidString() (string, bool) { |
| 162 | + if name.IsValid() { |
| 163 | + return string(name), true |
| 164 | + } |
| 165 | + return "", false |
| 166 | +} |
| 167 | + |
| 168 | +// ProviderSearch holds values used in verbatim searches for providers. |
| 169 | +type ProviderSearch struct { |
| 170 | + Name ProviderName `json:"name" enums:"azuredevops,gitlab,github"` |
| 171 | + URL string `json:"url"` |
| 172 | + TokenID uint `json:"tokenId" minimum:"0"` |
| 173 | +} |
| 174 | + |
| 175 | +// Provider specifies fields when creating a new provider. |
| 176 | +type Provider struct { |
| 177 | + Name ProviderName `json:"name" enums:"azuredevops,gitlab,github" validate:"required" binding:"required"` |
| 178 | + URL string `json:"url" validate:"required" binding:"required"` |
| 179 | + TokenID uint `json:"tokenId" minimum:"0"` |
| 180 | +} |
| 181 | + |
| 182 | +// ProviderUpdate specifies fields when updating a provider. |
| 183 | +type ProviderUpdate struct { |
| 184 | + Name ProviderName `json:"name" enums:"azuredevops,gitlab,github" validate:"required" binding:"required"` |
| 185 | + URL string `json:"url" validate:"required" binding:"required"` |
| 186 | + TokenID uint `json:"tokenId" minimum:"0"` |
| 187 | +} |
0 commit comments