diff --git a/lib/ci/api/runners.rb b/lib/ci/api/runners.rb index c10858f4c5e7f242b4c80952af2e0fe2fe7941b5..bcc82969eb3f0e0f97eca45335d9f17a4d741dcd 100644 --- a/lib/ci/api/runners.rb +++ b/lib/ci/api/runners.rb @@ -28,27 +28,23 @@ module Ci post "register" do required_attributes! [:token] - project = nil + attributes = attributes_for_keys( + [:description, :tag_list, :run_untagged, :locked] + ) + runner = if runner_registration_token_valid? # Create shared runner. Requires admin access - Ci::Runner.new(is_shared: true) + Ci::Runner.create(attributes.merge(is_shared: true)) elsif project = Project.find_by(runners_token: params[:token]) - Ci::Runner.new + # Create a specific runner for project. + project.runners.create(attributes) end return forbidden! unless runner - attributes = attributes_for_keys( - [:description, :tag_list, :run_untagged, :locked] - ).merge(get_runner_version_from_params || {}) - - Ci::UpdateRunnerService.new(runner).update(attributes) - - # Assign the specific runner for the project - project.runners << runner if project - if runner.id + runner.update(get_runner_version_from_params) present runner, with: Entities::Runner else not_found!