Skip to content

Commit 6701727

Browse files
authored
Updated to be wharf-api v5.0.0 compatible (#29)
* Updated to use wharf-api/v5 * Updated/Created/Removed methods to match [wharf-api v5.0.0](iver-wharf/wharf-api#129) endpoints. * Updated minimum Go version from 1.13 to 1.16. * Updated `github.com/iver-wharf/wharf-core` from v1.2.0 to v1.3.0. * Added dependency on `github.com/google/go-querystring` v1.0.0. * Copied wharf-api/pkg/model/request and response from [wharf-api v5.0.0](iver-wharf/wharf-api#129). * Changed to return io.ReadCloser instead of *io.ReadCloser.
1 parent bc78285 commit 6701727

File tree

16 files changed

+1165
-585
lines changed

16 files changed

+1165
-585
lines changed

CHANGELOG.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ This project tries to follow [SemVer 2.0.0](https://semver.org/).
1717
- BREAKING: Changed module path from `github.com/iver-wharf/wharf-api-client-go`
1818
to `github.com/iver-wharf/wharf-api-client-go/v2`. (#30)
1919

20-
- Removed the `wharfapi.Provider.UploadURL` field, which will be removed from
21-
the `Provider` struct in `github.com/iver-wharf/wharf-api` in v5.0.0. (#21)
20+
- BREAKING: Changed minimum version of Go from 1.13 to 1.16. (#29)
21+
22+
- BREAKING: Removed support for wharf-api v4.2.0 and below. (#29)
23+
24+
- Added support for wharf-api v5. (#29)
25+
26+
- Changed version of `github.com/iver-wharf/wharf-core` from v1.2.0 to v1.3.0.
27+
(#29)
28+
29+
- Added dependency `github.com/google/go-querystring` v1.1.0. (#29)
2230

2331
## v1.4.0 (2021-09-07)
2432

@@ -36,7 +44,7 @@ This project tries to follow [SemVer 2.0.0](https://semver.org/).
3644
(#12, #13, #16)
3745

3846
- Changed all logging via `fmt.Print` and sirupsen/logrus to instead use the new
39-
`github.com/iver-wharf/wharf-core/pkg/logger`. (#13)
47+
`github.com/iver-wharf/wharf-core/pkg/logger`. (#13)
4048

4149
- Changed to use `problem.Response` from `wharf-core` instead of the
4250
`wharfapi.Problem` that was added in v1.3.0/#4. (#12, #14)

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ serialize/deserialize each message back and forth.
1111
This project is for example used inside the providers to create projects
1212
into the database when importing from GitLab, GitHub, or Azure DevOps.
1313

14+
## Compatibility
15+
16+
| wharf-api-client-go | wharf-api |
17+
| :---: | :---: |
18+
| v1 | v0, v1, v2, v3, v4, *and* v5<sup>1</sup> |
19+
| v2 | v5, *and beyond* |
20+
21+
<sup>1</sup>: The `PUT` endpoints `/api/project`, `/api/token`, and `/api/provider` were removed in `wharf-api v5.0.0`.
22+
1423
## Usage
1524

1625
```console

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
module github.com/iver-wharf/wharf-api-client-go/v2
22

3-
go 1.13
3+
go 1.16
44

55
require (
6-
github.com/iver-wharf/wharf-core v1.1.0
6+
github.com/google/go-querystring v1.1.0
7+
github.com/iver-wharf/wharf-core v1.3.0
78
github.com/stretchr/testify v1.7.0
89
gopkg.in/guregu/null.v4 v4.0.0
910
)

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ
116116
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
117117
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
118118
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
119+
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
120+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
121+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
122+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
119123
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
120124
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
121125
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
@@ -162,8 +166,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
162166
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
163167
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
164168
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
165-
github.com/iver-wharf/wharf-core v1.1.0 h1:vdjW+A8p0GBBcd1sB3vKwpN44t0dBrYfpY+B6ebSMbI=
166-
github.com/iver-wharf/wharf-core v1.1.0/go.mod h1:dpYtdL52i17Aue7An6mJL9dICeulBDsGZO/PxZYHgrE=
169+
github.com/iver-wharf/wharf-core v1.3.0 h1:iJqa0JYBkMmJDkBKeErKCpZCa+qa97u5MLMBQ685Jhs=
170+
github.com/iver-wharf/wharf-core v1.3.0/go.mod h1:dpYtdL52i17Aue7An6mJL9dICeulBDsGZO/PxZYHgrE=
167171
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
168172
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
169173
github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=

pkg/model/request/request.go

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
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

Comments
 (0)