Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
ed8975cd2a2f
Commit
ed8975cd
authored
Aug 14, 2014
by
jubianchi
Browse files
Filters issues by labels via API
parent
7ec100a4df8e
Changes
5
Hide whitespace changes
Inline
Side-by-side
CHANGELOG
View file @
ed8975cd
...
...
@@ -12,6 +12,7 @@
- Deprecate LDAP account takeover based on partial LDAP email / GitLab username match
- Keyboard shortcuts for productivity (Robert Schilling)
- API: filter issues by state (Julien Bianchi)
- API: filter issues by labels (Julien Bianchi)
- Add system hook for ssh key changes
v 7.2.0
...
...
app/models/project.rb
View file @
ed8975cd
...
...
@@ -70,7 +70,7 @@
has_many
:merge_requests
,
dependent: :destroy
,
foreign_key:
"target_project_id"
# Merge requests from source project should be kept when source project was removed
has_many
:fork_merge_requests
,
foreign_key:
"source_project_id"
,
class_name:
MergeRequest
has_many
:issues
,
->
{
order
"
state DESC, created_at DESC
"
},
dependent: :destroy
has_many
:issues
,
->
{
order
'issues.
state DESC,
issues.
created_at DESC
'
},
dependent: :destroy
has_many
:labels
,
dependent: :destroy
has_many
:services
,
dependent: :destroy
has_many
:events
,
dependent: :destroy
...
...
doc/api/issues.md
View file @
ed8975cd
...
...
@@ -9,8 +9,11 @@
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
```
Parameters:
-
`state`
(optional) - Return
`all`
issues or just those that are
`opened`
or
`closed`
...
...
@@ -12,8 +15,9 @@
```
Parameters:
-
`state`
(optional) - Return
`all`
issues or just those that are
`opened`
or
`closed`
-
`labels`
(optional) - Comma-separated list of label names
```
json
[
...
...
@@ -88,9 +92,12 @@
GET /projects/:id/issues
GET /projects/:id/issues?state=opened
GET /projects/:id/issues?state=closed
GET /projects/:id/issues?labels=foo
GET /projects/:id/issues?labels=foo,bar
GET /projects/:id/issues?labels=foo,bar&state=opened
```
Parameters:
-
`id`
(required) - The ID of a project
-
`state`
(optional) - Return
`all`
issues or just those that are
`opened`
or
`closed`
...
...
@@ -91,9 +98,10 @@
```
Parameters:
-
`id`
(required) - The ID of a project
-
`state`
(optional) - Return
`all`
issues or just those that are
`opened`
or
`closed`
-
`labels`
(optional) - Comma-separated list of label names
## Single issue
...
...
lib/api/issues.rb
View file @
ed8975cd
...
...
@@ -11,6 +11,10 @@
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,8 +22,9 @@
#
# 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
...
...
@@ -22,5 +27,8 @@
# 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
...
...
@@ -26,5 +34,9 @@
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,8 +46,9 @@
# 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
...
...
@@ -37,6 +50,10 @@
#
# 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
...
...
@@ -42,5 +59,9 @@
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
...
...
spec/requests/api/issues_spec.rb
View file @
ed8975cd
...
...
@@ -9,6 +9,7 @@
let!
(
:label
)
do
create
(
:label
,
title:
'label'
,
color:
'#FFAABB'
,
project:
project
)
end
let!
(
:label_link
)
{
create
(
:label_link
,
label:
label
,
target:
issue
)
}
before
{
project
.
team
<<
[
user
,
:reporter
]
}
...
...
@@ -58,6 +59,45 @@
json_response
.
first
[
'id'
].
should
==
issue
.
id
json_response
.
second
[
'id'
].
should
==
closed_issue
.
id
end
it
'should return an array of labeled issues'
do
get
api
(
"/issues?labels=
#{
label
.
title
}
"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
1
json_response
.
first
[
'labels'
].
should
==
[
label
.
title
]
end
it
'should return an array of labeled issues when at least one label matches'
do
get
api
(
"/issues?labels=
#{
label
.
title
}
,foo,bar"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
1
json_response
.
first
[
'labels'
].
should
==
[
label
.
title
]
end
it
'should return an empty array if no issue matches labels'
do
get
api
(
'/issues?labels=foo,bar'
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
0
end
it
'should return an array of labeled issues matching given state'
do
get
api
(
"/issues?labels=
#{
label
.
title
}
&state=opened"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
1
json_response
.
first
[
'labels'
].
should
==
[
label
.
title
]
json_response
.
first
[
'state'
].
should
==
'opened'
end
it
'should return an empty array if no issue matches labels and state filters'
do
get
api
(
"/issues?labels=
#{
label
.
title
}
&state=closed"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
0
end
end
end
...
...
@@ -68,6 +108,29 @@
json_response
.
should
be_an
Array
json_response
.
first
[
'title'
].
should
==
issue
.
title
end
it
'should return an array of labeled project issues'
do
get
api
(
"/projects/
#{
project
.
id
}
/issues?labels=
#{
label
.
title
}
"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
1
json_response
.
first
[
'labels'
].
should
==
[
label
.
title
]
end
it
'should return an array of labeled project issues when at least one label matches'
do
get
api
(
"/projects/
#{
project
.
id
}
/issues?labels=
#{
label
.
title
}
,foo,bar"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
1
json_response
.
first
[
'labels'
].
should
==
[
label
.
title
]
end
it
'should return an empty array if no project issue matches labels'
do
get
api
(
"/projects/
#{
project
.
id
}
/issues?labels=foo,bar"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
==
0
end
end
describe
"GET /projects/:id/issues/:issue_id"
do
...
...
@@ -182,7 +245,7 @@
labels:
'label2'
,
state_event:
"close"
response
.
status
.
should
==
200
json_response
[
'labels'
].
should
==
[
'label2'
]
json_response
[
'labels'
].
should
include
'label2'
json_response
[
'state'
].
should
eq
"closed"
end
end
...
...
Write
Preview
Supports
Markdown
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