diff options
author | David Eisner <david.eisner@oriel.oxon.org> | 2016-10-26 09:08:58 +0100 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-01-12 17:51:06 -0500 |
commit | 7ef1c6408e95c780e947e5c56cfae10b3dbb03d4 (patch) | |
tree | 6603a9e457e6ef35e3fd0554789823242d519a38 /lib | |
parent | 5c253116ae57c9db567394f544a40997de115f82 (diff) | |
download | gitlab-ce-7ef1c6408e95c780e947e5c56cfae10b3dbb03d4.tar.gz |
API: Implement project issues iid param with IssuesFinder and add tests23194-fix-no-milestone-option-for-projects-endpoint
- Use IssuesFinder for the /issues API resouce
- Tests for iid filter in project issues API resource
- Tests for No Milestone filter in issues API resources
The "No Milestone" case was not previously tested, and the `/issues`
resource did not support the the `milestone` parameter.
- Return issues where all labels match from the issues and project issues
API resources, like the group issues resource already does. See
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6825#note_17474533
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/issues.rb | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/lib/api/issues.rb b/lib/api/issues.rb index dc55bb10636..161269cbd41 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -5,13 +5,31 @@ module API before { authenticate! } helpers do - # TODO: Remove in 9.0 and switch to IssueFinder-based label filtering - def filter_issues_labels(issues, labels) - issues.includes(:labels).where('labels.title' => labels.split(',')) + def find_issues(args = {}) + args = params.merge(args) + + args.delete(:id) + args[:milestone_title] = args.delete(:milestone) + + match_all_labels = args.delete(:match_all_labels) + labels = args.delete(:labels) + args[:label_name] = labels if match_all_labels + + args[:search] = "#{Issue.reference_prefix}#{args.delete(:iid)}" if args.key?(:iid) + + issues = IssuesFinder.new(current_user, args).execute.inc_notes_with_associations + + # TODO: Remove in 9.0 pass `label_name: args.delete(:labels)` to IssuesFinder + if !match_all_labels && labels.present? + issues = issues.includes(:labels).where('labels.title' => labels.split(',')) + end + + issues.reorder(args[:order_by] => args[:sort]) end params :issues_params do optional :labels, type: String, desc: 'Comma-separated list of label names' + optional :milestone, type: String, desc: 'Milestone title' optional :order_by, type: String, values: %w[created_at updated_at], default: 'created_at', desc: 'Return issues ordered by `created_at` or `updated_at` fields.' optional :sort, type: String, values: %w[asc desc], default: 'desc', @@ -40,9 +58,7 @@ module API use :issues_params end get do - issues = IssuesFinder.new(current_user, scope: 'all', author_id: current_user.id, state: params[:state]).execute.inc_notes_with_associations - issues = filter_issues_labels(issues, params[:labels]) unless params[:labels].nil? - issues = issues.reorder(params[:order_by] => params[:sort]) + issues = find_issues(scope: 'authored') present paginate(issues), with: Entities::Issue, current_user: current_user end @@ -61,15 +77,10 @@ module API use :issues_params end get ":id/issues" do - group = find_group!(params.delete(:id)) + group = find_group!(params[:id]) - params[:group_id] = group.id - params[:milestone_title] = params.delete(:milestone) - params[:label_name] = params.delete(:labels) + issues = find_issues(group_id: group.id, state: params[:state] || 'opened', match_all_labels: true) - issues = IssuesFinder.new(current_user, params).execute - - issues = issues.reorder(params[:order_by] => params[:sort]) present paginate(issues), with: Entities::Issue, current_user: current_user end end @@ -84,19 +95,13 @@ module API params do optional :state, type: String, values: %w[opened closed all], default: 'all', desc: 'Return opened, closed, or all issues' - optional :iid, type: Integer, desc: 'The IID of the issue' + optional :iid, type: Integer, desc: 'Return the issue having the given `iid`' use :issues_params end get ":id/issues" do project = find_project(params[:id]) - params[:state] ||= 'opened' - params[:project_id] = project.id - params[:milestone_title] = params.delete(:milestone) - params[:label_name] = params.delete(:labels) - - issues = IssuesFinder.new(current_user, params).execute - issues = issues.reorder(params[:order_by] => params[:sort]) + issues = find_issues(project_id: project.id) present paginate(issues), with: Entities::Issue, current_user: current_user, project: user_project end |