Commit ef482c91 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'confapi-repo-push-mirror' into 'master'

API for creating remote mirrors

Closes #24189

See merge request gitlab-org/gitlab!25825
parents 2ecc6b7d 98f8fe95
---
title: Add support for configuring remote mirrors via API
merge_request: 25825
author: Rajendra Kadam
type: added
......@@ -26,6 +26,26 @@ module API
with: Entities::RemoteMirror
end
desc 'Create remote mirror for a project' do
success Entities::RemoteMirror
end
params do
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'
end
post ':id/remote_mirrors' do
create_params = declared_params(include_missing: false)
new_mirror = user_project.remote_mirrors.create(create_params)
if new_mirror.persisted?
present new_mirror, with: Entities::RemoteMirror
else
render_validation_error!(new_mirror)
end
end
desc 'Update the attributes of a single remote mirror' do
success Entities::RemoteMirror
end
......
......@@ -39,6 +39,54 @@ describe API::RemoteMirrors do
end
end
describe 'POST /projects/:id/remote_mirrors' do
let(:route) { "/projects/#{project.id}/remote_mirrors" }
shared_examples 'creates a remote mirror' do
it 'creates a remote mirror and returns reponse' do
project.add_maintainer(user)
post api(route, user), params: params
enabled = params.fetch(:enabled, false)
expect(response).to have_gitlab_http_status(:success)
expect(response).to match_response_schema('remote_mirror')
expect(json_response['enabled']).to eq(enabled)
end
end
it 'requires `admin_remote_mirror` permission' do
post api(route, developer)
expect(response).to have_gitlab_http_status(:unauthorized)
end
context 'creates a remote mirror' do
context 'disabled by default' do
let(:params) { { url: 'https://foo:bar@test.com' } }
it_behaves_like 'creates a remote mirror'
end
context 'enabled' do
let(:params) { { url: 'https://foo:bar@test.com', enabled: true } }
it_behaves_like 'creates a remote mirror'
end
end
it 'returns error if url is invalid' do
project.add_maintainer(user)
post api(route, user), params: {
url: 'ftp://foo:bar@test.com'
}
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']['url']).to eq(["is blocked: Only allowed schemes are ssh, git, http, https"])
end
end
describe 'PUT /projects/:id/remote_mirrors/:mirror_id' do
let(:route) { ->(id) { "/projects/#{project.id}/remote_mirrors/#{id}" } }
let(:mirror) { project.remote_mirrors.first }
......
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