BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
78ba3a9a
Commit
78ba3a9a
authored
Dec 14, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '40509_sorting_tags_api' into 'master'
sorting for tags api See merge request gitlab-org/gitlab-ce!15772
parents
b0bc676f
e7b40c2f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
5 deletions
+65
-5
repository.rb
app/models/repository.rb
+3
-1
40509_sorting_tags_api.yml
changelogs/unreleased/40509_sorting_tags_api.yml
+5
-0
tags.md
doc/api/tags.md
+5
-1
tags.rb
lib/api/tags.rb
+6
-1
repository_spec.rb
spec/models/repository_spec.rb
+8
-2
tags_spec.rb
spec/requests/api/tags_spec.rb
+38
-0
No files found.
app/models/repository.rb
View file @
78ba3a9a
...
@@ -686,7 +686,9 @@ class Repository
...
@@ -686,7 +686,9 @@ class Repository
def
tags_sorted_by
(
value
)
def
tags_sorted_by
(
value
)
case
value
case
value
when
'name'
when
'name_asc'
VersionSorter
.
sort
(
tags
)
{
|
tag
|
tag
.
name
}
when
'name_desc'
VersionSorter
.
rsort
(
tags
)
{
|
tag
|
tag
.
name
}
VersionSorter
.
rsort
(
tags
)
{
|
tag
|
tag
.
name
}
when
'updated_desc'
when
'updated_desc'
tags_sorted_by_committed_date
.
reverse
tags_sorted_by_committed_date
.
reverse
...
...
changelogs/unreleased/40509_sorting_tags_api.yml
0 → 100644
View file @
78ba3a9a
---
title
:
add support for sorting in tags api
merge_request
:
15772
author
:
haseebeqx
type
:
added
doc/api/tags.md
View file @
78ba3a9a
...
@@ -12,7 +12,11 @@ GET /projects/:id/repository/tags
...
@@ -12,7 +12,11 @@ GET /projects/:id/repository/tags
Parameters:
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
```
json
[
[
...
...
lib/api/tags.rb
View file @
78ba3a9a
...
@@ -14,10 +14,15 @@ module API
...
@@ -14,10 +14,15 @@ module API
success
Entities
::
Tag
success
Entities
::
Tag
end
end
params
do
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
use
:pagination
end
end
get
':id/repository/tags'
do
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
present
paginate
(
tags
),
with:
Entities
::
Tag
,
project:
user_project
end
end
...
...
spec/models/repository_spec.rb
View file @
78ba3a9a
...
@@ -59,12 +59,18 @@ describe Repository do
...
@@ -59,12 +59,18 @@ describe Repository do
end
end
describe
'tags_sorted_by'
do
describe
'tags_sorted_by'
do
context
'name'
do
context
'name
_desc
'
do
subject
{
repository
.
tags_sorted_by
(
'name'
).
map
(
&
:name
)
}
subject
{
repository
.
tags_sorted_by
(
'name
_desc
'
).
map
(
&
:name
)
}
it
{
is_expected
.
to
eq
([
'v1.1.0'
,
'v1.0.0'
])
}
it
{
is_expected
.
to
eq
([
'v1.1.0'
,
'v1.0.0'
])
}
end
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
context
'updated'
do
let
(
:tag_a
)
{
repository
.
find_tag
(
'v1.0.0'
)
}
let
(
:tag_a
)
{
repository
.
find_tag
(
'v1.0.0'
)
}
let
(
:tag_b
)
{
repository
.
find_tag
(
'v1.1.0'
)
}
let
(
:tag_b
)
{
repository
.
find_tag
(
'v1.1.0'
)
}
...
...
spec/requests/api/tags_spec.rb
View file @
78ba3a9a
...
@@ -16,6 +16,44 @@ describe API::Tags do
...
@@ -16,6 +16,44 @@ describe API::Tags do
describe
'GET /projects/:id/repository/tags'
do
describe
'GET /projects/:id/repository/tags'
do
let
(
:route
)
{
"/projects/
#{
project_id
}
/repository/tags"
}
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
shared_examples_for
'repository tags'
do
it
'returns the repository tags'
do
it
'returns the repository tags'
do
get
api
(
route
,
current_user
)
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