diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-04 12:54:08 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-04 12:54:08 +0000 |
commit | 0bcc323928fa3a794aea5ce190319ebea89ca1ad (patch) | |
tree | 1c5c8fd06db82989469535d5d389788c292b4d8e /lib/api | |
parent | 18e4e997644aa0772153938106e4fc798a12e10f (diff) | |
parent | 0ac4a933ffae00adc4b7ab58af9bef15ed8c412b (diff) | |
download | gitlab-ce-0bcc323928fa3a794aea5ce190319ebea89ca1ad.tar.gz |
Merge branch 'api/issues-filter-labels' into 'master'
API: Filter issues by labels
While working on [laboard](https://gitlab.com/jubianchi/laboard) I had some issues with the API : I was not able to filter issues by labels so I had to write some logic to do it on my side.
I think it will be useful to have this feature supported by the Gitlab API.
I added the filtering logic on `/issues` and `/projects/:id/issues`.
The commits are not squashed but I'll do it once everything seems ok to you.
See merge request !169
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/issues.rb | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 15a49b452bd..e4a66eceadd 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -11,6 +11,10 @@ module API else issues.order('id DESC') end end + + def filter_issues_labels(issues, labels) + issues.includes(:labels).where("labels.title" => labels.split(',')) + end end resource :issues do @@ -18,13 +22,21 @@ module API # # Parameters: # state (optional) - Return "opened" or "closed" issues - # + # labels (optional) - Comma-separated list of label names + # Example Requests: # GET /issues # GET /issues?state=opened # GET /issues?state=closed + # GET /issues?labels=foo + # GET /issues?labels=foo,bar + # GET /issues?labels=foo,bar&state=opened get do - present paginate(filter_issues_state(current_user.issues, params['state'])), with: Entities::Issue + issues = current_user.issues + issues = filter_issues_state(issues, params[:state]) unless params[:state].nil? + issues = filter_issues_labels(issues, params[:labels]) unless params[:labels].nil? + + present paginate(issues), with: Entities::Issue end end @@ -34,13 +46,22 @@ module API # Parameters: # id (required) - The ID of a project # state (optional) - Return "opened" or "closed" issues + # labels (optional) - Comma-separated list of label names # # Example Requests: # GET /projects/:id/issues # GET /projects/:id/issues?state=opened # GET /projects/:id/issues?state=closed + # GET /projects/:id/issues + # GET /projects/:id/issues?labels=foo + # GET /projects/:id/issues?labels=foo,bar + # GET /projects/:id/issues?labels=foo,bar&state=opened get ":id/issues" do - present paginate(filter_issues_state(user_project.issues, params['state'])), with: Entities::Issue + issues = user_project.issues + issues = filter_issues_state(issues, params[:state]) unless params[:state].nil? + issues = filter_issues_labels(issues, params[:labels]) unless params[:labels].nil? + + present paginate(issues), with: Entities::Issue end # Get a single project issue |