From d6327a2cd13afdb164450cc29a968da3e19aecc3 Mon Sep 17 00:00:00 2001 From: ecrupper Date: Fri, 11 Oct 2024 13:55:09 -0500 Subject: [PATCH 1/2] chore: change types to api types --- go.mod | 2 +- go.sum | 2 ++ vela/admin.go | 8 ++++---- vela/admin_test.go | 10 ++++------ vela/deployment.go | 14 +++++++------- vela/deployment_test.go | 23 ++++++++++------------- vela/hook.go | 18 +++++++++--------- vela/hook_test.go | 24 ++++++++++++------------ vela/pipeline.go | 20 ++++++++++---------- vela/pipeline_test.go | 26 +++++++++++++------------- 10 files changed, 72 insertions(+), 75 deletions(-) diff --git a/go.mod b/go.mod index cef68c0..344a7fb 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index b911314..ce9c673 100644 --- a/go.sum +++ b/go.sum @@ -37,6 +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.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/server v0.25.1 h1:KM3g5ZD3N6SnttnkfOyJjS2utbL6baKx0mGSJLCEf0c= github.com/go-vela/server v0.25.1/go.mod h1:QZ9troVMUpDCAdUxxAquHqahkeSwp9Lmx6a47ao0gGs= github.com/go-vela/types v0.25.1 h1:DCPHv1+ouqldjfsjfcVTcm/Yyd0OwazIfxYyR+GwpMo= diff --git a/vela/admin.go b/vela/admin.go index c1abc1c..e003782 100644 --- a/vela/admin.go +++ b/vela/admin.go @@ -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) @@ -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) diff --git a/vela/admin_test.go b/vela/admin_test.go index 43e7403..919834c 100644 --- a/vela/admin_test.go +++ b/vela/admin_test.go @@ -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"), @@ -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"), diff --git a/vela/deployment.go b/vela/deployment.go index da35287..7ce2de6 100644 --- a/vela/deployment.go +++ b/vela/deployment.go @@ -5,7 +5,7 @@ package vela import ( "fmt" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" ) // DeploymentService handles retrieving deployments from @@ -13,12 +13,12 @@ import ( 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) @@ -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) @@ -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) @@ -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) diff --git a/vela/deployment_test.go b/vela/deployment_test.go index a49d952..e47cabe 100644 --- a/vela/deployment_test.go +++ b/vela/deployment_test.go @@ -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) { @@ -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) @@ -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) } } @@ -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) @@ -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 @@ -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"), @@ -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"), diff --git a/vela/hook.go b/vela/hook.go index e7e7fa8..5cf1f1c 100644 --- a/vela/hook.go +++ b/vela/hook.go @@ -5,7 +5,7 @@ package vela import ( "fmt" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" ) // HookService handles retrieving hooks from @@ -13,12 +13,12 @@ import ( 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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/vela/hook_test.go b/vela/hook_test.go index cc18559..ab9726b 100644 --- a/vela/hook_test.go +++ b/vela/hook_test.go @@ -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) { @@ -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 @@ -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) @@ -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 @@ -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"), @@ -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"), @@ -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"), @@ -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"), @@ -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(""), } diff --git a/vela/pipeline.go b/vela/pipeline.go index 26089fb..32c6816 100644 --- a/vela/pipeline.go +++ b/vela/pipeline.go @@ -5,8 +5,8 @@ package vela import ( "fmt" - "github.com/go-vela/types/library" - "github.com/go-vela/types/yaml" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/compiler/types/yaml" ) // PipelineService handles retrieving pipelines from @@ -35,12 +35,12 @@ type PipelineOptions struct { } // Get returns the provided pipeline. -func (svc *PipelineService) Get(org, repo, ref string) (*library.Pipeline, *Response, error) { +func (svc *PipelineService) Get(org, repo, ref string) (*api.Pipeline, *Response, error) { // set the API endpoint path we send the request to u := fmt.Sprintf("/api/v1/pipelines/%s/%s/%s", org, repo, ref) // library Pipeline type we want to return - v := new(library.Pipeline) + v := new(api.Pipeline) // send request using client resp, err := svc.client.Call("GET", u, nil, v) @@ -49,7 +49,7 @@ func (svc *PipelineService) Get(org, repo, ref string) (*library.Pipeline, *Resp } // GetAll returns a list of all pipelines. -func (svc *PipelineService) GetAll(org, repo string, opt *ListOptions) (*[]library.Pipeline, *Response, error) { +func (svc *PipelineService) GetAll(org, repo string, opt *ListOptions) (*[]api.Pipeline, *Response, error) { // set the API endpoint path we send the request to u := fmt.Sprintf("/api/v1/pipelines/%s/%s", org, repo) @@ -60,7 +60,7 @@ func (svc *PipelineService) GetAll(org, repo string, opt *ListOptions) (*[]libra } // slice library Pipeline type we want to return - v := new([]library.Pipeline) + v := new([]api.Pipeline) // send request using client resp, err := svc.client.Call("GET", u, nil, v) @@ -69,12 +69,12 @@ func (svc *PipelineService) GetAll(org, repo string, opt *ListOptions) (*[]libra } // Add constructs a pipeline with the provided details. -func (svc *PipelineService) Add(org, repo string, h *library.Pipeline) (*library.Pipeline, *Response, error) { +func (svc *PipelineService) Add(org, repo string, h *api.Pipeline) (*api.Pipeline, *Response, error) { // set the API endpoint path we send the request to u := fmt.Sprintf("/api/v1/pipelines/%s/%s", org, repo) // library Pipeline type we want to return - v := new(library.Pipeline) + v := new(api.Pipeline) // send request using client resp, err := svc.client.Call("POST", u, h, v) @@ -83,12 +83,12 @@ func (svc *PipelineService) Add(org, repo string, h *library.Pipeline) (*library } // Update modifies a pipeline with the provided details. -func (svc *PipelineService) Update(org, repo string, p *library.Pipeline) (*library.Pipeline, *Response, error) { +func (svc *PipelineService) Update(org, repo string, p *api.Pipeline) (*api.Pipeline, *Response, error) { // set the API endpoint path we send the request to u := fmt.Sprintf("/api/v1/pipelines/%s/%s/%s", org, repo, p.GetCommit()) // library Pipeline type we want to return - v := new(library.Pipeline) + v := new(api.Pipeline) // send request using client resp, err := svc.client.Call("PUT", u, p, v) diff --git a/vela/pipeline_test.go b/vela/pipeline_test.go index fc2da43..d1067b6 100644 --- a/vela/pipeline_test.go +++ b/vela/pipeline_test.go @@ -13,9 +13,9 @@ import ( yml "github.com/buildkite/yaml" "github.com/gin-gonic/gin" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/compiler/types/yaml" "github.com/go-vela/server/mock/server" - "github.com/go-vela/types/library" - "github.com/go-vela/types/yaml" ) func TestPipeline_Get_200(t *testing.T) { @@ -27,7 +27,7 @@ func TestPipeline_Get_200(t *testing.T) { data := []byte(server.PipelineResp) - var want library.Pipeline + var want api.Pipeline _ = json.Unmarshal(data, &want) // run test @@ -53,7 +53,7 @@ func TestPipeline_Get_404(t *testing.T) { s := httptest.NewServer(server.FakeHandler()) c, _ := NewClient(s.URL, "", nil) - want := library.Pipeline{} + want := api.Pipeline{} // run test got, resp, err := c.Pipeline.Get("github", "octocat", "0") @@ -80,7 +80,7 @@ func TestPipeline_GetAll_200(t *testing.T) { data := []byte(server.PipelinesResp) - var want []library.Pipeline + var want []api.Pipeline _ = json.Unmarshal(data, &want) // run test @@ -108,10 +108,10 @@ func TestPipeline_Add_201(t *testing.T) { data := []byte(server.PipelineResp) - var want library.Pipeline + var want api.Pipeline _ = json.Unmarshal(data, &want) - req := library.Pipeline{ + req := api.Pipeline{ Commit: String("48afb5bdc41ad69bf22588491333f7cf71135163"), Ref: String("refs/heads/main"), Type: String("yaml"), @@ -144,10 +144,10 @@ func TestPipeline_Update_200(t *testing.T) { data := []byte(server.PipelineResp) - var want library.Pipeline + var want api.Pipeline _ = json.Unmarshal(data, &want) - req := library.Pipeline{ + req := api.Pipeline{ Commit: String("48afb5bdc41ad69bf22588491333f7cf71135163"), Type: String("yaml"), } @@ -175,9 +175,9 @@ func TestPipeline_Update_404(t *testing.T) { s := httptest.NewServer(server.FakeHandler()) c, _ := NewClient(s.URL, "", nil) - want := library.Pipeline{} + want := api.Pipeline{} - req := library.Pipeline{ + req := api.Pipeline{ Commit: String("0"), } @@ -471,7 +471,7 @@ func ExamplePipelineService_Add() { // Set new token in existing client c.Authentication.SetPersonalAccessTokenAuth("token") - req := library.Pipeline{ + req := api.Pipeline{ Commit: String("48afb5bdc41ad69bf22588491333f7cf71135163"), Ref: String("refs/heads/main"), Type: String("yaml"), @@ -495,7 +495,7 @@ func ExamplePipelineService_Update() { // Set new token in existing client c.Authentication.SetPersonalAccessTokenAuth("token") - req := library.Pipeline{ + req := api.Pipeline{ Commit: String("48afb5bdc41ad69bf22588491333f7cf71135163"), Type: String("yaml"), } From b837863b39cb42b5819a5f585d5c5a38451b15e7 Mon Sep 17 00:00:00 2001 From: ecrupper Date: Fri, 11 Oct 2024 13:56:15 -0500 Subject: [PATCH 2/2] tidy --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index ce9c673..3cd3c3d 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,6 @@ github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27 github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= 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/server v0.25.1 h1:KM3g5ZD3N6SnttnkfOyJjS2utbL6baKx0mGSJLCEf0c= -github.com/go-vela/server v0.25.1/go.mod h1:QZ9troVMUpDCAdUxxAquHqahkeSwp9Lmx6a47ao0gGs= 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=