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
47d4890d
Commit
47d4890d
authored
Mar 05, 2018
by
bunufi
Committed by
Rémy Coutable
Mar 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update API: add search param to branches
parent
bd57be28
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
2 deletions
+41
-2
changelogs/unreleased/42712_api_branches_add_search_param_20180207.yml
...released/42712_api_branches_add_search_param_20180207.yml
+5
-0
doc/api/branches.md
doc/api/branches.md
+1
-0
lib/api/branches.rb
lib/api/branches.rb
+14
-2
spec/requests/api/branches_spec.rb
spec/requests/api/branches_spec.rb
+21
-0
No files found.
changelogs/unreleased/42712_api_branches_add_search_param_20180207.yml
0 → 100644
View file @
47d4890d
---
title
:
Add search param to Branches API
merge_request
:
17005
author
:
bunufi
type
:
added
doc/api/branches.md
View file @
47d4890d
...
...
@@ -13,6 +13,7 @@ GET /projects/:id/repository/branches
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user |
|
`search`
| string | no | Return list of branches matching the search criteria. |
```
bash
curl
--header
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v4/projects/5/repository/branches
...
...
lib/api/branches.rb
View file @
47d4890d
...
...
@@ -16,6 +16,10 @@ module API
render_api_error!
(
'The branch refname is invalid'
,
400
)
end
end
params
:filter_params
do
optional
:search
,
type:
String
,
desc:
'Return list of branches matching the search criteria'
end
end
params
do
...
...
@@ -27,15 +31,23 @@ module API
end
params
do
use
:pagination
use
:filter_params
end
get
':id/repository/branches'
do
Gitlab
::
QueryLimiting
.
whitelist
(
'https://gitlab.com/gitlab-org/gitlab-ce/issues/42329'
)
repository
=
user_project
.
repository
branches
=
::
Kaminari
.
paginate_array
(
repository
.
branches
.
sort_by
(
&
:name
))
branches
=
BranchesFinder
.
new
(
repository
,
declared_params
(
include_missing:
false
)).
execute
merged_branch_names
=
repository
.
merged_branch_names
(
branches
.
map
(
&
:name
))
present
paginate
(
branches
),
with:
Entities
::
Branch
,
project:
user_project
,
merged_branch_names:
merged_branch_names
present
(
paginate
(
::
Kaminari
.
paginate_array
(
branches
)),
with:
Entities
::
Branch
,
project:
user_project
,
merged_branch_names:
merged_branch_names
)
end
resource
':id/repository/branches/:branch'
,
requirements:
BRANCH_ENDPOINT_REQUIREMENTS
do
...
...
spec/requests/api/branches_spec.rb
View file @
47d4890d
...
...
@@ -39,6 +39,27 @@ describe API::Branches do
end
end
context
'when search parameter is passed'
do
context
'and branch exists'
do
it
'returns correct branches'
do
get
api
(
route
,
user
),
per_page:
100
,
search:
branch_name
searched_branch_names
=
json_response
.
map
{
|
branch
|
branch
[
'name'
]
}
project_branch_names
=
project
.
repository
.
branch_names
.
grep
(
/
#{
branch_name
}
/
)
expect
(
searched_branch_names
).
to
match_array
(
project_branch_names
)
end
end
context
'and branch does not exist'
do
it
'returns an empty array'
do
get
api
(
route
,
user
),
per_page:
100
,
search:
'no_such_branch_name_entropy_of_jabadabadu'
expect
(
json_response
).
to
eq
[]
end
end
end
context
'when unauthenticated'
,
'and project is public'
do
before
do
project
.
update
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
)
...
...
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