Merge branch 'add-since-and-until-params-to-issuables' into 'master'
add created_after and created_before params to issuables Closes #32901 See merge request !12151
This commit is contained in:
commit
9fe6c2b2c2
8 changed files with 87 additions and 3 deletions
|
@ -41,6 +41,7 @@ class IssuableFinder
|
|||
items = by_iids(items)
|
||||
items = by_milestone(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
|
||||
items = by_project(items)
|
||||
|
@ -402,6 +403,18 @@ class IssuableFinder
|
|||
params[:non_archived].present? ? items.non_archived : items
|
||||
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?
|
||||
params[:scope] == 'created-by-me' || params[:scope] == 'authored' || params[:scope] == 'assigned-to-me'
|
||||
end
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Added "created_after" and "created_before" params to issuables
|
||||
merge_request: 12151
|
||||
author: Kyle Bishop @kybishop
|
|
@ -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` |
|
||||
| `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` |
|
||||
|
||||
| `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
|
||||
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/4/issues
|
||||
|
|
|
@ -26,6 +26,8 @@ Parameters:
|
|||
| `sort` | string | no | Return requests sorted in `asc` or `desc` order. Default is `desc` |
|
||||
| `milestone` | string | no | Return merge requests for a specific milestone |
|
||||
| `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
|
||||
[
|
||||
|
|
|
@ -27,6 +27,8 @@ module API
|
|||
optional :milestone, type: String, desc: 'Return issues for a specific milestone'
|
||||
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 :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
|
||||
end
|
||||
|
||||
|
|
|
@ -72,6 +72,8 @@ module API
|
|||
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 :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
|
||||
end
|
||||
get ":id/merge_requests" do
|
||||
|
|
|
@ -7,9 +7,9 @@ describe IssuesFinder do
|
|||
set(:project2) { create(:empty_project) }
|
||||
set(:milestone) { create(:milestone, project: project1) }
|
||||
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(: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
|
||||
set(:closed_issue) { create(:issue, author: user2, assignees: [user2], project: project2, state: 'closed') }
|
||||
|
@ -215,6 +215,24 @@ describe IssuesFinder do
|
|||
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
|
||||
let(:search_user) { nil }
|
||||
|
||||
|
|
|
@ -46,5 +46,47 @@ describe MergeRequestsFinder do
|
|||
|
||||
expect(merge_requests).to contain_exactly(merge_request1)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue