diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/settings/ci_cd_controller.rb | 3 | ||||
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | app/models/project_ci_cd_setting.rb | 18 | ||||
-rw-r--r-- | app/presenters/ci/build_runner_presenter.rb | 18 | ||||
-rw-r--r-- | app/services/projects/fork_service.rb | 22 | ||||
-rw-r--r-- | app/views/projects/settings/ci_cd/_form.html.haml | 8 |
6 files changed, 55 insertions, 16 deletions
diff --git a/app/controllers/projects/settings/ci_cd_controller.rb b/app/controllers/projects/settings/ci_cd_controller.rb index c4dff95a4b9..1b8d479209b 100644 --- a/app/controllers/projects/settings/ci_cd_controller.rb +++ b/app/controllers/projects/settings/ci_cd_controller.rb @@ -50,7 +50,8 @@ module Projects :runners_token, :builds_enabled, :build_allow_git_fetch, :build_timeout_human_readable, :build_coverage_regex, :public_builds, :auto_cancel_pending_pipelines, :ci_config_path, - auto_devops_attributes: [:id, :domain, :enabled, :deploy_strategy] + auto_devops_attributes: [:id, :domain, :enabled, :deploy_strategy], + ci_cd_settings_attributes: [:default_git_depth] ) end diff --git a/app/models/project.rb b/app/models/project.rb index 78d54571d94..e64a4b313aa 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -292,6 +292,7 @@ class Project < ApplicationRecord accepts_nested_attributes_for :project_feature, update_only: true accepts_nested_attributes_for :import_data accepts_nested_attributes_for :auto_devops, update_only: true + accepts_nested_attributes_for :ci_cd_settings, update_only: true accepts_nested_attributes_for :remote_mirrors, allow_destroy: true, @@ -310,6 +311,7 @@ class Project < ApplicationRecord delegate :root_ancestor, to: :namespace, allow_nil: true delegate :last_pipeline, to: :commit, allow_nil: true delegate :external_dashboard_url, to: :metrics_setting, allow_nil: true, prefix: true + delegate :default_git_depth, :default_git_depth=, to: :ci_cd_settings # Validations validates :creator, presence: true, on: :create diff --git a/app/models/project_ci_cd_setting.rb b/app/models/project_ci_cd_setting.rb index 1414164b703..cf1f80fd1ef 100644 --- a/app/models/project_ci_cd_setting.rb +++ b/app/models/project_ci_cd_setting.rb @@ -6,6 +6,18 @@ class ProjectCiCdSetting < ApplicationRecord # The version of the schema that first introduced this model/table. MINIMUM_SCHEMA_VERSION = 20180403035759 + DEFAULT_GIT_DEPTH = 50 + + before_create :set_default_git_depth, unless: :default_git_depth? + + validates :default_git_depth, + numericality: { + only_integer: true, + greater_than_or_equal_to: 0, + less_than_or_equal_to: 1000 + }, + allow_nil: true + def self.available? @available ||= ActiveRecord::Migrator.current_version >= MINIMUM_SCHEMA_VERSION @@ -15,4 +27,10 @@ class ProjectCiCdSetting < ApplicationRecord @available = nil super end + + private + + def set_default_git_depth + self.default_git_depth = DEFAULT_GIT_DEPTH + end end diff --git a/app/presenters/ci/build_runner_presenter.rb b/app/presenters/ci/build_runner_presenter.rb index 6d46e0bf18a..471b6d3b726 100644 --- a/app/presenters/ci/build_runner_presenter.rb +++ b/app/presenters/ci/build_runner_presenter.rb @@ -25,14 +25,16 @@ module Ci end def git_depth - strong_memoize(:git_depth) do - git_depth = variables&.find { |variable| variable[:key] == 'GIT_DEPTH' }&.dig(:value) - git_depth.to_i - end + if git_depth_variable + git_depth_variable[:value] + else + project.default_git_depth + end.to_i end def refspecs specs = [] + specs << refspec_for_merge_request_ref if merge_request_ref? if git_depth > 0 specs << refspec_for_branch(ref) if branch? || legacy_detached_merge_request_pipeline? @@ -42,8 +44,6 @@ module Ci specs << refspec_for_tag end - specs << refspec_for_merge_request_ref if merge_request_ref? - specs end @@ -89,5 +89,11 @@ module Ci def refspec_for_merge_request_ref "+#{ref}:#{ref}" end + + def git_depth_variable + strong_memoize(:git_depth_variable) do + variables&.find { |variable| variable[:key] == 'GIT_DEPTH' } + end + end end end diff --git a/app/services/projects/fork_service.rb b/app/services/projects/fork_service.rb index fc234bafc57..14c1c98ea73 100644 --- a/app/services/projects/fork_service.rb +++ b/app/services/projects/fork_service.rb @@ -36,18 +36,19 @@ module Projects def fork_new_project new_params = { - visibility_level: allowed_visibility_level, - description: @project.description, - name: target_name, - path: target_path, - shared_runners_enabled: @project.shared_runners_enabled, - namespace_id: target_namespace.id, - fork_network: fork_network, + visibility_level: allowed_visibility_level, + description: @project.description, + name: target_name, + path: target_path, + shared_runners_enabled: @project.shared_runners_enabled, + namespace_id: target_namespace.id, + fork_network: fork_network, + ci_cd_settings_attributes: { default_git_depth: @project.default_git_depth }, # We need to assign the fork network membership after the project has # been instantiated to avoid ActiveRecord trying to create it when # initializing the project, as that would cause a foreign key constraint # exception. - relations_block: -> (project) { build_fork_network_member(project) } + relations_block: -> (project) { build_fork_network_member(project) } } if @project.avatar.present? && @project.avatar.image? @@ -56,7 +57,10 @@ module Projects new_params.merge!(@project.object_pool_params) - new_project = CreateService.new(current_user, new_params).execute + new_project = CreateService.new(current_user, new_params).execute do |p| + p.build_ci_cd_settings(default_git_depth: @project.default_git_depth) + end + return new_project unless new_project.persisted? # Set the forked_from_project relation after saving to avoid having to diff --git a/app/views/projects/settings/ci_cd/_form.html.haml b/app/views/projects/settings/ci_cd/_form.html.haml index b38b8e3f686..2d108a1cba5 100644 --- a/app/views/projects/settings/ci_cd/_form.html.haml +++ b/app/views/projects/settings/ci_cd/_form.html.haml @@ -26,6 +26,14 @@ %hr .form-group + = f.fields_for :ci_cd_settings_attributes, @project.ci_cd_settings do |form| + = form.label :default_git_depth, _('Git shallow clone'), class: 'label-bold' + = form.number_field :default_git_depth, { class: 'form-control', min: 0, max: 1000 } + %p.form-text.text-muted + = _('The number of changes to be fetched from GitLab when cloning a repository. This can speed up Pipelines execution. Keep empty or set to 0 to disable shallow clone by default and make GitLab CI fetch all branches and tags each time.') + + %hr + .form-group = f.label :build_timeout_human_readable, _('Timeout'), class: 'label-bold' = f.text_field :build_timeout_human_readable, class: 'form-control' %p.form-text.text-muted |