Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/branches.rb')
-rw-r--r--lib/api/branches.rb45
1 files changed, 37 insertions, 8 deletions
diff --git a/lib/api/branches.rb b/lib/api/branches.rb
index 7e6b0214c03..845e42c2ed8 100644
--- a/lib/api/branches.rb
+++ b/lib/api/branches.rb
@@ -14,7 +14,7 @@ module API
before do
require_repository_enabled!
- authorize! :download_code, user_project
+ authorize! :read_code, user_project
end
rescue_from Gitlab::Git::Repository::NoRepository do
@@ -29,17 +29,21 @@ module API
end
params do
- requires :id, type: String, desc: 'The ID of a project'
+ requires :id, types: [String, Integer], desc: 'The ID or URL-encoded path of the project'
end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get a project repository branches' do
success Entities::Branch
+ success code: 200, model: Entities::Branch
+ failure [{ code: 404, message: '404 Project Not Found' }]
+ tags %w[branches]
+ is_array true
end
params do
use :pagination
use :filter_params
- optional :page_token, type: String, desc: 'Name of branch to start the paginaition from'
+ optional :page_token, type: String, desc: 'Name of branch to start the pagination from'
end
get ':id/repository/branches', urgency: :low do
cache_action([user_project, :branches, current_user, declared_params], expires_in: 30.seconds) do
@@ -65,15 +69,23 @@ module API
end
resource ':id/repository/branches/:branch', requirements: BRANCH_ENDPOINT_REQUIREMENTS do
- desc 'Get a single branch' do
- success Entities::Branch
- end
params do
requires :branch, type: String, desc: 'The name of the branch'
end
+ desc 'Check if a branch exists' do
+ success [{ code: 204, message: 'No Content' }]
+ failure [{ code: 404, message: 'Not Found' }]
+ tags %w[branches]
+ end
head do
user_project.repository.branch_exists?(params[:branch]) ? no_content! : not_found!
end
+ desc 'Get a single repository branch' do
+ success Entities::Branch
+ success code: 200, model: Entities::Branch
+ failure [{ code: 404, message: 'Branch Not Found' }, { code: 404, message: 'Project Not Found' }]
+ tags %w[branches]
+ end
get '/', urgency: :low do
branch = find_branch!(params[:branch])
@@ -87,6 +99,9 @@ module API
# but it works with the changed data model to infer `developers_can_merge` and `developers_can_push`.
desc 'Protect a single branch' do
success Entities::Branch
+ success code: 200, model: Entities::Branch
+ failure [{ code: 404, message: '404 Branch Not Found' }]
+ tags %w[branches]
end
params do
requires :branch, type: String, desc: 'The name of the branch', allow_blank: false
@@ -126,6 +141,9 @@ module API
# Note: This API will be deprecated in favor of the protected branches API.
desc 'Unprotect a single branch' do
success Entities::Branch
+ success code: 200, model: Entities::Branch
+ failure [{ code: 404, message: '404 Project Not Found' }, { code: 404, message: '404 Branch Not Found' }]
+ tags %w[branches]
end
params do
requires :branch, type: String, desc: 'The name of the branch', allow_blank: false
@@ -145,6 +163,9 @@ module API
desc 'Create branch' do
success Entities::Branch
+ success code: 201, model: Entities::Branch
+ failure [{ code: 400, message: 'Failed to create branch' }, { code: 400, message: 'Branch already exists' }]
+ tags %w[branches]
end
params do
requires :branch, type: String, desc: 'The name of the branch', allow_blank: false
@@ -166,7 +187,11 @@ module API
end
end
- desc 'Delete a branch'
+ desc 'Delete a branch' do
+ success code: 204
+ failure [{ code: 404, message: 'Branch Not Found' }]
+ tags %w[branches]
+ end
params do
requires :branch, type: String, desc: 'The name of the branch', allow_blank: false
end
@@ -187,7 +212,11 @@ module API
end
end
- desc 'Delete all merged branches'
+ desc 'Delete all merged branches' do
+ success code: 202, message: '202 Accepted'
+ failure [{ code: 404, message: '404 Project Not Found' }]
+ tags %w[branches]
+ end
delete ':id/repository/merged_branches' do
::Branches::DeleteMergedService.new(user_project, current_user).async_execute