summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-03-02 10:18:02 +0000
committerRémy Coutable <remy@rymai.me>2017-03-02 10:18:02 +0000
commit034c64968224caafaa3aec904359bf82cce36f7a (patch)
treec71e679bc09d443e48e87cec80cd5740082aadd2 /lib
parentd4154195329b0a823848df8ceae144aebd6ccf6b (diff)
parent61baf3528d2f39ffc8f7aa07eddf3df0cec3508b (diff)
downloadgitlab-ce-034c64968224caafaa3aec904359bf82cce36f7a.tar.gz
Merge branch '28807-search-for-milestone-by-title-in-rest-api' into 'master'
Enable filtering milestones by search criteria in the API Closes #28807 See merge request !9606
Diffstat (limited to 'lib')
-rw-r--r--lib/api/helpers.rb4
-rw-r--r--lib/api/milestones.rb2
2 files changed, 6 insertions, 0 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 72d2b320077..4600abc7dc7 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -164,6 +164,10 @@ module API
items.where(iid: iid)
end
+ def filter_by_search(items, text)
+ items.search(text)
+ end
+
# error helpers
def forbidden!(reason = nil)
diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb
index 0b4ed76b35c..44bdaea7fa4 100644
--- a/lib/api/milestones.rb
+++ b/lib/api/milestones.rb
@@ -31,6 +31,7 @@ module API
optional :state, type: String, values: %w[active closed all], default: 'all',
desc: 'Return "active", "closed", or "all" milestones'
optional :iid, type: Array[Integer], desc: 'The IID of the milestone'
+ optional :search, type: String, desc: 'The search criteria for the title or description of the milestone'
use :pagination
end
get ":id/milestones" do
@@ -39,6 +40,7 @@ module API
milestones = user_project.milestones
milestones = filter_milestones_state(milestones, params[:state])
milestones = filter_by_iid(milestones, params[:iid]) if params[:iid].present?
+ milestones = filter_by_search(milestones, params[:search]) if params[:search]
present paginate(milestones), with: Entities::Milestone
end