diff options
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | app/presenters/ci/build_runner_presenter.rb | 2 | ||||
-rw-r--r-- | app/services/projects/fork_service.rb | 6 | ||||
-rw-r--r-- | changelogs/unreleased/expose-project-git-depth-via-api.yml | 5 | ||||
-rw-r--r-- | doc/api/projects.md | 8 | ||||
-rw-r--r-- | lib/api/entities.rb | 2 | ||||
-rw-r--r-- | lib/api/helpers/projects_helpers.rb | 1 | ||||
-rw-r--r-- | spec/controllers/projects/settings/ci_cd_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/presenters/ci/build_runner_presenter_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/runner_spec.rb | 6 | ||||
-rw-r--r-- | spec/services/projects/fork_service_spec.rb | 8 |
12 files changed, 32 insertions, 14 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index e64a4b313aa..9d17d68eee2 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -311,7 +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 + delegate :default_git_depth, :default_git_depth=, to: :ci_cd_settings, prefix: :ci # Validations validates :creator, presence: true, on: :create diff --git a/app/presenters/ci/build_runner_presenter.rb b/app/presenters/ci/build_runner_presenter.rb index c75f62149f8..b928988ed8c 100644 --- a/app/presenters/ci/build_runner_presenter.rb +++ b/app/presenters/ci/build_runner_presenter.rb @@ -28,7 +28,7 @@ module Ci if git_depth_variable git_depth_variable[:value] elsif Feature.enabled?(:ci_project_git_depth, default_enabled: true) - project.default_git_depth + project.ci_default_git_depth end.to_i end diff --git a/app/services/projects/fork_service.rb b/app/services/projects/fork_service.rb index 0b4ab7b8e4d..d8fa9d37359 100644 --- a/app/services/projects/fork_service.rb +++ b/app/services/projects/fork_service.rb @@ -43,10 +43,10 @@ module Projects shared_runners_enabled: @project.shared_runners_enabled, namespace_id: target_namespace.id, fork_network: fork_network, - # We need to set default_git_depth to 0 for the forked project when - # @project.default_git_depth is nil in order to keep the same behaviour + # We need to set ci_default_git_depth to 0 for the forked project when + # @project.ci_default_git_depth is nil in order to keep the same behaviour # and not get ProjectCiCdSetting::DEFAULT_GIT_DEPTH set on create - ci_cd_settings_attributes: { default_git_depth: @project.default_git_depth || 0 }, + ci_cd_settings_attributes: { default_git_depth: @project.ci_default_git_depth || 0 }, # 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 diff --git a/changelogs/unreleased/expose-project-git-depth-via-api.yml b/changelogs/unreleased/expose-project-git-depth-via-api.yml new file mode 100644 index 00000000000..e9d158fda16 --- /dev/null +++ b/changelogs/unreleased/expose-project-git-depth-via-api.yml @@ -0,0 +1,5 @@ +--- +title: Get and edit ci_default_git_depth via project API +merge_request: 29353 +author: +type: added diff --git a/doc/api/projects.md b/doc/api/projects.md index 75669d85803..1d58e390d9e 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -143,6 +143,7 @@ When the user is authenticated and `simple` is not set this returns something li "forks_count": 0, "star_count": 0, "runners_token": "b8547b1dc37721d05889db52fa2f02", + "ci_default_git_depth": 50, "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, @@ -225,6 +226,7 @@ When the user is authenticated and `simple` is not set this returns something li "forks_count": 0, "star_count": 0, "runners_token": "b8547b1dc37721d05889db52fa2f02", + "ci_default_git_depth": 0, "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, @@ -334,6 +336,7 @@ GET /users/:user_id/projects "forks_count": 0, "star_count": 0, "runners_token": "b8547b1dc37721d05889db52fa2f02", + "ci_default_git_depth": 50, "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, @@ -416,6 +419,7 @@ GET /users/:user_id/projects "forks_count": 0, "star_count": 0, "runners_token": "b8547b1dc37721d05889db52fa2f02", + "ci_default_git_depth": 0, "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, @@ -528,6 +532,7 @@ GET /projects/:id "forks_count": 0, "star_count": 0, "runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b", + "ci_default_git_depth": 50, "public_jobs": true, "shared_with_groups": [ { @@ -763,6 +768,7 @@ PUT /projects/:id | `tag_list` | array | no | The list of tags for a project; put array of tags, that should be finally assigned to a project | | `avatar` | mixed | no | Image file for avatar of the project | | `ci_config_path` | string | no | The path to CI config file | +| `ci_default_git_depth` | integer | no | Default number of revisions for [shallow cloning](../user/project/pipelines/settings.md#git-shallow-clone) | ## Fork project @@ -1160,6 +1166,7 @@ Example response: "forks_count": 0, "star_count": 0, "runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b", + "ci_default_git_depth": 50, "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, @@ -1264,6 +1271,7 @@ Example response: "forks_count": 0, "star_count": 0, "runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b", + "ci_default_git_depth": 50, "public_jobs": true, "shared_with_groups": [], "only_allow_merge_if_pipeline_succeeds": false, diff --git a/lib/api/entities.rb b/lib/api/entities.rb index f8b950cb55d..82aa8310a1c 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -265,6 +265,7 @@ module API expose :open_issues_count, if: lambda { |project, options| project.feature_available?(:issues, options[:current_user]) } expose :runners_token, if: lambda { |_project, options| options[:user_can_admin_project] } + expose :ci_default_git_depth expose :public_builds, as: :public_jobs expose :ci_config_path, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) } expose :shared_with_groups do |project, options| @@ -287,6 +288,7 @@ module API # N+1 is solved then by using `subject.tags.map(&:name)` # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20555 super(projects_relation).preload(:group) + .preload(:ci_cd_settings) .preload(project_group_links: { group: :route }, fork_network: :root_project, fork_network_member: :forked_from_project, diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb index 813e46e9520..f242f1fea0e 100644 --- a/lib/api/helpers/projects_helpers.rb +++ b/lib/api/helpers/projects_helpers.rb @@ -29,6 +29,7 @@ module API optional :merge_method, type: String, values: %w(ff rebase_merge merge), desc: 'The merge method used when merging merge requests' optional :initialize_with_readme, type: Boolean, desc: "Initialize a project with a README.md" optional :external_authorization_classification_label, type: String, desc: 'The classification label for the project' + optional :ci_default_git_depth, type: Integer, desc: 'Default number of revisions for shallow cloning' end params :optional_project_params_ee do diff --git a/spec/controllers/projects/settings/ci_cd_controller_spec.rb b/spec/controllers/projects/settings/ci_cd_controller_spec.rb index 117b9cf7915..5bfbcf6eeb5 100644 --- a/spec/controllers/projects/settings/ci_cd_controller_spec.rb +++ b/spec/controllers/projects/settings/ci_cd_controller_spec.rb @@ -212,7 +212,7 @@ describe Projects::Settings::CiCdController do subject project.reload - expect(project.default_git_depth).to eq(10) + expect(project.ci_default_git_depth).to eq(10) end end end diff --git a/spec/presenters/ci/build_runner_presenter_spec.rb b/spec/presenters/ci/build_runner_presenter_spec.rb index 620f34bac79..a4234d14255 100644 --- a/spec/presenters/ci/build_runner_presenter_spec.rb +++ b/spec/presenters/ci/build_runner_presenter_spec.rb @@ -134,7 +134,7 @@ describe Ci::BuildRunnerPresenter do end it 'defaults to git depth setting for the project' do - expect(git_depth).to eq(build.project.default_git_depth) + expect(git_depth).to eq(build.project.ci_default_git_depth) end context 'when feature flag :ci_project_git_depth is disabled' do diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 799e84e83c1..5f7d2fa6d9c 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -1125,6 +1125,7 @@ describe API::Projects do expect(json_response['shared_with_groups'][0]['expires_at']).to be_nil expect(json_response['only_allow_merge_if_pipeline_succeeds']).to eq(project.only_allow_merge_if_pipeline_succeeds) expect(json_response['only_allow_merge_if_all_discussions_are_resolved']).to eq(project.only_allow_merge_if_all_discussions_are_resolved) + expect(json_response['ci_default_git_depth']).to eq(project.ci_default_git_depth) expect(json_response['merge_method']).to eq(project.merge_method.to_s) expect(json_response['readme_url']).to eq(project.readme_url) end @@ -1963,6 +1964,7 @@ describe API::Projects do snippets_enabled: true, merge_requests_enabled: true, merge_method: 'ff', + ci_default_git_depth: 20, description: 'new description' } put api("/projects/#{project3.id}", user4), params: project_param diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb index 038c958b5cc..d9ef5edb848 100644 --- a/spec/requests/api/runner_spec.rb +++ b/spec/requests/api/runner_spec.rb @@ -445,7 +445,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do 'before_sha' => job.before_sha, 'ref_type' => 'branch', 'refspecs' => ["+refs/heads/#{job.ref}:refs/remotes/origin/#{job.ref}"], - 'depth' => project.default_git_depth } + 'depth' => project.ci_default_git_depth } end let(:expected_steps) do @@ -533,7 +533,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do context 'when GIT_DEPTH is not specified and there is no default git depth for the project' do before do - project.update!(default_git_depth: nil) + project.update!(ci_default_git_depth: nil) end it 'specifies refspecs' do @@ -593,7 +593,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do context 'when GIT_DEPTH is not specified and there is no default git depth for the project' do before do - project.update!(default_git_depth: nil) + project.update!(ci_default_git_depth: nil) end it 'specifies refspecs' do diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb index 3211a6e1310..6afc91d5e95 100644 --- a/spec/services/projects/fork_service_spec.rb +++ b/spec/services/projects/fork_service_spec.rb @@ -150,21 +150,21 @@ describe Projects::ForkService do context "when origin has git depth specified" do before do - @from_project.update(default_git_depth: 42) + @from_project.update(ci_default_git_depth: 42) end it "inherits default_git_depth from the origin project" do - expect(to_project.default_git_depth).to eq(42) + expect(to_project.ci_default_git_depth).to eq(42) end end context "when origin does not define git depth" do before do - @from_project.update!(default_git_depth: nil) + @from_project.update!(ci_default_git_depth: nil) end it "the fork has git depth set to 0" do - expect(to_project.default_git_depth).to eq(0) + expect(to_project.ci_default_git_depth).to eq(0) end end end |