Commit d614c431 authored by Shinya Maeda's avatar Shinya Maeda

Fix trigger_request.variables

parent cff104ec
......@@ -32,15 +32,13 @@ module API
render_api_error!(result[:message], result[:http_status])
else
pipeline = result[:pipeline]
trigger_request = pipeline.trigger_request
trigger_request = Ci::TriggerRequest.find_by(commit_id: pipeline.id)
# We switched to Ci::PipelineVariable from Ci::TriggerRequest.variables.
# Ci::TriggerRequest doesn't save variables anymore.
# Here is copying Ci::PipelineVariable to Ci::TriggerRequest.variables for presenting the variables.
# The same endpoint in v4 API pressents Pipeline instead of TriggerRequest, so it doesn't need such a process.
pipeline.variables.each do |variable|
trigger_request.variables << { key: variable.key, value: variable.value }
end
trigger_request.variables = params[:variables]
present trigger_request, with: ::API::V3::Entities::TriggerRequest
end
......
......@@ -5,13 +5,13 @@ describe Ci::TriggerRequest do
it 'be invalid if saving a variable' do
trigger = build(:ci_trigger_request, variables: { TRIGGER_KEY_1: 'TRIGGER_VALUE_1' } )
expect(trigger.valid?).to be_falsey
expect(trigger).not_to be_valid
end
it 'be valid if not saving a variable' do
trigger = build(:ci_trigger_request)
expect(trigger.valid?).to be_truthy
expect(trigger).to be_valid
end
end
end
......@@ -80,7 +80,8 @@ describe API::V3::Triggers do
post v3_api("/projects/#{project.id}/trigger/builds"), options.merge(variables: variables, ref: 'master')
expect(response).to have_http_status(201)
pipeline.builds.reload
expect(pipeline.builds.first.trigger_request.variables).to eq(variables)
expect(pipeline.variables.map { |v| { v.key => v.value } }.first).to eq(variables)
expect(json_response['variables']).to eq(variables)
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment