Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
fix(modification): send as yaml string since json fails (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanSussman authored Feb 1, 2021
1 parent cbc1a82 commit ae518cf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
17 changes: 12 additions & 5 deletions compiler/native/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ import (
"github.com/go-vela/types/yaml"
"github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/go-retryablehttp"

uyaml "github.com/goccy/go-yaml"
)

// ModifyRequest contains the payload passed to the modification endpoint
type ModifyRequest struct {
Pipeline *yaml.Build `json:"pipeline,omitempty"`
Build int `json:"build,omitempty"`
Repo string `json:"repo,omitempty"`
User string `json:"user,omitempty"`
Pipeline string `json:"pipeline,omitempty"`
Build int `json:"build,omitempty"`
Repo string `json:"repo,omitempty"`
User string `json:"user,omitempty"`
}

// Compile produces an executable pipeline from a yaml configuration.
Expand Down Expand Up @@ -210,8 +212,13 @@ func errorHandler(resp *http.Response, err error, attempts int) (*http.Response,
// nolint:lll // parameter struct references push line limit
func (c *client) modifyConfig(build *yaml.Build, libraryBuild *library.Build, repo *library.Repo) (*yaml.Build, error) {
// create request to send to endpoint
data, err := uyaml.Marshal(build)
if err != nil {
return nil, err
}

modReq := &ModifyRequest{
Pipeline: build,
Pipeline: string(data),
Build: libraryBuild.GetNumber(),
Repo: repo.GetName(),
User: libraryBuild.GetAuthor(),
Expand Down
14 changes: 12 additions & 2 deletions compiler/native/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,11 @@ func Test_client_modifyConfig(t *testing.T) {
Environment: nil,
Name: "docker",
Pull: "always",
Parameters: map[string]interface{}{
"init_options": map[string]interface{}{
"get_plugins": "true",
},
},
},
},
}
Expand Down Expand Up @@ -1430,6 +1435,11 @@ func Test_client_modifyConfig(t *testing.T) {
Environment: nil,
Name: "docker",
Pull: "always",
Parameters: map[string]interface{}{
"init_options": map[string]interface{}{
"get_plugins": "true",
},
},
},
&yaml.Step{
Image: "alpine",
Expand Down Expand Up @@ -1548,8 +1558,8 @@ func Test_client_modifyConfig(t *testing.T) {
return
}

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

0 comments on commit ae518cf

Please sign in to comment.