Commit 1b7d6dd2 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'rs-keep-divergent-refs-api' into 'master'

Modify keep_divergent_refs via RemoteMirror API

See merge request gitlab-org/gitlab!26407
parents 9fe7b97d 70d25552
...@@ -12,6 +12,9 @@ module API ...@@ -12,6 +12,9 @@ module API
expose :last_successful_update_at expose :last_successful_update_at
expose :last_error expose :last_error
expose :only_protected_branches expose :only_protected_branches
expose :keep_divergent_refs, if: -> (mirror, _options) do
::Feature.enabled?(:keep_divergent_refs, mirror.project)
end
end end
end end
end end
...@@ -33,9 +33,11 @@ module API ...@@ -33,9 +33,11 @@ module API
requires :url, type: String, desc: 'The URL for a remote mirror' requires :url, type: String, desc: 'The URL for a remote mirror'
optional :enabled, type: Boolean, desc: 'Determines if the mirror is enabled' optional :enabled, type: Boolean, desc: 'Determines if the mirror is enabled'
optional :only_protected_branches, type: Boolean, desc: 'Determines if only protected branches are mirrored' optional :only_protected_branches, type: Boolean, desc: 'Determines if only protected branches are mirrored'
optional :keep_divergent_refs, type: Boolean, desc: 'Determines if divergent refs are kept on the target'
end end
post ':id/remote_mirrors' do post ':id/remote_mirrors' do
create_params = declared_params(include_missing: false) create_params = declared_params(include_missing: false)
create_params.delete(:keep_divergent_refs) unless ::Feature.enabled?(:keep_divergent_refs, user_project)
new_mirror = user_project.remote_mirrors.create(create_params) new_mirror = user_project.remote_mirrors.create(create_params)
...@@ -53,12 +55,15 @@ module API ...@@ -53,12 +55,15 @@ module API
requires :mirror_id, type: String, desc: 'The ID of a remote mirror' requires :mirror_id, type: String, desc: 'The ID of a remote mirror'
optional :enabled, type: Boolean, desc: 'Determines if the mirror is enabled' optional :enabled, type: Boolean, desc: 'Determines if the mirror is enabled'
optional :only_protected_branches, type: Boolean, desc: 'Determines if only protected branches are mirrored' optional :only_protected_branches, type: Boolean, desc: 'Determines if only protected branches are mirrored'
optional :keep_divergent_refs, type: Boolean, desc: 'Determines if divergent refs are kept on the target'
end end
put ':id/remote_mirrors/:mirror_id' do put ':id/remote_mirrors/:mirror_id' do
mirror = user_project.remote_mirrors.find(params[:mirror_id]) mirror = user_project.remote_mirrors.find(params[:mirror_id])
mirror_params = declared_params(include_missing: false) mirror_params = declared_params(include_missing: false)
mirror_params[:id] = mirror_params.delete(:mirror_id) mirror_params[:id] = mirror_params.delete(:mirror_id)
mirror_params.delete(:keep_divergent_refs) unless ::Feature.enabled?(:keep_divergent_refs, user_project)
update_params = { remote_mirrors_attributes: mirror_params } update_params = { remote_mirrors_attributes: mirror_params }
result = ::Projects::UpdateService result = ::Projects::UpdateService
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
"last_successful_update_at", "last_successful_update_at",
"last_error", "last_error",
"only_protected_branches" "only_protected_branches"
], ],
"properties": { "properties": {
"id": { "type": "integer" }, "id": { "type": "integer" },
"enabled": { "type": "boolean" }, "enabled": { "type": "boolean" },
...@@ -20,7 +20,8 @@ ...@@ -20,7 +20,8 @@
"last_update_started_at": { "type": ["string", "null"] }, "last_update_started_at": { "type": ["string", "null"] },
"last_successful_update_at": { "type": ["string", "null"] }, "last_successful_update_at": { "type": ["string", "null"] },
"last_error": { "type": ["string", "null"] }, "last_error": { "type": ["string", "null"] },
"only_protected_branches": { "type": "boolean" } "only_protected_branches": { "type": "boolean" },
"keep_divergent_refs": { "type": ["boolean", "null"] }
}, },
"additionalProperties": false "additionalProperties": false
} }
...@@ -91,6 +91,10 @@ describe API::RemoteMirrors do ...@@ -91,6 +91,10 @@ describe API::RemoteMirrors do
let(:route) { ->(id) { "/projects/#{project.id}/remote_mirrors/#{id}" } } let(:route) { ->(id) { "/projects/#{project.id}/remote_mirrors/#{id}" } }
let(:mirror) { project.remote_mirrors.first } let(:mirror) { project.remote_mirrors.first }
before do
stub_feature_flags(keep_divergent_refs: false)
end
it 'requires `admin_remote_mirror` permission' do it 'requires `admin_remote_mirror` permission' do
put api(route[mirror.id], developer) put api(route[mirror.id], developer)
...@@ -102,12 +106,31 @@ describe API::RemoteMirrors do ...@@ -102,12 +106,31 @@ describe API::RemoteMirrors do
put api(route[mirror.id], user), params: { put api(route[mirror.id], user), params: {
enabled: '0', enabled: '0',
only_protected_branches: 'true' only_protected_branches: 'true',
keep_divergent_refs: 'true'
} }
expect(response).to have_gitlab_http_status(:success) expect(response).to have_gitlab_http_status(:success)
expect(json_response['enabled']).to eq(false) expect(json_response['enabled']).to eq(false)
expect(json_response['only_protected_branches']).to eq(true) expect(json_response['only_protected_branches']).to eq(true)
# Deleted due to lack of feature availability
expect(json_response['keep_divergent_refs']).to be_nil
end
context 'with the `keep_divergent_refs` feature enabled' do
before do
stub_feature_flags(keep_divergent_refs: { enabled: true, project: project })
end
it 'updates the `keep_divergent_refs` attribute' do
project.add_maintainer(user)
put api(route[mirror.id], user), params: { keep_divergent_refs: 'true' }
expect(response).to have_gitlab_http_status(:success)
expect(json_response['keep_divergent_refs']).to eq(true)
end
end end
# TODO: Remove flag: https://gitlab.com/gitlab-org/gitlab/issues/38121 # TODO: Remove flag: https://gitlab.com/gitlab-org/gitlab/issues/38121
......
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