Commit 99197664 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'expose-project-git-depth-via-api' into 'master'

Expose default_git_depth via project API

Closes #62908

See merge request gitlab-org/gitlab-ce!29353
parents 06e89d78 3ac527b4
...@@ -311,7 +311,7 @@ class Project < ApplicationRecord ...@@ -311,7 +311,7 @@ class Project < ApplicationRecord
delegate :root_ancestor, to: :namespace, allow_nil: true delegate :root_ancestor, to: :namespace, allow_nil: true
delegate :last_pipeline, to: :commit, allow_nil: true delegate :last_pipeline, to: :commit, allow_nil: true
delegate :external_dashboard_url, to: :metrics_setting, allow_nil: true, prefix: 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 # Validations
validates :creator, presence: true, on: :create validates :creator, presence: true, on: :create
......
...@@ -28,7 +28,7 @@ module Ci ...@@ -28,7 +28,7 @@ module Ci
if git_depth_variable if git_depth_variable
git_depth_variable[:value] git_depth_variable[:value]
elsif Feature.enabled?(:ci_project_git_depth, default_enabled: true) elsif Feature.enabled?(:ci_project_git_depth, default_enabled: true)
project.default_git_depth project.ci_default_git_depth
end.to_i end.to_i
end end
......
...@@ -43,10 +43,10 @@ module Projects ...@@ -43,10 +43,10 @@ module Projects
shared_runners_enabled: @project.shared_runners_enabled, shared_runners_enabled: @project.shared_runners_enabled,
namespace_id: target_namespace.id, namespace_id: target_namespace.id,
fork_network: fork_network, fork_network: fork_network,
# We need to set default_git_depth to 0 for the forked project when # We need to set ci_default_git_depth to 0 for the forked project when
# @project.default_git_depth is nil in order to keep the same behaviour # @project.ci_default_git_depth is nil in order to keep the same behaviour
# and not get ProjectCiCdSetting::DEFAULT_GIT_DEPTH set on create # 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 # We need to assign the fork network membership after the project has
# been instantiated to avoid ActiveRecord trying to create it when # been instantiated to avoid ActiveRecord trying to create it when
# initializing the project, as that would cause a foreign key constraint # initializing the project, as that would cause a foreign key constraint
......
---
title: Get and edit ci_default_git_depth via project API
merge_request: 29353
author:
type: added
...@@ -143,6 +143,7 @@ When the user is authenticated and `simple` is not set this returns something li ...@@ -143,6 +143,7 @@ When the user is authenticated and `simple` is not set this returns something li
"forks_count": 0, "forks_count": 0,
"star_count": 0, "star_count": 0,
"runners_token": "b8547b1dc37721d05889db52fa2f02", "runners_token": "b8547b1dc37721d05889db52fa2f02",
"ci_default_git_depth": 50,
"public_jobs": true, "public_jobs": true,
"shared_with_groups": [], "shared_with_groups": [],
"only_allow_merge_if_pipeline_succeeds": false, "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 ...@@ -225,6 +226,7 @@ When the user is authenticated and `simple` is not set this returns something li
"forks_count": 0, "forks_count": 0,
"star_count": 0, "star_count": 0,
"runners_token": "b8547b1dc37721d05889db52fa2f02", "runners_token": "b8547b1dc37721d05889db52fa2f02",
"ci_default_git_depth": 0,
"public_jobs": true, "public_jobs": true,
"shared_with_groups": [], "shared_with_groups": [],
"only_allow_merge_if_pipeline_succeeds": false, "only_allow_merge_if_pipeline_succeeds": false,
...@@ -334,6 +336,7 @@ GET /users/:user_id/projects ...@@ -334,6 +336,7 @@ GET /users/:user_id/projects
"forks_count": 0, "forks_count": 0,
"star_count": 0, "star_count": 0,
"runners_token": "b8547b1dc37721d05889db52fa2f02", "runners_token": "b8547b1dc37721d05889db52fa2f02",
"ci_default_git_depth": 50,
"public_jobs": true, "public_jobs": true,
"shared_with_groups": [], "shared_with_groups": [],
"only_allow_merge_if_pipeline_succeeds": false, "only_allow_merge_if_pipeline_succeeds": false,
...@@ -416,6 +419,7 @@ GET /users/:user_id/projects ...@@ -416,6 +419,7 @@ GET /users/:user_id/projects
"forks_count": 0, "forks_count": 0,
"star_count": 0, "star_count": 0,
"runners_token": "b8547b1dc37721d05889db52fa2f02", "runners_token": "b8547b1dc37721d05889db52fa2f02",
"ci_default_git_depth": 0,
"public_jobs": true, "public_jobs": true,
"shared_with_groups": [], "shared_with_groups": [],
"only_allow_merge_if_pipeline_succeeds": false, "only_allow_merge_if_pipeline_succeeds": false,
...@@ -528,6 +532,7 @@ GET /projects/:id ...@@ -528,6 +532,7 @@ GET /projects/:id
"forks_count": 0, "forks_count": 0,
"star_count": 0, "star_count": 0,
"runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b", "runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b",
"ci_default_git_depth": 50,
"public_jobs": true, "public_jobs": true,
"shared_with_groups": [ "shared_with_groups": [
{ {
...@@ -763,6 +768,7 @@ PUT /projects/:id ...@@ -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 | | `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 | | `avatar` | mixed | no | Image file for avatar of the project |
| `ci_config_path` | string | no | The path to CI config file | | `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 ## Fork project
...@@ -1160,6 +1166,7 @@ Example response: ...@@ -1160,6 +1166,7 @@ Example response:
"forks_count": 0, "forks_count": 0,
"star_count": 0, "star_count": 0,
"runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b", "runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b",
"ci_default_git_depth": 50,
"public_jobs": true, "public_jobs": true,
"shared_with_groups": [], "shared_with_groups": [],
"only_allow_merge_if_pipeline_succeeds": false, "only_allow_merge_if_pipeline_succeeds": false,
...@@ -1264,6 +1271,7 @@ Example response: ...@@ -1264,6 +1271,7 @@ Example response:
"forks_count": 0, "forks_count": 0,
"star_count": 0, "star_count": 0,
"runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b", "runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b",
"ci_default_git_depth": 50,
"public_jobs": true, "public_jobs": true,
"shared_with_groups": [], "shared_with_groups": [],
"only_allow_merge_if_pipeline_succeeds": false, "only_allow_merge_if_pipeline_succeeds": false,
......
...@@ -265,6 +265,7 @@ module API ...@@ -265,6 +265,7 @@ module API
expose :open_issues_count, if: lambda { |project, options| project.feature_available?(:issues, options[:current_user]) } 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 :runners_token, if: lambda { |_project, options| options[:user_can_admin_project] }
expose :ci_default_git_depth
expose :public_builds, as: :public_jobs expose :public_builds, as: :public_jobs
expose :ci_config_path, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) } expose :ci_config_path, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) }
expose :shared_with_groups do |project, options| expose :shared_with_groups do |project, options|
...@@ -287,6 +288,7 @@ module API ...@@ -287,6 +288,7 @@ module API
# N+1 is solved then by using `subject.tags.map(&:name)` # 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 # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20555
super(projects_relation).preload(:group) super(projects_relation).preload(:group)
.preload(:ci_cd_settings)
.preload(project_group_links: { group: :route }, .preload(project_group_links: { group: :route },
fork_network: :root_project, fork_network: :root_project,
fork_network_member: :forked_from_project, fork_network_member: :forked_from_project,
......
...@@ -29,6 +29,7 @@ module API ...@@ -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 :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 :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 :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 end
params :optional_project_params_ee do params :optional_project_params_ee do
......
...@@ -212,7 +212,7 @@ describe Projects::Settings::CiCdController do ...@@ -212,7 +212,7 @@ describe Projects::Settings::CiCdController do
subject subject
project.reload project.reload
expect(project.default_git_depth).to eq(10) expect(project.ci_default_git_depth).to eq(10)
end end
end end
end end
......
...@@ -134,7 +134,7 @@ describe Ci::BuildRunnerPresenter do ...@@ -134,7 +134,7 @@ describe Ci::BuildRunnerPresenter do
end end
it 'defaults to git depth setting for the project' do 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 end
context 'when feature flag :ci_project_git_depth is disabled' do context 'when feature flag :ci_project_git_depth is disabled' do
......
...@@ -1125,6 +1125,7 @@ describe API::Projects do ...@@ -1125,6 +1125,7 @@ describe API::Projects do
expect(json_response['shared_with_groups'][0]['expires_at']).to be_nil 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_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['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['merge_method']).to eq(project.merge_method.to_s)
expect(json_response['readme_url']).to eq(project.readme_url) expect(json_response['readme_url']).to eq(project.readme_url)
end end
...@@ -1963,6 +1964,7 @@ describe API::Projects do ...@@ -1963,6 +1964,7 @@ describe API::Projects do
snippets_enabled: true, snippets_enabled: true,
merge_requests_enabled: true, merge_requests_enabled: true,
merge_method: 'ff', merge_method: 'ff',
ci_default_git_depth: 20,
description: 'new description' } description: 'new description' }
put api("/projects/#{project3.id}", user4), params: project_param put api("/projects/#{project3.id}", user4), params: project_param
......
...@@ -445,7 +445,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do ...@@ -445,7 +445,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
'before_sha' => job.before_sha, 'before_sha' => job.before_sha,
'ref_type' => 'branch', 'ref_type' => 'branch',
'refspecs' => ["+refs/heads/#{job.ref}:refs/remotes/origin/#{job.ref}"], 'refspecs' => ["+refs/heads/#{job.ref}:refs/remotes/origin/#{job.ref}"],
'depth' => project.default_git_depth } 'depth' => project.ci_default_git_depth }
end end
let(:expected_steps) do let(:expected_steps) do
...@@ -533,7 +533,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state 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 context 'when GIT_DEPTH is not specified and there is no default git depth for the project' do
before do before do
project.update!(default_git_depth: nil) project.update!(ci_default_git_depth: nil)
end end
it 'specifies refspecs' do it 'specifies refspecs' do
...@@ -593,7 +593,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state 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 context 'when GIT_DEPTH is not specified and there is no default git depth for the project' do
before do before do
project.update!(default_git_depth: nil) project.update!(ci_default_git_depth: nil)
end end
it 'specifies refspecs' do it 'specifies refspecs' do
......
...@@ -150,21 +150,21 @@ describe Projects::ForkService do ...@@ -150,21 +150,21 @@ describe Projects::ForkService do
context "when origin has git depth specified" do context "when origin has git depth specified" do
before do before do
@from_project.update(default_git_depth: 42) @from_project.update(ci_default_git_depth: 42)
end end
it "inherits default_git_depth from the origin project" do 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
end end
context "when origin does not define git depth" do context "when origin does not define git depth" do
before do before do
@from_project.update!(default_git_depth: nil) @from_project.update!(ci_default_git_depth: nil)
end end
it "the fork has git depth set to 0" do 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 end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment