Commit 03ec52ec authored by Nick Thomas's avatar Nick Thomas

Merge branch 'feature/get-project-mirror-api' into 'master'

Implement API to get single Project Remote Mirror

See merge request gitlab-org/gitlab!82770
parents 676fd0cb 67ca0604
......@@ -51,6 +51,43 @@ NOTE:
For security reasons, the `url` attribute is always scrubbed of username
and password information.
## Get a single project's remote mirror
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/82770) in GitLab 14.10.
Returns a remote mirror and its statuses:
```plaintext
GET /projects/:id/remote_mirrors/:mirror_id
```
Example request:
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/42/remote_mirrors/101486"
```
Example response:
```json
{
"enabled": true,
"id": 101486,
"last_error": null,
"last_successful_update_at": "2020-01-06T17:32:02.823Z",
"last_update_at": "2020-01-06T17:32:02.823Z",
"last_update_started_at": "2020-01-06T17:31:55.864Z",
"only_protected_branches": true,
"keep_divergent_refs": true,
"update_status": "finished",
"url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git"
}
```
NOTE:
For security reasons, the `url` attribute is always scrubbed of username
and password information.
## Create a pull mirror
Learn how to [configure a pull mirror](projects.md#configure-pull-mirroring-for-a-project) using the Projects API.
......
......@@ -25,6 +25,18 @@ module API
with: Entities::RemoteMirror
end
desc 'Get a single remote mirror' do
success Entities::RemoteMirror
end
params do
requires :mirror_id, type: String, desc: 'The ID of a remote mirror'
end
get ':id/remote_mirrors/:mirror_id' do
mirror = user_project.remote_mirrors.find(params[:mirror_id])
present mirror, with: Entities::RemoteMirror
end
desc 'Create remote mirror for a project' do
success Entities::RemoteMirror
end
......
......@@ -26,6 +26,26 @@ RSpec.describe API::RemoteMirrors do
end
end
describe 'GET /projects/:id/remote_mirrors/:mirror_id' do
let(:route) { "/projects/#{project.id}/remote_mirrors/#{mirror.id}" }
let(:mirror) { project.remote_mirrors.first }
it 'requires `admin_remote_mirror` permission' do
get api(route, developer)
expect(response).to have_gitlab_http_status(:unauthorized)
end
it 'returns at remote mirror' do
project.add_maintainer(user)
get api(route, user)
expect(response).to have_gitlab_http_status(:success)
expect(response).to match_response_schema('remote_mirror')
end
end
describe 'POST /projects/:id/remote_mirrors' do
let(:route) { "/projects/#{project.id}/remote_mirrors" }
......@@ -75,11 +95,11 @@ RSpec.describe API::RemoteMirrors do
end
describe 'PUT /projects/:id/remote_mirrors/:mirror_id' do
let(:route) { ->(id) { "/projects/#{project.id}/remote_mirrors/#{id}" } }
let(:route) { "/projects/#{project.id}/remote_mirrors/#{mirror.id}" }
let(:mirror) { project.remote_mirrors.first }
it 'requires `admin_remote_mirror` permission' do
put api(route[mirror.id], developer)
put api(route, developer)
expect(response).to have_gitlab_http_status(:unauthorized)
end
......@@ -87,7 +107,7 @@ RSpec.describe API::RemoteMirrors do
it 'updates a remote mirror' do
project.add_maintainer(user)
put api(route[mirror.id], user), params: {
put api(route, user), params: {
enabled: '0',
only_protected_branches: 'true',
keep_divergent_refs: 'true'
......
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