Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
3413f6fa
Commit
3413f6fa
authored
Jul 19, 2016
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify entities for branches and tags API
parent
1cd573ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
42 deletions
+21
-42
lib/api/branches.rb
lib/api/branches.rb
+7
-5
lib/api/entities.rb
lib/api/entities.rb
+14
-37
No files found.
lib/api/branches.rb
View file @
3413f6fa
...
@@ -15,7 +15,8 @@ module API
...
@@ -15,7 +15,8 @@ module API
# GET /projects/:id/repository/branches
# GET /projects/:id/repository/branches
get
":id/repository/branches"
do
get
":id/repository/branches"
do
branches
=
user_project
.
repository
.
branches
.
sort_by
(
&
:name
)
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
end
# Get a single branch
# Get a single branch
...
@@ -28,7 +29,8 @@ module API
...
@@ -28,7 +29,8 @@ module API
get
':id/repository/branches/:branch'
,
requirements:
{
branch:
/.+/
}
do
get
':id/repository/branches/:branch'
,
requirements:
{
branch:
/.+/
}
do
@branch
=
user_project
.
repository
.
branches
.
find
{
|
item
|
item
.
name
==
params
[
:branch
]
}
@branch
=
user_project
.
repository
.
branches
.
find
{
|
item
|
item
.
name
==
params
[
:branch
]
}
not_found!
(
"Branch"
)
unless
@branch
not_found!
(
"Branch"
)
unless
@branch
present
@branch
,
with:
Entities
::
RepoObject
,
project:
user_project
present
@branch
,
with:
Entities
::
RepoBranch
,
project:
user_project
end
end
# Protect a single branch
# Protect a single branch
...
@@ -60,7 +62,7 @@ module API
...
@@ -60,7 +62,7 @@ module API
developers_can_merge:
developers_can_merge
||
false
)
developers_can_merge:
developers_can_merge
||
false
)
end
end
present
@branch
,
with:
Entities
::
Repo
Object
,
project:
user_project
present
@branch
,
with:
Entities
::
Repo
Branch
,
project:
user_project
end
end
# Unprotect a single branch
# Unprotect a single branch
...
@@ -79,7 +81,7 @@ module API
...
@@ -79,7 +81,7 @@ module API
protected_branch
=
user_project
.
protected_branches
.
find_by
(
name:
@branch
.
name
)
protected_branch
=
user_project
.
protected_branches
.
find_by
(
name:
@branch
.
name
)
protected_branch
.
destroy
if
protected_branch
protected_branch
.
destroy
if
protected_branch
present
@branch
,
with:
Entities
::
Repo
Object
,
project:
user_project
present
@branch
,
with:
Entities
::
Repo
Branch
,
project:
user_project
end
end
# Create branch
# Create branch
...
@@ -97,7 +99,7 @@ module API
...
@@ -97,7 +99,7 @@ module API
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
present
result
[
:branch
],
present
result
[
:branch
],
with:
Entities
::
Repo
Object
,
with:
Entities
::
Repo
Branch
,
project:
user_project
project:
user_project
else
else
render_api_error!
(
result
[
:message
],
400
)
render_api_error!
(
result
[
:message
],
400
)
...
...
lib/api/entities.rb
View file @
3413f6fa
...
@@ -114,33 +114,23 @@ module API
...
@@ -114,33 +114,23 @@ module API
end
end
end
end
class
Repo
Object
<
Grape
::
Entity
class
Repo
Branch
<
Grape
::
Entity
expose
:name
expose
:name
expose
:commit
do
|
repo_obj
,
options
|
expose
:commit
do
|
repo_branch
,
options
|
if
repo_obj
.
respond_to?
(
:commit
)
options
[
:project
].
repository
.
commit
(
repo_branch
.
target
)
repo_obj
.
commit
elsif
options
[
:project
]
options
[
:project
].
repository
.
commit
(
repo_obj
.
target
)
end
end
end
expose
:protected
do
|
repo_obj
,
options
|
expose
:protected
do
|
repo_branch
,
options
|
if
options
[
:project
]
options
[
:project
].
protected_branch?
repo_branch
.
name
options
[
:project
].
protected_branch?
repo_obj
.
name
end
end
end
expose
:developers_can_push
do
|
repo_obj
,
options
|
expose
:developers_can_push
do
|
repo_branch
,
options
|
if
options
[
:project
]
options
[
:project
].
developers_can_push_to_protected_branch?
repo_branch
.
name
options
[
:project
].
developers_can_push_to_protected_branch?
repo_obj
.
name
end
end
end
expose
:developers_can_merge
do
|
repo_obj
,
options
|
expose
:developers_can_merge
do
|
repo_branch
,
options
|
if
options
[
:project
]
options
[
:project
].
developers_can_merge_to_protected_branch?
repo_branch
.
name
options
[
:project
].
developers_can_merge_to_protected_branch?
repo_obj
.
name
end
end
end
end
end
...
@@ -437,27 +427,14 @@ module API
...
@@ -437,27 +427,14 @@ module API
end
end
class
RepoTag
<
Grape
::
Entity
class
RepoTag
<
Grape
::
Entity
expose
:name
expose
:name
,
:message
expose
:message
do
|
repo_obj
,
_options
|
if
repo_obj
.
respond_to?
(
:message
)
repo_obj
.
message
else
nil
end
end
expose
:commit
do
|
repo_obj
,
options
|
expose
:commit
do
|
repo_tag
,
options
|
if
repo_obj
.
respond_to?
(
:commit
)
options
[
:project
].
repository
.
commit
(
repo_tag
.
target
)
repo_obj
.
commit
elsif
options
[
:project
]
options
[
:project
].
repository
.
commit
(
repo_obj
.
target
)
end
end
end
expose
:release
,
using:
Entities
::
Release
do
|
repo_obj
,
options
|
expose
:release
,
using:
Entities
::
Release
do
|
repo_tag
,
options
|
if
options
[
:project
]
options
[
:project
].
releases
.
find_by
(
tag:
repo_tag
.
name
)
options
[
:project
].
releases
.
find_by
(
tag:
repo_obj
.
name
)
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment