summaryrefslogtreecommitdiff
path: root/lib/api/projects.rb
diff options
context:
space:
mode:
authorSebastian Ziebell <sebastian.ziebell@asquera.de>2013-02-08 10:32:42 +0100
committerSebastian Ziebell <sebastian.ziebell@asquera.de>2013-02-08 10:32:42 +0100
commit8045a81bcf5822f1992442750e1484a93c368229 (patch)
tree94ce2b257f3ba002ac1a0fde70b69b622304810d /lib/api/projects.rb
parent5d8a99f10429168e6471fdd1843f5045a10a84b3 (diff)
parent2f0a75ab77af430f682d67aa9bb865007d832795 (diff)
downloadgitlab-ce-8045a81bcf5822f1992442750e1484a93c368229.tar.gz
Merge branch 'master' into fixes/api
Diffstat (limited to 'lib/api/projects.rb')
-rw-r--r--lib/api/projects.rb40
1 files changed, 38 insertions, 2 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 5444ba6a205..47ab4e1aab0 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -222,7 +222,7 @@ module Gitlab
# Example Request:
# GET /projects/:id/repository/branches
get ":id/repository/branches" do
- present user_project.repo.heads.sort_by(&:name), with: Entities::RepoObject
+ present user_project.repo.heads.sort_by(&:name), with: Entities::RepoObject, project: user_project
end
# Get a single branch
@@ -234,7 +234,43 @@ module Gitlab
# GET /projects/:id/repository/branches/:branch
get ":id/repository/branches/:branch" do
@branch = user_project.repo.heads.find { |item| item.name == params[:branch] }
- present @branch, with: Entities::RepoObject
+ present @branch, with: Entities::RepoObject, project: user_project
+ end
+
+ # Protect a single branch
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # branch (required) - The name of the branch
+ # Example Request:
+ # PUT /projects/:id/repository/branches/:branch/protect
+ put ":id/repository/branches/:branch/protect" do
+ @branch = user_project.repo.heads.find { |item| item.name == params[:branch] }
+ protected = user_project.protected_branches.find_by_name(@branch.name)
+
+ unless protected
+ user_project.protected_branches.create(:name => @branch.name)
+ end
+
+ present @branch, with: Entities::RepoObject, project: user_project
+ end
+
+ # Unprotect a single branch
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # branch (required) - The name of the branch
+ # Example Request:
+ # PUT /projects/:id/repository/branches/:branch/unprotect
+ put ":id/repository/branches/:branch/unprotect" do
+ @branch = user_project.repo.heads.find { |item| item.name == params[:branch] }
+ protected = user_project.protected_branches.find_by_name(@branch.name)
+
+ if protected
+ protected.destroy
+ end
+
+ present @branch, with: Entities::RepoObject, project: user_project
end
# Get a project repository tags