2018-09-14 05:42:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-12-04 11:55:23 +00:00
|
|
|
class Admin::RunnersController < Admin::ApplicationController
|
2020-09-30 21:10:09 +00:00
|
|
|
include RunnerSetupScripts
|
|
|
|
|
|
|
|
before_action :runner, except: [:index, :tag_list, :runner_setup_scripts]
|
2022-03-30 21:09:29 +00:00
|
|
|
before_action only: [:index] do
|
2022-05-06 15:09:03 +00:00
|
|
|
push_frontend_feature_flag(:admin_runners_bulk_delete)
|
2022-08-31 12:13:01 +00:00
|
|
|
push_frontend_feature_flag(:runner_list_stacked_layout_admin)
|
2022-03-30 21:09:29 +00:00
|
|
|
end
|
2015-12-04 11:55:23 +00:00
|
|
|
|
2021-06-21 15:07:30 +00:00
|
|
|
feature_category :runner
|
2022-04-25 15:08:44 +00:00
|
|
|
urgency :low
|
2020-10-05 21:08:47 +00:00
|
|
|
|
2015-12-04 11:55:23 +00:00
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2022-01-06 18:13:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2022-04-21 03:09:30 +00:00
|
|
|
assign_projects
|
2015-12-04 11:55:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2022-02-24 09:14:06 +00:00
|
|
|
if Ci::Runners::UpdateRunnerService.new(@runner).update(runner_params)
|
2016-05-19 19:27:52 +00:00
|
|
|
respond_to do |format|
|
2022-01-06 18:13:45 +00:00
|
|
|
format.html { redirect_to edit_admin_runner_path(@runner) }
|
2016-05-19 19:27:52 +00:00
|
|
|
end
|
|
|
|
else
|
2022-04-21 03:09:30 +00:00
|
|
|
assign_projects
|
2016-05-19 19:27:52 +00:00
|
|
|
render 'show'
|
2015-12-04 11:55:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2022-02-24 09:14:06 +00:00
|
|
|
Ci::Runners::UnregisterRunnerService.new(@runner, current_user).execute
|
2015-12-04 11:55:23 +00:00
|
|
|
|
2018-07-02 10:43:06 +00:00
|
|
|
redirect_to admin_runners_path, status: :found
|
2015-12-04 11:55:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def resume
|
2022-02-24 09:14:06 +00:00
|
|
|
if Ci::Runners::UpdateRunnerService.new(@runner).update(active: true)
|
2019-03-21 13:31:05 +00:00
|
|
|
redirect_to admin_runners_path, notice: _('Runner was successfully updated.')
|
2015-12-04 11:55:23 +00:00
|
|
|
else
|
2019-03-21 13:31:05 +00:00
|
|
|
redirect_to admin_runners_path, alert: _('Runner was not updated.')
|
2015-12-04 11:55:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def pause
|
2022-02-24 09:14:06 +00:00
|
|
|
if Ci::Runners::UpdateRunnerService.new(@runner).update(active: false)
|
2019-03-21 13:31:05 +00:00
|
|
|
redirect_to admin_runners_path, notice: _('Runner was successfully updated.')
|
2015-12-04 11:55:23 +00:00
|
|
|
else
|
2019-03-21 13:31:05 +00:00
|
|
|
redirect_to admin_runners_path, alert: _('Runner was not updated.')
|
2015-12-04 11:55:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-13 09:18:47 +00:00
|
|
|
def tag_list
|
2018-12-11 08:43:34 +00:00
|
|
|
tags = Autocomplete::ActsAsTaggableOn::TagsFinder.new(params: params).execute
|
2018-11-15 15:10:10 +00:00
|
|
|
|
|
|
|
render json: ActsAsTaggableOn::TagSerializer.new.represent(tags)
|
2018-06-13 09:18:47 +00:00
|
|
|
end
|
|
|
|
|
2020-09-30 21:10:09 +00:00
|
|
|
def runner_setup_scripts
|
|
|
|
private_runner_setup_scripts
|
|
|
|
end
|
|
|
|
|
2015-12-04 11:55:23 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def runner
|
|
|
|
@runner ||= Ci::Runner.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def runner_params
|
2020-04-21 15:21:10 +00:00
|
|
|
params.require(:runner).permit(permitted_attrs)
|
|
|
|
end
|
|
|
|
|
|
|
|
def permitted_attrs
|
|
|
|
if Gitlab.com?
|
|
|
|
Ci::Runner::FORM_EDITABLE + Ci::Runner::MINUTES_COST_FACTOR_FIELDS
|
|
|
|
else
|
|
|
|
Ci::Runner::FORM_EDITABLE
|
|
|
|
end
|
2015-12-04 11:55:23 +00:00
|
|
|
end
|
2016-05-18 15:23:26 +00:00
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2022-04-21 03:09:30 +00:00
|
|
|
def assign_projects
|
2016-05-18 15:23:26 +00:00
|
|
|
@projects =
|
|
|
|
if params[:search].present?
|
|
|
|
::Project.search(params[:search])
|
|
|
|
else
|
|
|
|
Project.all
|
|
|
|
end
|
2018-01-11 16:34:01 +00:00
|
|
|
|
2022-01-21 15:13:54 +00:00
|
|
|
runner_projects_ids = runner.runner_projects.pluck(:project_id)
|
|
|
|
@projects = @projects.where.not(id: runner_projects_ids) if runner_projects_ids.any?
|
|
|
|
@projects = @projects.inc_routes
|
|
|
|
@projects = @projects.page(params[:page]).per(30).without_count
|
2016-05-18 15:23:26 +00:00
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2015-12-04 11:55:23 +00:00
|
|
|
end
|
2022-06-03 15:09:26 +00:00
|
|
|
|
|
|
|
Admin::RunnersController.prepend_mod
|