diff options
author | Rémy Coutable <remy@rymai.me> | 2016-07-19 12:48:17 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-07-19 12:48:17 +0000 |
commit | ad14c1bf85f716ed698e8802161de74f462a106c (patch) | |
tree | a579ed16be2c1233cd4b9093537fbc2007c60f26 | |
parent | 72cc43df1cce899e22317ffe5a45a1692789eee0 (diff) | |
parent | 3413f6fa50ec4275fac99b59d3fa44608141149c (diff) | |
download | gitlab-ce-ad14c1bf85f716ed698e8802161de74f462a106c.tar.gz |
Merge branch 'api-cleanup-entities' into 'master'
Simplify entities for branches and tags API
## What does this MR do?
As talked in !5208, I improved the entity for branches and tags.
## Does this MR meet the acceptance criteria?
~~- [ ] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added~~
~~- [ ] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~
~~- [ ] API support added~~
~~- Tests~~
~~- [ ] Added for this feature/bug~~
~~- [ ] All builds are passing~~
~~- [ ] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)~~
~~- [ ] Branch has no merge conflicts with `master` (if you do - rebase it please)~~
~~- [ ] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)~~
See merge request !5343
-rw-r--r-- | lib/api/branches.rb | 12 | ||||
-rw-r--r-- | lib/api/entities.rb | 51 |
2 files changed, 21 insertions, 42 deletions
diff --git a/lib/api/branches.rb b/lib/api/branches.rb index 35efe4f2e4a..66b853eb342 100644 --- a/lib/api/branches.rb +++ b/lib/api/branches.rb @@ -15,7 +15,8 @@ module API # GET /projects/:id/repository/branches get ":id/repository/branches" do branches = user_project.repository.branches.sort_by(&:name) - present branches, with: Entities::RepoObject, project: user_project + + present branches, with: Entities::RepoBranch, project: user_project end # Get a single branch @@ -28,7 +29,8 @@ module API get ':id/repository/branches/:branch', requirements: { branch: /.+/ } do @branch = user_project.repository.branches.find { |item| item.name == params[:branch] } not_found!("Branch") unless @branch - present @branch, with: Entities::RepoObject, project: user_project + + present @branch, with: Entities::RepoBranch, project: user_project end # Protect a single branch @@ -60,7 +62,7 @@ module API developers_can_merge: developers_can_merge || false) end - present @branch, with: Entities::RepoObject, project: user_project + present @branch, with: Entities::RepoBranch, project: user_project end # Unprotect a single branch @@ -79,7 +81,7 @@ module API protected_branch = user_project.protected_branches.find_by(name: @branch.name) protected_branch.destroy if protected_branch - present @branch, with: Entities::RepoObject, project: user_project + present @branch, with: Entities::RepoBranch, project: user_project end # Create branch @@ -97,7 +99,7 @@ module API if result[:status] == :success present result[:branch], - with: Entities::RepoObject, + with: Entities::RepoBranch, project: user_project else render_api_error!(result[:message], 400) diff --git a/lib/api/entities.rb b/lib/api/entities.rb index d6fed1a1eed..d7e74582459 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -114,33 +114,23 @@ module API end end - class RepoObject < Grape::Entity + class RepoBranch < Grape::Entity expose :name - expose :commit do |repo_obj, options| - if repo_obj.respond_to?(:commit) - repo_obj.commit - elsif options[:project] - options[:project].repository.commit(repo_obj.target) - end + expose :commit do |repo_branch, options| + options[:project].repository.commit(repo_branch.target) end - expose :protected do |repo_obj, options| - if options[:project] - options[:project].protected_branch? repo_obj.name - end + expose :protected do |repo_branch, options| + options[:project].protected_branch? repo_branch.name end - expose :developers_can_push do |repo_obj, options| - if options[:project] - options[:project].developers_can_push_to_protected_branch? repo_obj.name - end + expose :developers_can_push do |repo_branch, options| + options[:project].developers_can_push_to_protected_branch? repo_branch.name end - expose :developers_can_merge do |repo_obj, options| - if options[:project] - options[:project].developers_can_merge_to_protected_branch? repo_obj.name - end + expose :developers_can_merge do |repo_branch, options| + options[:project].developers_can_merge_to_protected_branch? repo_branch.name end end @@ -437,27 +427,14 @@ module API end class RepoTag < Grape::Entity - expose :name - expose :message do |repo_obj, _options| - if repo_obj.respond_to?(:message) - repo_obj.message - else - nil - end - end + expose :name, :message - expose :commit do |repo_obj, options| - if repo_obj.respond_to?(:commit) - repo_obj.commit - elsif options[:project] - options[:project].repository.commit(repo_obj.target) - end + expose :commit do |repo_tag, options| + options[:project].repository.commit(repo_tag.target) end - expose :release, using: Entities::Release do |repo_obj, options| - if options[:project] - options[:project].releases.find_by(tag: repo_obj.name) - end + expose :release, using: Entities::Release do |repo_tag, options| + options[:project].releases.find_by(tag: repo_tag.name) end end |