2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
class Projects::RunnersController < Projects::ApplicationController
|
2016-04-02 18:10:28 +05:30
|
|
|
before_action :authorize_admin_build!
|
2018-10-15 14:42:47 +05:30
|
|
|
before_action :runner, only: [:edit, :update, :destroy, :pause, :resume, :show]
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
feature_category :runner
|
2022-07-16 23:28:13 +05:30
|
|
|
urgency :low
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
def index
|
2018-11-18 11:00:15 +05:30
|
|
|
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-runners-settings')
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2022-10-11 01:57:18 +05:30
|
|
|
if Ci::Runners::UpdateRunnerService.new(@runner).execute(runner_params).success?
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to project_runner_path(@project, @runner), notice: _('Runner was successfully updated.')
|
2015-10-24 18:46:33 +05:30
|
|
|
else
|
2016-06-02 11:05:42 +05:30
|
|
|
render 'edit'
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2015-12-23 02:04:40 +05:30
|
|
|
if @runner.only_for?(project)
|
2022-05-07 20:08:51 +05:30
|
|
|
Ci::Runners::UnregisterRunnerService.new(@runner, current_user).execute
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
redirect_to project_runners_path(@project), status: :found
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def resume
|
2022-10-11 01:57:18 +05:30
|
|
|
if Ci::Runners::UpdateRunnerService.new(@runner).execute(active: true).success?
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to project_runners_path(@project), notice: _('Runner was successfully updated.')
|
2015-10-24 18:46:33 +05:30
|
|
|
else
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to project_runners_path(@project), alert: _('Runner was not updated.')
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def pause
|
2022-10-11 01:57:18 +05:30
|
|
|
if Ci::Runners::UpdateRunnerService.new(@runner).execute(active: false).success?
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to project_runners_path(@project), notice: _('Runner was successfully updated.')
|
2015-10-24 18:46:33 +05:30
|
|
|
else
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to project_runners_path(@project), alert: _('Runner was not updated.')
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
def toggle_shared_runners
|
2021-09-30 23:02:18 +05:30
|
|
|
update_params = { shared_runners_enabled: !project.shared_runners_enabled }
|
|
|
|
result = Projects::UpdateService.new(project, current_user, update_params).execute
|
2015-12-23 02:04:40 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
if result[:status] == :success
|
|
|
|
render json: {}, status: :ok
|
|
|
|
else
|
|
|
|
render json: { error: result[:message] }, status: :unauthorized
|
|
|
|
end
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
def toggle_group_runners
|
|
|
|
project.toggle_ci_cd_settings!(:group_runners_enabled)
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-runners-settings')
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
protected
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
def runner
|
2015-12-23 02:04:40 +05:30
|
|
|
@runner ||= project.runners.find(params[:id])
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def runner_params
|
2016-06-02 11:05:42 +05:30
|
|
|
params.require(:runner).permit(Ci::Runner::FORM_EDITABLE)
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
end
|