Commit 268f52ef authored by Matthias Käppler's avatar Matthias Käppler

Merge branch 'pedropombeiro/321368/add-error-message' into 'master'

Add more user-friendly message in case of hitting against runner registration limit

See merge request gitlab-org/gitlab!61051
parents fb9302b4 29971d70
...@@ -17,7 +17,10 @@ class Projects::RunnerProjectsController < Projects::ApplicationController ...@@ -17,7 +17,10 @@ class Projects::RunnerProjectsController < Projects::ApplicationController
if @runner.assign_to(project, current_user) if @runner.assign_to(project, current_user)
redirect_to path redirect_to path
else else
redirect_to path, alert: 'Failed adding runner to project' assign_to_messages = @runner.errors.messages[:assign_to]
alert = assign_to_messages&.join(',') || 'Failed adding runner to project'
redirect_to path, alert: alert
end end
end end
......
...@@ -46,9 +46,9 @@ module Ci ...@@ -46,9 +46,9 @@ module Ci
MINUTES_COST_FACTOR_FIELDS = %i[public_projects_minutes_cost_factor private_projects_minutes_cost_factor].freeze MINUTES_COST_FACTOR_FIELDS = %i[public_projects_minutes_cost_factor private_projects_minutes_cost_factor].freeze
has_many :builds has_many :builds
has_many :runner_projects, inverse_of: :runner, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :runner_projects, inverse_of: :runner, autosave: true, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :projects, through: :runner_projects has_many :projects, through: :runner_projects
has_many :runner_namespaces, inverse_of: :runner has_many :runner_namespaces, inverse_of: :runner, autosave: true
has_many :groups, through: :runner_namespaces has_many :groups, through: :runner_namespaces
has_one :last_build, -> { order('id DESC') }, class_name: 'Ci::Build' has_one :last_build, -> { order('id DESC') }, class_name: 'Ci::Build'
......
...@@ -102,7 +102,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -102,7 +102,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
request request
expect(response).to have_gitlab_http_status(:bad_request) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to include('runner_projects' => ['is invalid']) expect(json_response['message']).to include('runner_projects.base' => ['Maximum number of ci registered project runners (1) exceeded'])
expect(project.runners.reload.size).to eq(1) expect(project.runners.reload.size).to eq(1)
end end
end end
...@@ -143,7 +143,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -143,7 +143,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
request request
expect(response).to have_gitlab_http_status(:bad_request) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to include('runner_namespaces' => ['is invalid']) expect(json_response['message']).to include('runner_namespaces.base' => ['Maximum number of ci registered group runners (1) exceeded'])
expect(group.runners.reload.size).to eq(1) expect(group.runners.reload.size).to eq(1)
end 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