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
Boxiang Sun
gitlab-ce
Commits
ef633d24
Commit
ef633d24
authored
Jun 13, 2017
by
Kyle Bishop
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add since and until params to issuables
parent
0037cf63
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
87 additions
and
3 deletions
+87
-3
app/finders/issuable_finder.rb
app/finders/issuable_finder.rb
+13
-0
changelogs/unreleased/12151-add-since-and-until-params-to-issuables.yml
...eleased/12151-add-since-and-until-params-to-issuables.yml
+4
-0
doc/api/issues.md
doc/api/issues.md
+2
-1
doc/api/merge_requests.md
doc/api/merge_requests.md
+2
-0
lib/api/issues.rb
lib/api/issues.rb
+2
-0
lib/api/merge_requests.rb
lib/api/merge_requests.rb
+2
-0
spec/finders/issues_finder_spec.rb
spec/finders/issues_finder_spec.rb
+20
-2
spec/finders/merge_requests_finder_spec.rb
spec/finders/merge_requests_finder_spec.rb
+42
-0
No files found.
app/finders/issuable_finder.rb
View file @
ef633d24
...
@@ -41,6 +41,7 @@ class IssuableFinder
...
@@ -41,6 +41,7 @@ class IssuableFinder
items
=
by_iids
(
items
)
items
=
by_iids
(
items
)
items
=
by_milestone
(
items
)
items
=
by_milestone
(
items
)
items
=
by_label
(
items
)
items
=
by_label
(
items
)
items
=
by_created_at
(
items
)
# Filtering by project HAS TO be the last because we use the project IDs yielded by the issuable query thus far
# Filtering by project HAS TO be the last because we use the project IDs yielded by the issuable query thus far
items
=
by_project
(
items
)
items
=
by_project
(
items
)
...
@@ -402,6 +403,18 @@ class IssuableFinder
...
@@ -402,6 +403,18 @@ class IssuableFinder
params
[
:non_archived
].
present?
?
items
.
non_archived
:
items
params
[
:non_archived
].
present?
?
items
.
non_archived
:
items
end
end
def
by_created_at
(
items
)
if
params
[
:created_after
].
present?
items
=
items
.
where
(
items
.
klass
.
arel_table
[
:created_at
].
gteq
(
params
[
:created_after
]))
end
if
params
[
:created_before
].
present?
items
=
items
.
where
(
items
.
klass
.
arel_table
[
:created_at
].
lteq
(
params
[
:created_before
]))
end
items
end
def
current_user_related?
def
current_user_related?
params
[
:scope
]
==
'created-by-me'
||
params
[
:scope
]
==
'authored'
||
params
[
:scope
]
==
'assigned-to-me'
params
[
:scope
]
==
'created-by-me'
||
params
[
:scope
]
==
'authored'
||
params
[
:scope
]
==
'assigned-to-me'
end
end
...
...
changelogs/unreleased/12151-add-since-and-until-params-to-issuables.yml
0 → 100644
View file @
ef633d24
---
title
:
Added "created_after" and "created_before" params to issuables
merge_request
:
12151
author
:
Kyle Bishop @kybishop
doc/api/issues.md
View file @
ef633d24
...
@@ -221,7 +221,8 @@ GET /projects/:id/issues?search=issue+title+or+description
...
@@ -221,7 +221,8 @@ GET /projects/:id/issues?search=issue+title+or+description
|
`order_by`
| string | no | Return requests ordered by
`created_at`
or
`updated_at`
fields. Default is
`created_at`
|
|
`order_by`
| string | no | Return requests ordered by
`created_at`
or
`updated_at`
fields. Default is
`created_at`
|
|
`sort`
| string | no | Return requests sorted in
`asc`
or
`desc`
order. Default is
`desc`
|
|
`sort`
| string | no | Return requests sorted in
`asc`
or
`desc`
order. Default is
`desc`
|
|
`search`
| string | no | Search project issues against their
`title`
and
`description`
|
|
`search`
| string | no | Search project issues against their
`title`
and
`description`
|
|
`created_after`
| datetime | no | Return issues created after the given time (inclusive) |
|
`created_before`
| datetime | no | Return issues created before the given time (inclusive) |
```
bash
```
bash
curl
--header
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v4/projects/4/issues
curl
--header
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v4/projects/4/issues
...
...
doc/api/merge_requests.md
View file @
ef633d24
...
@@ -26,6 +26,8 @@ Parameters:
...
@@ -26,6 +26,8 @@ Parameters:
|
`sort`
| string | no | Return requests sorted in
`asc`
or
`desc`
order. Default is
`desc`
|
|
`sort`
| string | no | Return requests sorted in
`asc`
or
`desc`
order. Default is
`desc`
|
|
`milestone`
| string | no | Return merge requests for a specific milestone |
|
`milestone`
| string | no | Return merge requests for a specific milestone |
|
`labels`
| string | no | Return merge requests matching a comma separated list of labels |
|
`labels`
| string | no | Return merge requests matching a comma separated list of labels |
|
`created_after`
| datetime | no | Return merge requests created after the given time (inclusive) |
|
`created_before`
| datetime | no | Return merge requests created before the given time (inclusive) |
```
json
```
json
[
[
...
...
lib/api/issues.rb
View file @
ef633d24
...
@@ -27,6 +27,8 @@ module API
...
@@ -27,6 +27,8 @@ module API
optional
:milestone
,
type:
String
,
desc:
'Return issues for a specific milestone'
optional
:milestone
,
type:
String
,
desc:
'Return issues for a specific milestone'
optional
:iids
,
type:
Array
[
Integer
],
desc:
'The IID array of issues'
optional
:iids
,
type:
Array
[
Integer
],
desc:
'The IID array of issues'
optional
:search
,
type:
String
,
desc:
'Search issues for text present in the title or description'
optional
:search
,
type:
String
,
desc:
'Search issues for text present in the title or description'
optional
:created_after
,
type:
DateTime
,
desc:
'Return issues created after the specified time'
optional
:created_before
,
type:
DateTime
,
desc:
'Return issues created before the specified time'
use
:pagination
use
:pagination
end
end
...
...
lib/api/merge_requests.rb
View file @
ef633d24
...
@@ -72,6 +72,8 @@ module API
...
@@ -72,6 +72,8 @@ module API
optional
:iids
,
type:
Array
[
Integer
],
desc:
'The IID array of merge requests'
optional
:iids
,
type:
Array
[
Integer
],
desc:
'The IID array of merge requests'
optional
:milestone
,
type:
String
,
desc:
'Return merge requests for a specific milestone'
optional
:milestone
,
type:
String
,
desc:
'Return merge requests for a specific milestone'
optional
:labels
,
type:
String
,
desc:
'Comma-separated list of label names'
optional
:labels
,
type:
String
,
desc:
'Comma-separated list of label names'
optional
:created_after
,
type:
DateTime
,
desc:
'Return merge requests created after the specified time'
optional
:created_before
,
type:
DateTime
,
desc:
'Return merge requests created before the specified time'
use
:pagination
use
:pagination
end
end
get
":id/merge_requests"
do
get
":id/merge_requests"
do
...
...
spec/finders/issues_finder_spec.rb
View file @
ef633d24
...
@@ -7,9 +7,9 @@ describe IssuesFinder do
...
@@ -7,9 +7,9 @@ describe IssuesFinder do
set
(
:project2
)
{
create
(
:empty_project
)
}
set
(
:project2
)
{
create
(
:empty_project
)
}
set
(
:milestone
)
{
create
(
:milestone
,
project:
project1
)
}
set
(
:milestone
)
{
create
(
:milestone
,
project:
project1
)
}
set
(
:label
)
{
create
(
:label
,
project:
project2
)
}
set
(
:label
)
{
create
(
:label
,
project:
project2
)
}
set
(
:issue1
)
{
create
(
:issue
,
author:
user
,
assignees:
[
user
],
project:
project1
,
milestone:
milestone
,
title:
'gitlab'
)
}
set
(
:issue1
)
{
create
(
:issue
,
author:
user
,
assignees:
[
user
],
project:
project1
,
milestone:
milestone
,
title:
'gitlab'
,
created_at:
1
.
week
.
ago
)
}
set
(
:issue2
)
{
create
(
:issue
,
author:
user
,
assignees:
[
user
],
project:
project2
,
description:
'gitlab'
)
}
set
(
:issue2
)
{
create
(
:issue
,
author:
user
,
assignees:
[
user
],
project:
project2
,
description:
'gitlab'
)
}
set
(
:issue3
)
{
create
(
:issue
,
author:
user2
,
assignees:
[
user2
],
project:
project2
,
title:
'tanuki'
,
description:
'tanuki'
)
}
set
(
:issue3
)
{
create
(
:issue
,
author:
user2
,
assignees:
[
user2
],
project:
project2
,
title:
'tanuki'
,
description:
'tanuki'
,
created_at:
1
.
week
.
from_now
)
}
describe
'#execute'
do
describe
'#execute'
do
set
(
:closed_issue
)
{
create
(
:issue
,
author:
user2
,
assignees:
[
user2
],
project:
project2
,
state:
'closed'
)
}
set
(
:closed_issue
)
{
create
(
:issue
,
author:
user2
,
assignees:
[
user2
],
project:
project2
,
state:
'closed'
)
}
...
@@ -213,6 +213,24 @@ describe IssuesFinder do
...
@@ -213,6 +213,24 @@ describe IssuesFinder do
end
end
end
end
context
'filtering by created_at'
do
context
'through created_after'
do
let
(
:params
)
{
{
created_after:
issue3
.
created_at
}
}
it
'returns issues created on or after the given date'
do
expect
(
issues
).
to
contain_exactly
(
issue3
)
end
end
context
'through created_before'
do
let
(
:params
)
{
{
created_before:
issue1
.
created_at
+
1
.
second
}
}
it
'returns issues created on or before the given date'
do
expect
(
issues
).
to
contain_exactly
(
issue1
)
end
end
end
context
'when the user is unauthorized'
do
context
'when the user is unauthorized'
do
let
(
:search_user
)
{
nil
}
let
(
:search_user
)
{
nil
}
...
...
spec/finders/merge_requests_finder_spec.rb
View file @
ef633d24
...
@@ -46,5 +46,47 @@ describe MergeRequestsFinder do
...
@@ -46,5 +46,47 @@ describe MergeRequestsFinder do
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
)
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
)
end
end
context
'with created_after and created_before params'
do
let
(
:project4
)
{
create
(
:empty_project
,
forked_from_project:
project1
)
}
let!
(
:new_merge_request
)
do
create
(
:merge_request
,
:simple
,
author:
user
,
created_at:
1
.
week
.
from_now
,
source_project:
project4
,
target_project:
project1
)
end
let!
(
:old_merge_request
)
do
create
(
:merge_request
,
:simple
,
author:
user
,
created_at:
1
.
week
.
ago
,
source_project:
project4
,
target_project:
project4
)
end
before
do
project4
.
add_master
(
user
)
end
it
'filters by created_after'
do
params
=
{
project_id:
project1
.
id
,
created_after:
new_merge_request
.
created_at
}
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
expect
(
merge_requests
).
to
contain_exactly
(
new_merge_request
)
end
it
'filters by created_before'
do
params
=
{
project_id:
project4
.
id
,
created_before:
old_merge_request
.
created_at
+
1
.
second
}
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
expect
(
merge_requests
).
to
contain_exactly
(
old_merge_request
)
end
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