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
|
|
|
|
2021-06-21 15:07:30 +00:00
|
|
|
feature_category :runner
|
2020-10-08 18:08:32 +00:00
|
|
|
|
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
|
2022-02-24 09:14:06 +00:00
|
|
|
if Ci::Runners::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)
|
2022-02-24 09:14:06 +00:00
|
|
|
Ci::Runners::UnregisterRunnerService.new(@runner, current_user).execute
|
2015-09-25 16:03:41 +00:00
|
|
|
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
|
2022-02-24 09:14:06 +00:00
|
|
|
if Ci::Runners::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
|
2022-02-24 09:14:06 +00:00
|
|
|
if Ci::Runners::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
|
2021-06-18 15:10:16 +00:00
|
|
|
update_params = { shared_runners_enabled: !project.shared_runners_enabled }
|
|
|
|
result = Projects::UpdateService.new(project, current_user, update_params).execute
|
2015-12-04 11:55:23 +00:00
|
|
|
|
2021-06-18 15:10:16 +00:00
|
|
|
if result[:status] == :success
|
|
|
|
render json: {}, status: :ok
|
|
|
|
else
|
|
|
|
render json: { error: result[:message] }, status: :unauthorized
|
|
|
|
end
|
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
|