2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-09-25 12:03:41 -04:00
|
|
|
class Projects::RunnersController < Projects::ApplicationController
|
2016-02-01 17:58:04 -05:00
|
|
|
before_action :authorize_admin_build!
|
2018-05-04 08:02:37 -04:00
|
|
|
before_action :runner, only: [:edit, :update, :destroy, :pause, :resume, :show]
|
2015-09-25 12:03:41 -04:00
|
|
|
|
|
|
|
layout 'project_settings'
|
|
|
|
|
2020-10-08 14:08:32 -04:00
|
|
|
feature_category :continuous_integration
|
|
|
|
|
2015-09-25 12:03:41 -04:00
|
|
|
def index
|
2018-08-07 17:12:18 -04:00
|
|
|
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-runners-settings')
|
2015-09-25 12:03:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2017-01-20 08:57:01 -05:00
|
|
|
if Ci::UpdateRunnerService.new(@runner).update(runner_params)
|
2019-03-27 12:52:52 -04:00
|
|
|
redirect_to project_runner_path(@project, @runner), notice: _('Runner was successfully updated.')
|
2015-09-25 12:03:41 -04:00
|
|
|
else
|
2016-05-05 08:27:06 -04:00
|
|
|
render 'edit'
|
2015-09-25 12:03:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2015-12-04 06:55:23 -05:00
|
|
|
if @runner.only_for?(project)
|
2015-09-25 12:03:41 -04:00
|
|
|
@runner.destroy
|
|
|
|
end
|
|
|
|
|
2018-07-02 06:43:06 -04:00
|
|
|
redirect_to project_runners_path(@project), status: :found
|
2015-09-25 12:03:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def resume
|
2017-01-20 08:57:01 -05:00
|
|
|
if Ci::UpdateRunnerService.new(@runner).update(active: true)
|
2019-03-27 12:52:52 -04:00
|
|
|
redirect_to project_runners_path(@project), notice: _('Runner was successfully updated.')
|
2015-09-25 12:03:41 -04:00
|
|
|
else
|
2019-03-27 12:52:52 -04:00
|
|
|
redirect_to project_runners_path(@project), alert: _('Runner was not updated.')
|
2015-09-25 12:03:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def pause
|
2017-01-20 08:57:01 -05:00
|
|
|
if Ci::UpdateRunnerService.new(@runner).update(active: false)
|
2019-03-27 12:52:52 -04:00
|
|
|
redirect_to project_runners_path(@project), notice: _('Runner was successfully updated.')
|
2015-09-25 12:03:41 -04:00
|
|
|
else
|
2019-03-27 12:52:52 -04:00
|
|
|
redirect_to project_runners_path(@project), alert: _('Runner was not updated.')
|
2015-09-25 12:03:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2018-05-04 07:59:19 -04:00
|
|
|
render 'shared/runners/show'
|
2015-09-25 12:03:41 -04:00
|
|
|
end
|
|
|
|
|
2015-12-04 06:55:23 -05:00
|
|
|
def toggle_shared_runners
|
2020-09-30 11:09:46 -04:00
|
|
|
if Feature.enabled?(:disable_shared_runners_on_group, default_enabled: true) && !project.shared_runners_enabled && project.group && project.group.shared_runners_setting == 'disabled_and_unoverridable'
|
|
|
|
return redirect_to project_runners_path(@project), alert: _("Cannot enable shared runners because parent group does not allow it")
|
|
|
|
end
|
|
|
|
|
2015-12-04 06:55:23 -05:00
|
|
|
project.toggle!(:shared_runners_enabled)
|
|
|
|
|
2018-08-07 17:12:18 -04:00
|
|
|
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-runners-settings')
|
2015-12-04 06:55:23 -05:00
|
|
|
end
|
|
|
|
|
2017-10-05 03:55:01 -04:00
|
|
|
def toggle_group_runners
|
2018-04-25 22:39:04 -04:00
|
|
|
project.toggle_ci_cd_settings!(:group_runners_enabled)
|
2017-10-05 03:55:01 -04:00
|
|
|
|
2018-08-07 17:12:18 -04:00
|
|
|
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-runners-settings')
|
2017-10-05 03:55:01 -04:00
|
|
|
end
|
|
|
|
|
2015-09-25 12:03:41 -04:00
|
|
|
protected
|
|
|
|
|
2018-05-04 08:02:37 -04:00
|
|
|
def runner
|
2015-12-10 11:44:06 -05:00
|
|
|
@runner ||= project.runners.find(params[:id])
|
2015-09-25 12:03:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def runner_params
|
2016-05-09 07:07:10 -04:00
|
|
|
params.require(:runner).permit(Ci::Runner::FORM_EDITABLE)
|
2015-09-25 12:03:41 -04:00
|
|
|
end
|
|
|
|
end
|