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