Skip to content

Commit

Permalink
refactor: remove types dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed Oct 22, 2024
1 parent 0d47b45 commit 8cdfc24
Show file tree
Hide file tree
Showing 24 changed files with 138 additions and 147 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ require (
github.com/buildkite/yaml v0.0.0-20230306222819-0e4e032d4835
github.com/coreos/go-semver v0.3.1
github.com/gin-gonic/gin v1.10.0
github.com/go-vela/server v0.25.1-0.20241018183530-cb37db9087c5
github.com/go-vela/types v0.25.1
github.com/go-vela/server v0.25.1-0.20241022141112-a2b0d9146d65
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/google/go-cmp v0.6.0
github.com/google/go-querystring v1.1.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-vela/server v0.25.1-0.20241018183530-cb37db9087c5 h1:rj2IBy+Gy16ePQTsQYmpCfBsJyYaQFPiqmDv8EZMXE8=
github.com/go-vela/server v0.25.1-0.20241018183530-cb37db9087c5/go.mod h1:/DmGHNzsjsBOStLzlGDIDGCmNztUgCdvHiuWmyafFs8=
github.com/go-vela/types v0.25.1 h1:DCPHv1+ouqldjfsjfcVTcm/Yyd0OwazIfxYyR+GwpMo=
github.com/go-vela/types v0.25.1/go.mod h1:5+MHUI9ZSY2Uz1cTJa64FWUv8jKzzUUq96UQTokGJzs=
github.com/go-vela/server v0.25.1-0.20241022141112-a2b0d9146d65 h1:BepNezNRDLfookgMn81U9WB0/aMBxkqot9w8nLPWNhU=
github.com/go-vela/server v0.25.1-0.20241022141112-a2b0d9146d65/go.mod h1:hdVkyyxnRtk+Vjs7nCnKEkwWmd9yVQUV5Akpt7BY6wg=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
Expand Down
26 changes: 12 additions & 14 deletions vela/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (

api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/api/types/settings"
"github.com/go-vela/types"
"github.com/go-vela/types/library"
)

type (
Expand Down Expand Up @@ -101,7 +99,7 @@ func (svc *AdminBuildService) Update(b *api.Build) (*api.Build, *Response, error
// set the API endpoint path we send the request to
u := "/api/v1/admin/build"

// library Build type we want to return
// API Build type we want to return
v := new(api.Build)

// send request using client
Expand All @@ -111,7 +109,7 @@ func (svc *AdminBuildService) Update(b *api.Build) (*api.Build, *Response, error
}

// Clean sets build resources older than a specified time to a proper canceled / finished state with the provided message.
func (svc *AdminCleanService) Clean(e *types.Error, opt *CleanOptions) (*string, *Response, error) {
func (svc *AdminCleanService) Clean(e *api.Error, opt *CleanOptions) (*string, *Response, error) {
// set the API endpoint path we send the request to
u := "/api/v1/admin/clean"

Expand Down Expand Up @@ -152,7 +150,7 @@ func (svc *AdminDeploymentService) Update(d *api.Deployment) (*api.Deployment, *
// set the API endpoint path we send the request to
u := "/api/v1/admin/deployment"

// library Deployment type we want to return
// API Deployment type we want to return
v := new(api.Deployment)

// send request using client
Expand All @@ -166,7 +164,7 @@ func (svc *AdminHookService) Update(h *api.Hook) (*api.Hook, *Response, error) {
// set the API endpoint path we send the request to
u := "/api/v1/admin/hook"

// library Hook type we want to return
// API Hook type we want to return
v := new(api.Hook)

// send request using client
Expand All @@ -180,7 +178,7 @@ func (svc *AdminRepoService) Update(r *api.Repo) (*api.Repo, *Response, error) {
// set the API endpoint path we send the request to
u := "/api/v1/admin/repo"

// library Repo type we want to return
// API Repo type we want to return
v := new(api.Repo)

// send request using client
Expand All @@ -194,7 +192,7 @@ func (svc *AdminSecretService) Update(s *api.Secret) (*api.Secret, *Response, er
// set the API endpoint path we send the request to
u := "/api/v1/admin/secret"

// library Secret type we want to return
// API Secret type we want to return
v := new(api.Secret)

// send request using client
Expand All @@ -208,7 +206,7 @@ func (svc *AdminSvcService) Update(s *api.Service) (*api.Service, *Response, err
// set the API endpoint path we send the request to
u := "/api/v1/admin/service"

// library Service type we want to return
// API Service type we want to return
v := new(api.Service)

// send request using client
Expand All @@ -222,7 +220,7 @@ func (svc *AdminStepService) Update(s *api.Step) (*api.Step, *Response, error) {
// set the API endpoint path we send the request to
u := "/api/v1/admin/step"

// library Step type we want to return
// API Step type we want to return
v := new(api.Step)

// send request using client
Expand All @@ -236,7 +234,7 @@ func (svc *AdminUserService) Update(u *api.User) (*api.User, *Response, error) {
// set the API endpoint path we send the request to
url := "/api/v1/admin/user"

// library User type we want to return
// API User type we want to return
v := new(api.User)

// send request using client
Expand Down Expand Up @@ -289,7 +287,7 @@ func (svc *AdminSettingsService) Restore() (*settings.Platform, *Response, error
}

// RegisterToken generates a worker registration token with the provided details.
func (svc *AdminWorkerService) RegisterToken(hostname string) (*library.Token, *Response, error) {
func (svc *AdminWorkerService) RegisterToken(hostname string) (*api.Token, *Response, error) {
// validate input
if strings.EqualFold(hostname, "") {
return nil, nil, errors.New("bad request, no hostname provided")
Expand All @@ -298,8 +296,8 @@ func (svc *AdminWorkerService) RegisterToken(hostname string) (*library.Token, *
// set the API endpoint path we send the request to
url := fmt.Sprintf("/api/v1/admin/workers/%s/register", hostname)

// library Token type we want to return
t := new(library.Token)
// API Token type we want to return
t := new(api.Token)

// send request using client
resp, err := svc.client.Call("POST", url, nil, t)
Expand Down
8 changes: 3 additions & 5 deletions vela/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
"github.com/go-vela/server/api/types/actions"
"github.com/go-vela/server/api/types/settings"
"github.com/go-vela/server/mock/server"
"github.com/go-vela/types"
"github.com/go-vela/types/library"
)

func TestAdmin_Build_Update_200(t *testing.T) {
Expand Down Expand Up @@ -64,7 +62,7 @@ func TestAdmin_Clean_200(t *testing.T) {

want := server.CleanResourcesResp

req := types.Error{
req := api.Error{
Message: String("msg"),
}

Expand All @@ -91,7 +89,7 @@ func TestAdmin_Clean_Error(t *testing.T) {
s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

req := types.Error{
req := api.Error{
Message: String("msg"),
}

Expand Down Expand Up @@ -421,7 +419,7 @@ func TestAdmin_Worker_RegistrationToken_201(t *testing.T) {

data := []byte(server.RegisterTokenResp)

var want *library.Token
var want *api.Token

err := json.Unmarshal(data, &want)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions vela/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"fmt"
"net/http"

"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/constants"
)

type AuthenticationType int
Expand Down Expand Up @@ -94,7 +94,7 @@ func (svc *AuthenticationService) RefreshAccessToken(refreshToken string) (*Resp
// set the API endpoint path we send the request to
u := "/token-refresh"

v := new(library.Token)
v := new(api.Token)

// building a custom request -
// we can't use svc.client.NewRequest because
Expand Down Expand Up @@ -139,7 +139,7 @@ func (svc *AuthenticationService) AuthenticateWithToken(token string) (string, *
}

// will hold access token
v := new(library.Token)
v := new(api.Token)

// building a custom request -
// we can't use svc.client.NewRequest because
Expand Down Expand Up @@ -172,7 +172,7 @@ func (svc *AuthenticationService) ExchangeTokens(opt *OAuthExchangeOptions) (str
u := "/authenticate"

// will hold access token
v := new(library.Token)
v := new(api.Token)

// check required arguments
if len(opt.Code) == 0 || len(opt.State) == 0 {
Expand Down
8 changes: 4 additions & 4 deletions vela/authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

"github.com/gin-gonic/gin"

api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/mock/server"
"github.com/go-vela/types/library"
)

func TestVela_Authentication_SetTokenAuth(t *testing.T) {
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestVela_Authentication_RefreshAccessToken(t *testing.T) {

data := []byte(server.TokenRefreshResp)

var want library.Token
var want api.Token
_ = json.Unmarshal(data, &want)

// run test
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestVela_Authentication_AuthenticateWithToken(t *testing.T) {

data := []byte(server.TokenRefreshResp)

var want library.Token
var want api.Token
_ = json.Unmarshal(data, &want)

// run test
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestVela_Authentication_ExchangeTokens(t *testing.T) {

data := []byte(server.TokenRefreshResp)

var want library.Token
var want api.Token
_ = json.Unmarshal(data, &want)

// create options
Expand Down
41 changes: 20 additions & 21 deletions vela/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"

api "github.com/go-vela/server/api/types"
"github.com/go-vela/types/library"
)

// BuildService handles retrieving builds from
Expand Down Expand Up @@ -44,7 +43,7 @@ func (svc *BuildService) Get(org, repo string, build int) (*api.Build, *Response
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d", org, repo, build)

// library Build type we want to return
// API Build type we want to return
v := new(api.Build)

// send request using client
Expand All @@ -54,12 +53,12 @@ func (svc *BuildService) Get(org, repo string, build int) (*api.Build, *Response
}

// GetBuildExecutable returns the executable for the provided build.
func (svc *BuildService) GetBuildExecutable(org, repo string, build int) (*library.BuildExecutable, *Response, error) {
func (svc *BuildService) GetBuildExecutable(org, repo string, build int) (*api.BuildExecutable, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/executable", org, repo, build)

// library Build type we want to return
v := new(library.BuildExecutable)
// API Build type we want to return
v := new(api.BuildExecutable)

// send request using client
resp, err := svc.client.Call("GET", u, nil, v)
Expand All @@ -78,7 +77,7 @@ func (svc *BuildService) GetAll(org, repo string, opt *BuildListOptions) (*[]api
return nil, nil, err
}

// slice library Build type we want to return
// slice API Build type we want to return
v := new([]api.Build)

// send request using client
Expand All @@ -88,7 +87,7 @@ func (svc *BuildService) GetAll(org, repo string, opt *BuildListOptions) (*[]api
}

// GetLogs returns the provided build logs.
func (svc *BuildService) GetLogs(org, repo string, build int, opt *ListOptions) (*[]library.Log, *Response, error) {
func (svc *BuildService) GetLogs(org, repo string, build int, opt *ListOptions) (*[]api.Log, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/logs", org, repo, build)

Expand All @@ -99,7 +98,7 @@ func (svc *BuildService) GetLogs(org, repo string, build int, opt *ListOptions)
}

// slice database Log type we want to return
v := new([]library.Log)
v := new([]api.Log)

// send request using client
resp, err := svc.client.Call("GET", u, nil, v)
Expand All @@ -112,7 +111,7 @@ func (svc *BuildService) Add(b *api.Build) (*api.Build, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds", b.GetRepo().GetOrg(), b.GetRepo().GetName())

// library Build type we want to return
// API Build type we want to return
v := new(api.Build)

// send request using client
Expand All @@ -126,7 +125,7 @@ func (svc *BuildService) Update(b *api.Build) (*api.Build, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d", b.GetRepo().GetOrg(), b.GetRepo().GetName(), b.GetNumber())

// library Build type we want to return
// API Build type we want to return
v := new(api.Build)

// send request using client
Expand Down Expand Up @@ -154,7 +153,7 @@ func (svc *BuildService) Restart(org, repo string, build int) (*api.Build, *Resp
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d", org, repo, build)

// library Build type we want to return
// API Build type we want to return
v := new(api.Build)

// send request using client
Expand All @@ -168,7 +167,7 @@ func (svc *BuildService) Cancel(org, repo string, build int) (*api.Build, *Respo
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/cancel", org, repo, build)

// library Build type we want to return
// API Build type we want to return
v := new(api.Build)

// send request using client
Expand All @@ -186,12 +185,12 @@ func (svc *BuildService) Approve(org, repo string, build int) (*Response, error)
}

// GetBuildToken returns an auth token for updating build resources.
func (svc *BuildService) GetBuildToken(org, repo string, build int) (*library.Token, *Response, error) {
func (svc *BuildService) GetBuildToken(org, repo string, build int) (*api.Token, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/token", org, repo, build)

// library Token type we want to return
t := new(library.Token)
// API Token type we want to return
t := new(api.Token)

// send request using client
resp, err := svc.client.Call("GET", u, nil, t)
Expand All @@ -200,7 +199,7 @@ func (svc *BuildService) GetBuildToken(org, repo string, build int) (*library.To
}

// GetIDRequestToken returns an id request token for integrating with build OIDC.
func (svc *BuildService) GetIDRequestToken(org, repo string, build int, opt *RequestTokenOptions) (*library.Token, *Response, error) {
func (svc *BuildService) GetIDRequestToken(org, repo string, build int, opt *RequestTokenOptions) (*api.Token, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/id_request_token", org, repo, build)

Expand All @@ -210,8 +209,8 @@ func (svc *BuildService) GetIDRequestToken(org, repo string, build int, opt *Req
return nil, nil, err
}

// library Token type we want to return
t := new(library.Token)
// API Token type we want to return
t := new(api.Token)

// send request using client
resp, err := svc.client.Call("GET", u, nil, t)
Expand All @@ -220,7 +219,7 @@ func (svc *BuildService) GetIDRequestToken(org, repo string, build int, opt *Req
}

// GetIDToken returns an ID token corresponding to the request token during a build.
func (svc *BuildService) GetIDToken(org, repo string, build int, opt *IDTokenOptions) (*library.Token, *Response, error) {
func (svc *BuildService) GetIDToken(org, repo string, build int, opt *IDTokenOptions) (*api.Token, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/id_token", org, repo, build)

Expand All @@ -230,8 +229,8 @@ func (svc *BuildService) GetIDToken(org, repo string, build int, opt *IDTokenOpt
return nil, nil, err
}

// library Token type we want to return
t := new(library.Token)
// API Token type we want to return
t := new(api.Token)

// send request using client
resp, err := svc.client.Call("GET", u, nil, t)
Expand Down
Loading

0 comments on commit 8cdfc24

Please sign in to comment.