Commit cb20ab0201a0a685bd9340cc9fe4695ba82fc60b

Authored by Dmitriy Zaporozhets
2 parents 4d11a3d8 da9b009d

Merge pull request #6929 from asedge/fix_api_branches_with_periods

Add fix for API when branch names have periods in them.  Relates to issu...
Showing 1 changed file with 7 additions and 3 deletions   Show diff stats
lib/api/branches.rb
@@ -24,7 +24,7 @@ module API @@ -24,7 +24,7 @@ module API
24 # branch (required) - The name of the branch 24 # branch (required) - The name of the branch
25 # Example Request: 25 # Example Request:
26 # GET /projects/:id/repository/branches/:branch 26 # GET /projects/:id/repository/branches/:branch
27 - get ":id/repository/branches/:branch" do 27 + get ':id/repository/branches/:branch', requirements: { branch: /.*/ } do
28 @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } 28 @branch = user_project.repo.heads.find { |item| item.name == params[:branch] }
29 not_found!("Branch does not exist") if @branch.nil? 29 not_found!("Branch does not exist") if @branch.nil?
30 present @branch, with: Entities::RepoObject, project: user_project 30 present @branch, with: Entities::RepoObject, project: user_project
@@ -37,7 +37,9 @@ module API @@ -37,7 +37,9 @@ module API
37 # branch (required) - The name of the branch 37 # branch (required) - The name of the branch
38 # Example Request: 38 # Example Request:
39 # PUT /projects/:id/repository/branches/:branch/protect 39 # PUT /projects/:id/repository/branches/:branch/protect
40 - put ":id/repository/branches/:branch/protect" do 40 + put ':id/repository/branches/:branch/protect',
  41 + requirements: { branch: /.*/ } do
  42 +
41 authorize_admin_project 43 authorize_admin_project
42 44
43 @branch = user_project.repository.find_branch(params[:branch]) 45 @branch = user_project.repository.find_branch(params[:branch])
@@ -55,7 +57,9 @@ module API @@ -55,7 +57,9 @@ module API
55 # branch (required) - The name of the branch 57 # branch (required) - The name of the branch
56 # Example Request: 58 # Example Request:
57 # PUT /projects/:id/repository/branches/:branch/unprotect 59 # PUT /projects/:id/repository/branches/:branch/unprotect
58 - put ":id/repository/branches/:branch/unprotect" do 60 + put ':id/repository/branches/:branch/unprotect',
  61 + requirements: { branch: /.*/ } do
  62 +
59 authorize_admin_project 63 authorize_admin_project
60 64
61 @branch = user_project.repository.find_branch(params[:branch]) 65 @branch = user_project.repository.find_branch(params[:branch])