Skip to content

Commit

Permalink
Fix the case where the value of the passed in parameter is empty when…
Browse files Browse the repository at this point in the history
… running the Pipeline (#323)

* Include parameters which value is empty

Signed-off-by: John Niang <johnniang@fastmail.com>

* Add a unit test against empty value only
  • Loading branch information
JohnNiang committed Oct 21, 2021
1 parent 4271779 commit 9727751
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/kapis/devops/v1alpha3/pipelinerun/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (h *apiHandler) requestSyncPipelineRun(key client.ObjectKey) error {
return nil
}

func (h *apiHandler) createPipelineRuns(request *restful.Request, response *restful.Response) {
func (h *apiHandler) createPipelineRun(request *restful.Request, response *restful.Response) {
nsName := request.PathParameter("namespace")
pipName := request.PathParameter("pipeline")
branch := request.QueryParameter("branch")
Expand Down
2 changes: 1 addition & 1 deletion pkg/kapis/devops/v1alpha3/pipelinerun/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func RegisterRoutes(ws *restful.WebService, c client.Client) {
Returns(http.StatusOK, api.StatusOK, v1alpha3.PipelineRunList{}))

ws.Route(ws.POST("/namespaces/{namespace}/pipelines/{pipeline}/pipelineruns").
To(handler.createPipelineRuns).
To(handler.createPipelineRun).
Doc("Create a PipelineRun for the specified pipeline").
Param(ws.PathParameter("namespace", "Namespace of the pipeline")).
Param(ws.PathParameter("pipeline", "Name of the pipeline")).
Expand Down
2 changes: 1 addition & 1 deletion pkg/kapis/devops/v1alpha3/pipelinerun/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func convertParameters(payload *devops.RunPayload) []v1alpha3.Parameter {
}
var parameters []v1alpha3.Parameter
for _, parameter := range payload.Parameters {
if parameter.Name == "" || parameter.Value == "" {
if parameter.Name == "" {
continue
}
parameters = append(parameters, v1alpha3.Parameter{
Expand Down
14 changes: 14 additions & 0 deletions pkg/kapis/devops/v1alpha3/pipelinerun/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ func Test_convertParameters(t *testing.T) {
},
},
want: nil,
}, {
name: "Empty value only",
args: args{
payload: &devops.RunPayload{
Parameters: []devops.Parameter{{
Name: "fakeName",
Value: "",
}},
},
},
want: []v1alpha3.Parameter{{
Name: "fakeName",
Value: "",
}},
}, {
name: "Two parameters",
args: args{
Expand Down

0 comments on commit 9727751

Please sign in to comment.