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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
66a453a5
Commit
66a453a5
authored
May 21, 2021
by
Pedro Pombeiro
Committed by
Adam Hegyi
Jun 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add 2 new sort options to runner API: CREATED_ASC and CONTACTED_DESC
parent
67529808
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
18 deletions
+84
-18
app/finders/ci/runners_finder.rb
app/finders/ci/runners_finder.rb
+3
-2
app/graphql/types/ci/runner_sort_enum.rb
app/graphql/types/ci/runner_sort_enum.rb
+3
-1
app/models/ci/runner.rb
app/models/ci/runner.rb
+8
-1
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+3
-1
spec/finders/ci/runners_finder_spec.rb
spec/finders/ci/runners_finder_spec.rb
+49
-11
spec/graphql/resolvers/ci/runners_resolver_spec.rb
spec/graphql/resolvers/ci/runners_resolver_spec.rb
+18
-2
No files found.
app/finders/ci/runners_finder.rb
View file @
66a453a5
...
@@ -24,8 +24,9 @@ module Ci
...
@@ -24,8 +24,9 @@ module Ci
end
end
def
sort_key
def
sort_key
if
@params
[
:sort
]
==
'contacted_asc'
case
@params
[
:sort
]
'contacted_asc'
when
'contacted_asc'
,
'contacted_desc'
,
'created_at_asc'
,
'created_at_desc'
@params
[
:sort
]
else
else
'created_date'
'created_date'
end
end
...
...
app/graphql/types/ci/runner_sort_enum.rb
View file @
66a453a5
...
@@ -7,7 +7,9 @@ module Types
...
@@ -7,7 +7,9 @@ module Types
description
'Values for sorting runners'
description
'Values for sorting runners'
value
'CONTACTED_ASC'
,
'Ordered by contacted_at in ascending order.'
,
value: :contacted_asc
value
'CONTACTED_ASC'
,
'Ordered by contacted_at in ascending order.'
,
value: :contacted_asc
value
'CREATED_DESC'
,
'Ordered by created_date in descending order.'
,
value: :created_date
value
'CONTACTED_DESC'
,
'Ordered by contacted_at in descending order.'
,
value: :contacted_desc
value
'CREATED_ASC'
,
'Ordered by created_at in ascending order.'
,
value: :created_at_asc
value
'CREATED_DESC'
,
'Ordered by created_at in descending order.'
,
value: :created_at_desc
end
end
end
end
end
end
app/models/ci/runner.rb
View file @
66a453a5
...
@@ -134,6 +134,8 @@ module Ci
...
@@ -134,6 +134,8 @@ module Ci
end
end
scope
:order_contacted_at_asc
,
->
{
order
(
contacted_at: :asc
)
}
scope
:order_contacted_at_asc
,
->
{
order
(
contacted_at: :asc
)
}
scope
:order_contacted_at_desc
,
->
{
order
(
contacted_at: :desc
)
}
scope
:order_created_at_asc
,
->
{
order
(
created_at: :asc
)
}
scope
:order_created_at_desc
,
->
{
order
(
created_at: :desc
)
}
scope
:order_created_at_desc
,
->
{
order
(
created_at: :desc
)
}
scope
:with_tags
,
->
{
preload
(
:tags
)
}
scope
:with_tags
,
->
{
preload
(
:tags
)
}
...
@@ -190,8 +192,13 @@ module Ci
...
@@ -190,8 +192,13 @@ module Ci
end
end
def
self
.
order_by
(
order
)
def
self
.
order_by
(
order
)
if
order
==
'contacted_asc'
case
order
when
'contacted_asc'
order_contacted_at_asc
order_contacted_at_asc
when
'contacted_desc'
order_contacted_at_desc
when
'created_at_asc'
order_created_at_asc
else
else
order_created_at_desc
order_created_at_desc
end
end
...
...
doc/api/graphql/reference/index.md
View file @
66a453a5
...
@@ -13841,7 +13841,9 @@ Values for sorting runners.
...
@@ -13841,7 +13841,9 @@ Values for sorting runners.
| Value | Description |
| Value | Description |
| ----- | ----------- |
| ----- | ----------- |
|
<a
id=
"cirunnersortcontacted_asc"
></a>
`CONTACTED_ASC`
| Ordered by contacted_at in ascending order. |
|
<a
id=
"cirunnersortcontacted_asc"
></a>
`CONTACTED_ASC`
| Ordered by contacted_at in ascending order. |
|
<a
id=
"cirunnersortcreated_desc"
></a>
`CREATED_DESC`
| Ordered by created_date in descending order. |
|
<a
id=
"cirunnersortcontacted_desc"
></a>
`CONTACTED_DESC`
| Ordered by contacted_at in descending order. |
|
<a
id=
"cirunnersortcreated_asc"
></a>
`CREATED_ASC`
| Ordered by created_at in ascending order. |
|
<a
id=
"cirunnersortcreated_desc"
></a>
`CREATED_DESC`
| Ordered by created_at in descending order. |
### `CiRunnerStatus`
### `CiRunnerStatus`
...
...
spec/finders/ci/runners_finder_spec.rb
View file @
66a453a5
...
@@ -51,23 +51,61 @@ RSpec.describe Ci::RunnersFinder do
...
@@ -51,23 +51,61 @@ RSpec.describe Ci::RunnersFinder do
end
end
context
'sort'
do
context
'sort'
do
let_it_be
(
:runner1
)
{
create
:ci_runner
,
created_at:
'2018-07-12 07:00'
,
contacted_at:
1
.
minute
.
ago
}
let_it_be
(
:runner2
)
{
create
:ci_runner
,
created_at:
'2018-07-12 08:00'
,
contacted_at:
3
.
minutes
.
ago
}
let_it_be
(
:runner3
)
{
create
:ci_runner
,
created_at:
'2018-07-12 09:00'
,
contacted_at:
2
.
minutes
.
ago
}
subject
do
described_class
.
new
(
current_user:
admin
,
params:
params
).
execute
end
context
'without sort param'
do
context
'without sort param'
do
it
'sorts by created_at'
do
let
(
:params
)
{
{}
}
runner1
=
create
:ci_runner
,
created_at:
'2018-07-12 07:00'
runner2
=
create
:ci_runner
,
created_at:
'2018-07-12 08:00'
it
'sorts by created_at descending'
do
runner3
=
create
:ci_runner
,
created_at:
'2018-07-12 09:00'
is_expected
.
to
eq
[
runner3
,
runner2
,
runner1
]
end
end
context
'with sort param equal to created_date'
do
let
(
:params
)
{
{
sort:
'created_date'
}
}
it
'sorts by created_at descending'
do
is_expected
.
to
eq
[
runner3
,
runner2
,
runner1
]
end
end
context
'with sort param equal to created_at_desc'
do
let
(
:params
)
{
{
sort:
'created_at_desc'
}
}
expect
(
described_class
.
new
(
current_user:
admin
,
params:
{}).
execute
).
to
eq
[
runner3
,
runner2
,
runner1
]
it
'sorts by created_at descending'
do
is_expected
.
to
eq
[
runner3
,
runner2
,
runner1
]
end
end
end
end
context
'with sort param'
do
context
'with sort param equal to created_at_asc'
do
it
'sorts by specified attribute'
do
let
(
:params
)
{
{
sort:
'created_at_asc'
}
}
runner1
=
create
:ci_runner
,
contacted_at:
1
.
minute
.
ago
runner2
=
create
:ci_runner
,
contacted_at:
3
.
minutes
.
ago
it
'sorts by created_at ascending'
do
runner3
=
create
:ci_runner
,
contacted_at:
2
.
minutes
.
ago
is_expected
.
to
eq
[
runner1
,
runner2
,
runner3
]
end
end
context
'by contacted_at'
do
context
'with sort param equal to contacted_asc'
do
let
(
:params
)
{
{
sort:
'contacted_asc'
}
}
it
'sorts by contacted_at ascending'
do
is_expected
.
to
eq
[
runner2
,
runner3
,
runner1
]
end
end
context
'with sort param equal to contacted_desc'
do
let
(
:params
)
{
{
sort:
'contacted_desc'
}
}
expect
(
described_class
.
new
(
current_user:
admin
,
params:
{
sort:
'contacted_asc'
}).
execute
).
to
eq
[
runner2
,
runner3
,
runner1
]
it
'sorts by contacted_at descending'
do
is_expected
.
to
eq
[
runner1
,
runner3
,
runner2
]
end
end
end
end
end
end
end
...
...
spec/graphql/resolvers/ci/runners_resolver_spec.rb
View file @
66a453a5
...
@@ -50,13 +50,29 @@ RSpec.describe Resolvers::Ci::RunnersResolver do
...
@@ -50,13 +50,29 @@ RSpec.describe Resolvers::Ci::RunnersResolver do
it
{
is_expected
.
to
eq
([
offline_project_runner
,
instance_runner
,
inactive_project_runner
,
group_runner
])
}
it
{
is_expected
.
to
eq
([
offline_project_runner
,
instance_runner
,
inactive_project_runner
,
group_runner
])
}
end
end
context
"set to :c
reated_date
"
do
context
"set to :c
ontacted_desc
"
do
let
(
:args
)
do
let
(
:args
)
do
{
sort: :created_date
}
{
sort: :contacted_desc
}
end
it
{
is_expected
.
to
eq
([
offline_project_runner
,
instance_runner
,
inactive_project_runner
,
group_runner
].
reverse
)
}
end
context
"set to :created_at_desc"
do
let
(
:args
)
do
{
sort: :created_at_desc
}
end
end
it
{
is_expected
.
to
eq
([
instance_runner
,
group_runner
,
offline_project_runner
,
inactive_project_runner
])
}
it
{
is_expected
.
to
eq
([
instance_runner
,
group_runner
,
offline_project_runner
,
inactive_project_runner
])
}
end
end
context
"set to :created_at_asc"
do
let
(
:args
)
do
{
sort: :created_at_asc
}
end
it
{
is_expected
.
to
eq
([
instance_runner
,
group_runner
,
offline_project_runner
,
inactive_project_runner
].
reverse
)
}
end
end
end
context
'when type is filtered'
do
context
'when type is filtered'
do
...
...
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