gitlab-org--gitlab-foss/app/controllers/admin/runners_controller.rb

107 lines
2.8 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2015-12-04 06:55:23 -05:00
class Admin::RunnersController < Admin::ApplicationController
include RunnerSetupScripts
before_action :runner, except: [:index, :tag_list, :runner_setup_scripts]
2015-12-04 06:55:23 -05:00
feature_category :runner
2015-12-04 06:55:23 -05:00
def index
end
def show
# We will show runner details in a read-only view in
# future iterations. For now, this route will have a
# redirect until this new view is developed. See more:
# https://gitlab.com/gitlab-org/gitlab/-/issues/347856
redirect_to edit_admin_runner_path(runner) unless Feature.enabled?(:runner_read_only_admin_view, default_enabled: :yaml)
end
def edit
2016-05-19 15:27:52 -04:00
assign_builds_and_projects
2015-12-04 06:55:23 -05:00
end
def update
if Ci::Runners::UpdateRunnerService.new(@runner).update(runner_params)
2016-05-19 15:27:52 -04:00
respond_to do |format|
format.html { redirect_to edit_admin_runner_path(@runner) }
2016-05-19 15:27:52 -04:00
end
else
assign_builds_and_projects
render 'show'
2015-12-04 06:55:23 -05:00
end
end
def destroy
Ci::Runners::UnregisterRunnerService.new(@runner, current_user).execute
2015-12-04 06:55:23 -05:00
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
if Ci::Runners::UpdateRunnerService.new(@runner).update(active: true)
redirect_to admin_runners_path, notice: _('Runner was successfully updated.')
2015-12-04 06:55:23 -05:00
else
redirect_to admin_runners_path, alert: _('Runner was not updated.')
2015-12-04 06:55:23 -05:00
end
end
def pause
if Ci::Runners::UpdateRunnerService.new(@runner).update(active: false)
redirect_to admin_runners_path, notice: _('Runner was successfully updated.')
2015-12-04 06:55:23 -05:00
else
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
tags = Autocomplete::ActsAsTaggableOn::TagsFinder.new(params: params).execute
render json: ActsAsTaggableOn::TagSerializer.new.represent(tags)
2018-06-13 05:18:47 -04:00
end
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
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
# rubocop: disable CodeReuse/ActiveRecord
2016-05-19 15:27:52 -04:00
def assign_builds_and_projects
@builds = runner
.builds
.order_id_desc
.preload_project_and_pipeline_project.first(30)
@projects =
if params[:search].present?
::Project.search(params[:search])
else
Project.all
end
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
end
# rubocop: enable CodeReuse/ActiveRecord
2015-12-04 06:55:23 -05:00
end