Commit 70d25552 authored by Robert Speicher's avatar Robert Speicher

Modify keep_divergent_refs via RemoteMirror API

When the feature is enabled, this attribute can now be modified via the
API.
parent 72466dc4
......@@ -12,6 +12,9 @@ module API
expose :last_successful_update_at
expose :last_error
expose :only_protected_branches
expose :keep_divergent_refs, if: -> (mirror, _options) do
::Feature.enabled?(:keep_divergent_refs, mirror.project)
end
end
end
end
......@@ -33,9 +33,11 @@ module API
requires :url, type: String, desc: 'The URL for a remote mirror'
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 :keep_divergent_refs, type: Boolean, desc: 'Determines if divergent refs are kept on the target'
end
post ':id/remote_mirrors' do
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)
......@@ -53,12 +55,15 @@ module API
requires :mirror_id, type: String, desc: 'The ID of a remote mirror'
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 :keep_divergent_refs, type: Boolean, desc: 'Determines if divergent refs are kept on the target'
end
put ':id/remote_mirrors/:mirror_id' do
mirror = user_project.remote_mirrors.find(params[:mirror_id])
mirror_params = declared_params(include_missing: false)
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 }
result = ::Projects::UpdateService
......
......@@ -10,7 +10,7 @@
"last_successful_update_at",
"last_error",
"only_protected_branches"
],
],
"properties": {
"id": { "type": "integer" },
"enabled": { "type": "boolean" },
......@@ -20,7 +20,8 @@
"last_update_started_at": { "type": ["string", "null"] },
"last_successful_update_at": { "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
}
......@@ -91,6 +91,10 @@ describe API::RemoteMirrors do
let(:route) { ->(id) { "/projects/#{project.id}/remote_mirrors/#{id}" } }
let(:mirror) { project.remote_mirrors.first }
before do
stub_feature_flags(keep_divergent_refs: false)
end
it 'requires `admin_remote_mirror` permission' do
put api(route[mirror.id], developer)
......@@ -102,12 +106,31 @@ describe API::RemoteMirrors do
put api(route[mirror.id], user), params: {
enabled: '0',
only_protected_branches: 'true'
only_protected_branches: 'true',
keep_divergent_refs: 'true'
}
expect(response).to have_gitlab_http_status(:success)
expect(json_response['enabled']).to eq(false)
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
# 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