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
e7b40c2f
Commit
e7b40c2f
authored
Dec 14, 2017
by
haseeb
Committed by
Rémy Coutable
Dec 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sorting for tags api
parent
b0bc676f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
5 deletions
+65
-5
app/models/repository.rb
app/models/repository.rb
+3
-1
changelogs/unreleased/40509_sorting_tags_api.yml
changelogs/unreleased/40509_sorting_tags_api.yml
+5
-0
doc/api/tags.md
doc/api/tags.md
+5
-1
lib/api/tags.rb
lib/api/tags.rb
+6
-1
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+8
-2
spec/requests/api/tags_spec.rb
spec/requests/api/tags_spec.rb
+38
-0
No files found.
app/models/repository.rb
View file @
e7b40c2f
...
...
@@ -686,7 +686,9 @@ class Repository
def
tags_sorted_by
(
value
)
case
value
when
'name'
when
'name_asc'
VersionSorter
.
sort
(
tags
)
{
|
tag
|
tag
.
name
}
when
'name_desc'
VersionSorter
.
rsort
(
tags
)
{
|
tag
|
tag
.
name
}
when
'updated_desc'
tags_sorted_by_committed_date
.
reverse
...
...
changelogs/unreleased/40509_sorting_tags_api.yml
0 → 100644
View file @
e7b40c2f
---
title
:
add support for sorting in tags api
merge_request
:
15772
author
:
haseebeqx
type
:
added
doc/api/tags.md
View file @
e7b40c2f
...
...
@@ -12,7 +12,11 @@ GET /projects/:id/repository/tags
Parameters:
-
`id`
(required) - The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user
| 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|
|
`order_by`
| string | no | Return tags ordered by
`name`
or
`updated`
fields. Default is
`updated`
|
|
`sort`
| string | no | Return tags sorted in
`asc`
or
`desc`
order. Default is
`desc`
|
```
json
[
...
...
lib/api/tags.rb
View file @
e7b40c2f
...
...
@@ -14,10 +14,15 @@ module API
success
Entities
::
Tag
end
params
do
optional
:sort
,
type:
String
,
values:
%w[asc desc]
,
default:
'desc'
,
desc:
'Return tags sorted in updated by `asc` or `desc` order.'
optional
:order_by
,
type:
String
,
values:
%w[name updated]
,
default:
'updated'
,
desc:
'Return tags ordered by `name` or `updated` fields.'
use
:pagination
end
get
':id/repository/tags'
do
tags
=
::
Kaminari
.
paginate_array
(
user_project
.
repository
.
tags
.
sort_by
(
&
:name
).
reverse
)
tags
=
::
Kaminari
.
paginate_array
(
::
TagsFinder
.
new
(
user_project
.
repository
,
sort:
"
#{
params
[
:order_by
]
}
_
#{
params
[
:sort
]
}
"
).
execute
)
present
paginate
(
tags
),
with:
Entities
::
Tag
,
project:
user_project
end
...
...
spec/models/repository_spec.rb
View file @
e7b40c2f
...
...
@@ -59,12 +59,18 @@ describe Repository do
end
describe
'tags_sorted_by'
do
context
'name'
do
subject
{
repository
.
tags_sorted_by
(
'name'
).
map
(
&
:name
)
}
context
'name
_desc
'
do
subject
{
repository
.
tags_sorted_by
(
'name
_desc
'
).
map
(
&
:name
)
}
it
{
is_expected
.
to
eq
([
'v1.1.0'
,
'v1.0.0'
])
}
end
context
'name_asc'
do
subject
{
repository
.
tags_sorted_by
(
'name_asc'
).
map
(
&
:name
)
}
it
{
is_expected
.
to
eq
([
'v1.0.0'
,
'v1.1.0'
])
}
end
context
'updated'
do
let
(
:tag_a
)
{
repository
.
find_tag
(
'v1.0.0'
)
}
let
(
:tag_b
)
{
repository
.
find_tag
(
'v1.1.0'
)
}
...
...
spec/requests/api/tags_spec.rb
View file @
e7b40c2f
...
...
@@ -16,6 +16,44 @@ describe API::Tags do
describe
'GET /projects/:id/repository/tags'
do
let
(
:route
)
{
"/projects/
#{
project_id
}
/repository/tags"
}
context
'sorting'
do
let
(
:current_user
)
{
user
}
it
'sorts by descending order by default'
do
get
api
(
route
,
current_user
)
desc_order_tags
=
project
.
repository
.
tags
.
sort_by
{
|
tag
|
tag
.
dereferenced_target
.
committed_date
}
desc_order_tags
.
reverse!
.
map!
{
|
tag
|
tag
.
dereferenced_target
.
id
}
expect
(
json_response
.
map
{
|
tag
|
tag
[
'commit'
][
'id'
]
}).
to
eq
(
desc_order_tags
)
end
it
'sorts by ascending order if specified'
do
get
api
(
"
#{
route
}
?sort=asc"
,
current_user
)
asc_order_tags
=
project
.
repository
.
tags
.
sort_by
{
|
tag
|
tag
.
dereferenced_target
.
committed_date
}
asc_order_tags
.
map!
{
|
tag
|
tag
.
dereferenced_target
.
id
}
expect
(
json_response
.
map
{
|
tag
|
tag
[
'commit'
][
'id'
]
}).
to
eq
(
asc_order_tags
)
end
it
'sorts by name in descending order when requested'
do
get
api
(
"
#{
route
}
?order_by=name"
,
current_user
)
ordered_by_name
=
project
.
repository
.
tags
.
map
{
|
tag
|
tag
.
name
}.
sort
.
reverse
expect
(
json_response
.
map
{
|
tag
|
tag
[
'name'
]
}).
to
eq
(
ordered_by_name
)
end
it
'sorts by name in ascending order when requested'
do
get
api
(
"
#{
route
}
?order_by=name&sort=asc"
,
current_user
)
ordered_by_name
=
project
.
repository
.
tags
.
map
{
|
tag
|
tag
.
name
}.
sort
expect
(
json_response
.
map
{
|
tag
|
tag
[
'name'
]
}).
to
eq
(
ordered_by_name
)
end
end
shared_examples_for
'repository tags'
do
it
'returns the repository tags'
do
get
api
(
route
,
current_user
)
...
...
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