summaryrefslogtreecommitdiff
path: root/app/models/project_ci_cd_setting.rb
diff options
context:
space:
mode:
authorKrasimir Angelov <kangelov@gitlab.com>2019-05-30 18:40:53 +1200
committerFabio Pitino <fpitino@gitlab.com>2019-06-06 09:21:18 +0100
commitad9ae16d8a44dd2523bd6e6109db9fe2da45d3a5 (patch)
treeee8445389c89b4c7f5cc71c3d35f469345a5016f /app/models/project_ci_cd_setting.rb
parent3fd99b4e7a58843943ade87a3658d477278aa412 (diff)
downloadgitlab-ce-ad9ae16d8a44dd2523bd6e6109db9fe2da45d3a5.tar.gz
Add project level git depth setting
Introduce default_git_depth in project's CI/CD settings and set it to 50. Use it if there is no GIT_DEPTH variable specified. Apply this default only to newly created projects and keep it nil for old ones in order to not break pipelines that rely on non-shallow clones. default_git_depth can be updated from CI/CD Settings in the UI, must be either nil or integer between 0 and 1000 (incl). Inherit default_git_depth from the origin project when forking projects. MR pipelines are run on a MR ref (refs/merge-requests/:iid/merge) and it contains unique commit (i.e. merge commit) which doesn't exist in the other branch/tags refs. We need to add it cause otherwise it may break pipelines for old projects that have already enabled Pipelines for merge results and have git depth 0. Document new default_git_depth project CI/CD setting
Diffstat (limited to 'app/models/project_ci_cd_setting.rb')
-rw-r--r--app/models/project_ci_cd_setting.rb18
1 files changed, 18 insertions, 0 deletions
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