Commit 519cf46c authored by Robert Speicher's avatar Robert Speicher

Add a `remote_mirrors` project API

This API can be used to gather information on a project's push mirrors
and their status.
parent eefa6f35
......@@ -156,6 +156,7 @@ module API
mount ::API::ProtectedTags
mount ::API::Releases
mount ::API::Release::Links
mount ::API::RemoteMirrors
mount ::API::Repositories
mount ::API::Runner
mount ::API::Runners
......
......@@ -166,6 +166,18 @@ module API
end
end
class RemoteMirror < Grape::Entity
expose :id
expose :enabled
expose :safe_url, as: :url
expose :update_status
expose :last_update_at
expose :last_update_started_at
expose :last_successful_update_at
expose :last_error
expose :only_protected_branches
end
class ProjectImportStatus < ProjectIdentity
expose :import_status
......
# frozen_string_literal: true
module API
class RemoteMirrors < Grape::API
include PaginationParams
before do
# TODO: Remove flag: https://gitlab.com/gitlab-org/gitlab/issues/38121
not_found! unless Feature.enabled?(:remote_mirrors_api, user_project)
end
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc "List the project's remote mirrors" do
success Entities::RemoteMirror
end
params do
use :pagination
end
get ':id/remote_mirrors' do
unauthorized! unless can?(current_user, :admin_remote_mirror, user_project)
present paginate(user_project.remote_mirrors),
with: Entities::RemoteMirror
end
end
end
end
{
"type": "object",
"required": [
"id",
"enabled",
"url",
"update_status",
"last_update_at",
"last_update_started_at",
"last_successful_update_at",
"last_error",
"only_protected_branches"
],
"properties": {
"id": { "type": "integer" },
"enabled": { "type": "boolean" },
"url": { "type": "string" },
"update_status": { "type": "string" },
"last_update_at": { "type": ["string", "null"] },
"last_update_started_at": { "type": ["string", "null"] },
"last_successful_update_at": { "type": ["string", "null"] },
"last_error": { "type": ["string", "null"] },
"only_protected_branches": { "type": "boolean" }
},
"additionalProperties": false
}
{
"type": "array",
"items": { "$ref": "remote_mirror.json" }
}
# frozen_string_literal: true
require 'spec_helper'
describe API::RemoteMirrors do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository, :remote_mirror) }
describe 'GET /projects/:id/remote_mirrors' do
let(:route) { "/projects/#{project.id}/remote_mirrors" }
it 'requires `admin_remote_mirror` permission' do
project.add_developer(user)
get api(route, user)
expect(response).to have_gitlab_http_status(:unauthorized)
end
it 'returns a list of remote mirrors' do
project.add_maintainer(user)
get api(route, user)
expect(response).to have_gitlab_http_status(:success)
expect(response).to match_response_schema('remote_mirrors')
end
context 'with the `remote_mirrors_api` feature disabled' do
before do
stub_feature_flags(remote_mirrors_api: false)
end
it 'responds with `not_found`' do
get api(route, user)
expect(response).to have_gitlab_http_status(:not_found)
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