Commit 07e95b0c authored by Douwe Maan's avatar Douwe Maan

Expose whether current user can push into a branch on branches API

parent 99fdbe4c
---
title: Expose whether current user can push into a branch on branches API
merge_request:
author:
type: added
...@@ -29,6 +29,7 @@ Example response: ...@@ -29,6 +29,7 @@ Example response:
"protected": true, "protected": true,
"developers_can_push": false, "developers_can_push": false,
"developers_can_merge": false, "developers_can_merge": false,
"can_push": true,
"commit": { "commit": {
"author_email": "john@example.com", "author_email": "john@example.com",
"author_name": "John Smith", "author_name": "John Smith",
...@@ -76,6 +77,7 @@ Example response: ...@@ -76,6 +77,7 @@ Example response:
"protected": true, "protected": true,
"developers_can_push": false, "developers_can_push": false,
"developers_can_merge": false, "developers_can_merge": false,
"can_push": true,
"commit": { "commit": {
"author_email": "john@example.com", "author_email": "john@example.com",
"author_name": "John Smith", "author_name": "John Smith",
...@@ -140,7 +142,8 @@ Example response: ...@@ -140,7 +142,8 @@ Example response:
"merged": false, "merged": false,
"protected": true, "protected": true,
"developers_can_push": true, "developers_can_push": true,
"developers_can_merge": true "developers_can_merge": true,
"can_push": true
} }
``` ```
...@@ -188,7 +191,8 @@ Example response: ...@@ -188,7 +191,8 @@ Example response:
"merged": false, "merged": false,
"protected": false, "protected": false,
"developers_can_push": false, "developers_can_push": false,
"developers_can_merge": false "developers_can_merge": false,
"can_push": true
} }
``` ```
...@@ -231,7 +235,8 @@ Example response: ...@@ -231,7 +235,8 @@ Example response:
"merged": false, "merged": false,
"protected": false, "protected": false,
"developers_can_push": false, "developers_can_push": false,
"developers_can_merge": false "developers_can_merge": false,
"can_push": true
} }
``` ```
......
...@@ -349,6 +349,10 @@ module API ...@@ -349,6 +349,10 @@ module API
expose :developers_can_merge do |repo_branch, options| expose :developers_can_merge do |repo_branch, options|
options[:project].protected_branches.developers_can?(:merge, repo_branch.name) options[:project].protected_branches.developers_can?(:merge, repo_branch.name)
end end
expose :can_push do |repo_branch, options|
Gitlab::UserAccess.new(options[:current_user], project: options[:project]).can_push_to_branch?(repo_branch.name)
end
end end
class TreeObject < Grape::Entity class TreeObject < Grape::Entity
......
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
"merged": { "type": "boolean" }, "merged": { "type": "boolean" },
"protected": { "type": "boolean" }, "protected": { "type": "boolean" },
"developers_can_push": { "type": "boolean" }, "developers_can_push": { "type": "boolean" },
"developers_can_merge": { "type": "boolean" } "developers_can_merge": { "type": "boolean" },
"can_push": { "type": "boolean" }
}, },
"additionalProperties": false "additionalProperties": false
} }
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