2018-09-25 23:45:43 -04:00
# frozen_string_literal: true
2017-01-03 18:57:55 -05:00
module Projects
module Settings
2017-01-23 17:19:39 -05:00
class CiCdController < Projects :: ApplicationController
2017-01-03 18:57:55 -05:00
before_action :authorize_admin_pipeline!
2018-03-22 10:31:41 -04:00
before_action :define_variables
2017-01-06 10:23:32 -05:00
2017-01-03 18:57:55 -05:00
def show
2018-03-22 10:31:41 -04:00
end
def update
Projects :: UpdateService . new ( project , current_user , update_params ) . tap do | service |
result = service . execute
if result [ :status ] == :success
flash [ :notice ] = " Pipelines settings for ' #{ @project . name } ' were successfully updated. "
run_autodevops_pipeline ( service )
redirect_to project_settings_ci_cd_path ( @project )
else
render 'show'
end
end
2017-01-18 14:50:15 -05:00
end
2018-01-04 13:13:30 -05:00
def reset_cache
if ResetProjectCacheService . new ( @project , current_user ) . execute
2018-03-01 12:05:42 -05:00
respond_to do | format |
format . json { head :ok }
end
2018-01-04 13:13:30 -05:00
else
2018-03-01 12:05:42 -05:00
respond_to do | format |
format . json { head :bad_request }
end
2018-01-04 13:13:30 -05:00
end
end
2018-09-10 17:57:03 -04:00
def reset_registration_token
@project . reset_runners_token!
flash [ :notice ] = 'New runners registration token has been generated!'
redirect_to namespace_project_settings_ci_cd_path
end
2017-01-18 14:50:15 -05:00
private
2018-03-22 10:31:41 -04:00
def update_params
params . require ( :project ) . permit (
:runners_token , :builds_enabled , :build_allow_git_fetch ,
:build_timeout_human_readable , :build_coverage_regex , :public_builds ,
:auto_cancel_pending_pipelines , :ci_config_path ,
2018-06-06 06:07:32 -04:00
auto_devops_attributes : [ :id , :domain , :enabled , :deploy_strategy ]
2018-03-22 10:31:41 -04:00
)
end
def run_autodevops_pipeline ( service )
return unless service . run_auto_devops_pipeline?
if @project . empty_repo?
flash [ :warning ] = " This repository is currently empty. A new Auto DevOps pipeline will be created after a new file has been pushed to a branch. "
return
end
CreatePipelineWorker . perform_async ( project . id , current_user . id , project . default_branch , :web , ignore_skip_ci : true , save_on_errors : false )
flash [ :success ] = " A new Auto DevOps pipeline has been created, go to <a href= \" #{ project_pipelines_path ( @project ) } \" >Pipelines page</a> for details " . html_safe
end
def define_variables
define_runners_variables
2018-10-30 04:49:26 -04:00
define_ci_variables
2018-03-22 10:31:41 -04:00
define_triggers_variables
define_badges_variables
define_auto_devops_variables
end
2017-01-18 14:50:15 -05:00
def define_runners_variables
2017-01-03 18:57:55 -05:00
@project_runners = @project . runners . ordered
2017-10-04 07:59:51 -04:00
2017-12-19 10:40:19 -05:00
@assignable_runners = current_user
2018-05-10 08:42:55 -04:00
. ci_owned_runners
2017-12-19 10:40:19 -05:00
. assignable_for ( project )
. ordered
. page ( params [ :page ] ) . per ( 20 )
2018-06-26 05:36:54 -04:00
@shared_runners = :: Ci :: Runner . instance_type . active
2017-10-04 07:59:51 -04:00
2017-01-03 18:57:55 -05:00
@shared_runners_count = @shared_runners . count ( :all )
2017-10-04 07:59:51 -04:00
2018-04-26 21:15:54 -04:00
@group_runners = :: Ci :: Runner . belonging_to_parent_group_of_project ( @project . id )
2017-01-18 14:50:15 -05:00
end
2018-10-30 04:49:26 -04:00
def define_ci_variables
2018-03-13 16:57:42 -04:00
@variable = :: Ci :: Variable . new ( project : project )
2017-05-03 14:51:55 -04:00
. present ( current_user : current_user )
@variables = project . variables . order_key_asc
. map { | variable | variable . present ( current_user : current_user ) }
2017-01-23 17:19:39 -05:00
end
2017-01-18 14:50:15 -05:00
def define_triggers_variables
2017-01-03 18:57:55 -05:00
@triggers = @project . triggers
2018-12-19 09:51:02 -05:00
. present ( current_user : current_user )
2018-03-13 16:57:42 -04:00
@trigger = :: Ci :: Trigger . new
2018-12-19 09:51:02 -05:00
. present ( current_user : current_user )
2017-01-18 14:50:15 -05:00
end
def define_badges_variables
2017-01-03 18:57:55 -05:00
@ref = params [ :ref ] || @project . default_branch || 'master'
2017-07-19 07:08:47 -04:00
@badges = [ Gitlab :: Badge :: Pipeline :: Status ,
2017-01-03 18:57:55 -05:00
Gitlab :: Badge :: Coverage :: Report ]
@badges . map! do | badge |
badge . new ( @project , @ref ) . metadata
end
end
2017-08-30 14:39:23 -04:00
def define_auto_devops_variables
@auto_devops = @project . auto_devops || ProjectAutoDevops . new
end
2017-01-03 18:57:55 -05:00
end
end
end