2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-12-04 06:55:23 -05:00
|
|
|
class Admin::RunnersController < Admin::ApplicationController
|
2020-09-30 17:10:09 -04:00
|
|
|
include RunnerSetupScripts
|
|
|
|
|
|
|
|
before_action :runner, except: [:index, :tag_list, :runner_setup_scripts]
|
2015-12-04 06:55:23 -05:00
|
|
|
|
2021-06-21 11:07:30 -04:00
|
|
|
feature_category :runner
|
2020-10-05 17:08:47 -04:00
|
|
|
|
2015-12-04 06:55:23 -05:00
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2016-05-19 15:27:52 -04:00
|
|
|
assign_builds_and_projects
|
2015-12-04 06:55:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2017-01-20 08:57:01 -05:00
|
|
|
if Ci::UpdateRunnerService.new(@runner).update(runner_params)
|
2016-05-19 15:27:52 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to admin_runner_path(@runner) }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
assign_builds_and_projects
|
|
|
|
render 'show'
|
2015-12-04 06:55:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@runner.destroy
|
|
|
|
|
2018-07-02 06:43:06 -04:00
|
|
|
redirect_to admin_runners_path, status: :found
|
2015-12-04 06:55:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def resume
|
2017-01-20 08:57:01 -05:00
|
|
|
if Ci::UpdateRunnerService.new(@runner).update(active: true)
|
2019-03-21 09:31:05 -04:00
|
|
|
redirect_to admin_runners_path, notice: _('Runner was successfully updated.')
|
2015-12-04 06:55:23 -05:00
|
|
|
else
|
2019-03-21 09:31:05 -04:00
|
|
|
redirect_to admin_runners_path, alert: _('Runner was not updated.')
|
2015-12-04 06:55:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def pause
|
2017-01-20 08:57:01 -05:00
|
|
|
if Ci::UpdateRunnerService.new(@runner).update(active: false)
|
2019-03-21 09:31:05 -04:00
|
|
|
redirect_to admin_runners_path, notice: _('Runner was successfully updated.')
|
2015-12-04 06:55:23 -05:00
|
|
|
else
|
2019-03-21 09:31:05 -04:00
|
|
|
redirect_to admin_runners_path, alert: _('Runner was not updated.')
|
2015-12-04 06:55:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-13 05:18:47 -04:00
|
|
|
def tag_list
|
2018-12-11 03:43:34 -05:00
|
|
|
tags = Autocomplete::ActsAsTaggableOn::TagsFinder.new(params: params).execute
|
2018-11-15 10:10:10 -05:00
|
|
|
|
|
|
|
render json: ActsAsTaggableOn::TagSerializer.new.represent(tags)
|
2018-06-13 05:18:47 -04:00
|
|
|
end
|
|
|
|
|
2020-09-30 17:10:09 -04:00
|
|
|
def runner_setup_scripts
|
|
|
|
private_runner_setup_scripts
|
|
|
|
end
|
|
|
|
|
2015-12-04 06:55:23 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def runner
|
|
|
|
@runner ||= Ci::Runner.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def runner_params
|
2020-04-21 11:21:10 -04: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 06:55:23 -05:00
|
|
|
end
|
2016-05-18 11:23:26 -04:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-05-19 15:27:52 -04:00
|
|
|
def assign_builds_and_projects
|
2020-01-24 07:09:01 -05:00
|
|
|
@builds = runner.builds.order('id DESC').preload_project_and_pipeline_project.first(30)
|
2016-05-18 11:23:26 -04:00
|
|
|
@projects =
|
|
|
|
if params[:search].present?
|
|
|
|
::Project.search(params[:search])
|
|
|
|
else
|
|
|
|
Project.all
|
|
|
|
end
|
2018-01-11 11:34:01 -05:00
|
|
|
|
2021-10-19 02:09:36 -04:00
|
|
|
::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/338659') do
|
|
|
|
@projects = @projects.where.not(id: runner.projects.select(:id)) if runner.projects.any?
|
2021-10-22 08:09:12 -04:00
|
|
|
@projects = @projects.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/338659')
|
2021-10-19 02:09:36 -04:00
|
|
|
@projects = @projects.inc_routes
|
|
|
|
@projects = @projects.page(params[:page]).per(30).without_count
|
|
|
|
end
|
2016-05-18 11:23:26 -04:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2015-12-04 06:55:23 -05:00
|
|
|
end
|