Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: change types to api types #336

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +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
github.com/go-vela/server v0.25.1-0.20241011184259-67a8e47f475e
github.com/go-vela/types v0.25.1
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/google/go-cmp v0.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +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 h1:KM3g5ZD3N6SnttnkfOyJjS2utbL6baKx0mGSJLCEf0c=
github.com/go-vela/server v0.25.1/go.mod h1:QZ9troVMUpDCAdUxxAquHqahkeSwp9Lmx6a47ao0gGs=
github.com/go-vela/server v0.25.1-0.20241011184259-67a8e47f475e h1:3wUbrVnaMvZSbl8zrU5iHzkYh1xU5fo/QQD/ILcOe5g=
github.com/go-vela/server v0.25.1-0.20241011184259-67a8e47f475e/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/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
Expand Down
8 changes: 4 additions & 4 deletions vela/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ func (svc *AdminBuildService) GetQueue(opt *GetQueueOptions) (*[]api.QueueBuild,
}

// Update modifies a deployment with the provided details.
func (svc *AdminDeploymentService) Update(d *library.Deployment) (*library.Deployment, *Response, error) {
func (svc *AdminDeploymentService) Update(d *api.Deployment) (*api.Deployment, *Response, error) {
// set the API endpoint path we send the request to
u := "/api/v1/admin/deployment"

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

// send request using client
resp, err := svc.client.Call("PUT", u, d, v)
Expand All @@ -162,12 +162,12 @@ func (svc *AdminDeploymentService) Update(d *library.Deployment) (*library.Deplo
}

// Update modifies a hook with the provided details.
func (svc *AdminHookService) Update(h *library.Hook) (*library.Hook, *Response, error) {
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
v := new(library.Hook)
v := new(api.Hook)

// send request using client
resp, err := svc.client.Call("PUT", u, h, v)
Expand Down
10 changes: 4 additions & 6 deletions vela/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,10 @@ func TestAdmin_Deployment_Update_200(t *testing.T) {

data := []byte(server.DeploymentResp)

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

want.SetBuilds(nil)

req := library.Deployment{
req := api.Deployment{
Commit: String("48afb5bdc41ad69bf22588491333f7cf71135163"),
Ref: String("refs/heads/main"),
Task: String("vela-deploy"),
Expand Down Expand Up @@ -164,10 +162,10 @@ func TestAdmin_Hook_Update_200(t *testing.T) {

data := []byte(server.HookResp)

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

req := library.Hook{
req := api.Hook{
Number: Int(1),
Event: String("push"),
Status: String("success"),
Expand Down
14 changes: 7 additions & 7 deletions vela/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ package vela
import (
"fmt"

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

// DeploymentService handles retrieving deployments from
// the server methods of the Vela API.
type DeploymentService service

// Get returns the provided deployment.
func (svc *DeploymentService) Get(org, repo string, deployment int) (*library.Deployment, *Response, error) {
func (svc *DeploymentService) Get(org, repo string, deployment int) (*api.Deployment, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/deployments/%s/%s/%d", org, repo, deployment)

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

// send request using client
resp, err := svc.client.Call("GET", u, nil, v)
Expand All @@ -27,7 +27,7 @@ func (svc *DeploymentService) Get(org, repo string, deployment int) (*library.De
}

// GetAll returns a list of all deployments.
func (svc *DeploymentService) GetAll(org, repo string, opt *ListOptions) (*[]library.Deployment, *Response, error) {
func (svc *DeploymentService) GetAll(org, repo string, opt *ListOptions) (*[]api.Deployment, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/deployments/%s/%s", org, repo)

Expand All @@ -38,7 +38,7 @@ func (svc *DeploymentService) GetAll(org, repo string, opt *ListOptions) (*[]lib
}

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

// send request using client
resp, err := svc.client.Call("GET", u, nil, v)
Expand All @@ -47,12 +47,12 @@ func (svc *DeploymentService) GetAll(org, repo string, opt *ListOptions) (*[]lib
}

// Add constructs a deployment with the provided details.
func (svc *DeploymentService) Add(org, repo string, d *library.Deployment) (*library.Deployment, *Response, error) {
func (svc *DeploymentService) Add(org, repo string, d *api.Deployment) (*api.Deployment, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/deployments/%s/%s", org, repo)

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

// send request using client
resp, err := svc.client.Call("POST", u, d, v)
Expand Down
23 changes: 10 additions & 13 deletions vela/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
"testing"

"github.com/gin-gonic/gin"
"github.com/google/go-cmp/cmp"

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

func TestDeployment_Get_200(t *testing.T) {
Expand All @@ -25,11 +26,9 @@ func TestDeployment_Get_200(t *testing.T) {

data := []byte(server.DeploymentResp)

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

want.SetBuilds(nil)

// run test
got, resp, err := c.Deployment.Get("github", "octocat", 1)

Expand All @@ -41,8 +40,8 @@ func TestDeployment_Get_200(t *testing.T) {
t.Errorf("Get returned %v, want %v", resp.StatusCode, http.StatusOK)
}

if !reflect.DeepEqual(got, &want) {
t.Errorf("Get is %v, want %v", got, want)
if diff := cmp.Diff(&want, got); diff != "" {
t.Errorf("Get mismatch (-want +got):\n%s", diff)
}
}

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

want := library.Deployment{}
want := api.Deployment{}

// run test
got, resp, err := c.Deployment.Get("github", "octocat", 0)
Expand All @@ -80,7 +79,7 @@ func TestDeployment_GetAll_200(t *testing.T) {

data := []byte(server.DeploymentsResp)

var want []library.Deployment
var want []api.Deployment
_ = json.Unmarshal(data, &want)

// run test
Expand Down Expand Up @@ -108,12 +107,10 @@ func TestDeployment_Add_201(t *testing.T) {

data := []byte(server.DeploymentResp)

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

want.SetBuilds(nil)

req := library.Deployment{
req := api.Deployment{
Commit: String("48afb5bdc41ad69bf22588491333f7cf71135163"),
Ref: String("refs/heads/main"),
Task: String("vela-deploy"),
Expand Down Expand Up @@ -176,7 +173,7 @@ func ExampleDeploymentService_Add() {
// Set new token in existing client
c.Authentication.SetPersonalAccessTokenAuth("token")

req := library.Deployment{
req := api.Deployment{
Commit: String("48afb5bdc41ad69bf22588491333f7cf71135163"),
Ref: String("refs/heads/main"),
Task: String("vela-deploy"),
Expand Down
18 changes: 9 additions & 9 deletions vela/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ package vela
import (
"fmt"

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

// HookService handles retrieving hooks from
// the server methods of the Vela API.
type HookService service

// Get returns the provided hook.
func (svc *HookService) Get(org, repo string, hook int) (*library.Hook, *Response, error) {
func (svc *HookService) Get(org, repo string, hook int) (*api.Hook, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/hooks/%s/%s/%d", org, repo, hook)

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

// send request using client
resp, err := svc.client.Call("GET", u, nil, v)
Expand All @@ -27,7 +27,7 @@ func (svc *HookService) Get(org, repo string, hook int) (*library.Hook, *Respons
}

// GetAll returns a list of all hooks.
func (svc *HookService) GetAll(org, repo string, opt *ListOptions) (*[]library.Hook, *Response, error) {
func (svc *HookService) GetAll(org, repo string, opt *ListOptions) (*[]api.Hook, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/hooks/%s/%s", org, repo)

Expand All @@ -38,7 +38,7 @@ func (svc *HookService) GetAll(org, repo string, opt *ListOptions) (*[]library.H
}

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

// send request using client
resp, err := svc.client.Call("GET", u, nil, v)
Expand All @@ -47,12 +47,12 @@ func (svc *HookService) GetAll(org, repo string, opt *ListOptions) (*[]library.H
}

// Add constructs a hook with the provided details.
func (svc *HookService) Add(org, repo string, h *library.Hook) (*library.Hook, *Response, error) {
func (svc *HookService) Add(org, repo string, h *api.Hook) (*api.Hook, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/hooks/%s/%s", org, repo)

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

// send request using client
resp, err := svc.client.Call("POST", u, h, v)
Expand All @@ -61,12 +61,12 @@ func (svc *HookService) Add(org, repo string, h *library.Hook) (*library.Hook, *
}

// Update modifies a hook with the provided details.
func (svc *HookService) Update(org, repo string, h *library.Hook) (*library.Hook, *Response, error) {
func (svc *HookService) Update(org, repo string, h *api.Hook) (*api.Hook, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/hooks/%s/%s/%d", org, repo, h.GetNumber())

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

// send request using client
resp, err := svc.client.Call("PUT", u, h, v)
Expand Down
24 changes: 12 additions & 12 deletions vela/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,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 TestHook_Get_200(t *testing.T) {
Expand All @@ -25,7 +25,7 @@ func TestHook_Get_200(t *testing.T) {

data := []byte(server.HookResp)

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

// run test
Expand All @@ -51,7 +51,7 @@ func TestHook_Get_404(t *testing.T) {
s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

want := library.Hook{}
want := api.Hook{}

// run test
got, resp, err := c.Hook.Get("github", "octocat", 0)
Expand All @@ -78,7 +78,7 @@ func TestHook_GetAll_200(t *testing.T) {

data := []byte(server.HooksResp)

var want []library.Hook
var want []api.Hook
_ = json.Unmarshal(data, &want)

// run test
Expand Down Expand Up @@ -106,10 +106,10 @@ func TestHook_Add_201(t *testing.T) {

data := []byte(server.HookResp)

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

req := library.Hook{
req := api.Hook{
Number: Int(1),
SourceID: String("c8da1302-07d6-11ea-882f-4893bca275b8"),
Event: String("push"),
Expand Down Expand Up @@ -146,10 +146,10 @@ func TestHook_Update_200(t *testing.T) {

data := []byte(server.HookResp)

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

req := library.Hook{
req := api.Hook{
Number: Int(1),
Event: String("push"),
Status: String("success"),
Expand Down Expand Up @@ -178,9 +178,9 @@ func TestHook_Update_404(t *testing.T) {
s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

want := library.Hook{}
want := api.Hook{}

req := library.Hook{
req := api.Hook{
Number: Int(0),
Event: String("push"),
Status: String("running"),
Expand Down Expand Up @@ -279,7 +279,7 @@ func ExampleHookService_Add() {
// Set new token in existing client
c.Authentication.SetPersonalAccessTokenAuth("token")

req := library.Hook{
req := api.Hook{
Number: Int(1),
SourceID: String("c8da1302-07d6-11ea-882f-4893bca275b8"),
Event: String("push"),
Expand Down Expand Up @@ -307,7 +307,7 @@ func ExampleHookService_Update() {
// Set new token in existing client
c.Authentication.SetPersonalAccessTokenAuth("token")

req := library.Hook{
req := api.Hook{
Status: String("error"),
Error: String(""),
}
Expand Down
Loading
Loading