Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
260fd212
Commit
260fd212
authored
Sep 04, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce
parents
9bb1d8fc
0bcc3239
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
98 additions
and
5 deletions
+98
-5
CHANGELOG
CHANGELOG
+1
-0
app/models/project.rb
app/models/project.rb
+1
-1
doc/api/issues.md
doc/api/issues.md
+8
-0
lib/api/issues.rb
lib/api/issues.rb
+24
-3
spec/requests/api/issues_spec.rb
spec/requests/api/issues_spec.rb
+64
-1
No files found.
CHANGELOG
View file @
260fd212
...
@@ -12,6 +12,7 @@ v 7.3.0
...
@@ -12,6 +12,7 @@ v 7.3.0
- Deprecate LDAP account takeover based on partial LDAP email / GitLab username match
- Deprecate LDAP account takeover based on partial LDAP email / GitLab username match
- Keyboard shortcuts for productivity (Robert Schilling)
- Keyboard shortcuts for productivity (Robert Schilling)
- API: filter issues by state (Julien Bianchi)
- API: filter issues by state (Julien Bianchi)
- API: filter issues by labels (Julien Bianchi)
- Add system hook for ssh key changes
- Add system hook for ssh key changes
- Add blob permalink link (Ciro Santilli)
- Add blob permalink link (Ciro Santilli)
...
...
app/models/project.rb
View file @
260fd212
...
@@ -70,7 +70,7 @@ class Project < ActiveRecord::Base
...
@@ -70,7 +70,7 @@ class Project < ActiveRecord::Base
has_many
:merge_requests
,
dependent: :destroy
,
foreign_key:
"target_project_id"
has_many
:merge_requests
,
dependent: :destroy
,
foreign_key:
"target_project_id"
# Merge requests from source project should be kept when source project was removed
# 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
: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
:labels
,
dependent: :destroy
has_many
:services
,
dependent: :destroy
has_many
:services
,
dependent: :destroy
has_many
:events
,
dependent: :destroy
has_many
:events
,
dependent: :destroy
...
...
doc/api/issues.md
View file @
260fd212
...
@@ -9,11 +9,15 @@ Get all issues created by authenticated user. This function takes pagination par
...
@@ -9,11 +9,15 @@ Get all issues created by authenticated user. This function takes pagination par
GET /issues
GET /issues
GET /issues?state=opened
GET /issues?state=opened
GET /issues?state=closed
GET /issues?state=closed
GET /issues?labels=foo
GET /issues?labels=foo,bar
GET /issues?labels=foo,bar&state=opened
```
```
Parameters:
Parameters:
-
`state`
(optional) - Return
`all`
issues or just those that are
`opened`
or
`closed`
-
`state`
(optional) - Return
`all`
issues or just those that are
`opened`
or
`closed`
-
`labels`
(optional) - Comma-separated list of label names
```
json
```
json
[
[
...
@@ -88,12 +92,16 @@ to return the list of project issues.
...
@@ -88,12 +92,16 @@ to return the list of project issues.
GET /projects/:id/issues
GET /projects/:id/issues
GET /projects/:id/issues?state=opened
GET /projects/:id/issues?state=opened
GET /projects/:id/issues?state=closed
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:
Parameters:
-
`id`
(required) - The ID of a project
-
`id`
(required) - The ID of a project
-
`state`
(optional) - Return
`all`
issues or just those that are
`opened`
or
`closed`
-
`state`
(optional) - Return
`all`
issues or just those that are
`opened`
or
`closed`
-
`labels`
(optional) - Comma-separated list of label names
## Single issue
## Single issue
...
...
lib/api/issues.rb
View file @
260fd212
...
@@ -11,6 +11,10 @@ module API
...
@@ -11,6 +11,10 @@ module API
else
issues
.
order
(
'id DESC'
)
else
issues
.
order
(
'id DESC'
)
end
end
end
end
def
filter_issues_labels
(
issues
,
labels
)
issues
.
includes
(
:labels
).
where
(
"labels.title"
=>
labels
.
split
(
','
))
end
end
end
resource
:issues
do
resource
:issues
do
...
@@ -18,13 +22,21 @@ module API
...
@@ -18,13 +22,21 @@ module API
#
#
# Parameters:
# Parameters:
# state (optional) - Return "opened" or "closed" issues
# state (optional) - Return "opened" or "closed" issues
#
# labels (optional) - Comma-separated list of label names
# Example Requests:
# Example Requests:
# GET /issues
# GET /issues
# GET /issues?state=opened
# GET /issues?state=opened
# GET /issues?state=closed
# GET /issues?state=closed
# GET /issues?labels=foo
# GET /issues?labels=foo,bar
# GET /issues?labels=foo,bar&state=opened
get
do
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
end
end
...
@@ -34,13 +46,22 @@ module API
...
@@ -34,13 +46,22 @@ module API
# Parameters:
# Parameters:
# id (required) - The ID of a project
# id (required) - The ID of a project
# state (optional) - Return "opened" or "closed" issues
# state (optional) - Return "opened" or "closed" issues
# labels (optional) - Comma-separated list of label names
#
#
# Example Requests:
# Example Requests:
# GET /projects/:id/issues
# GET /projects/:id/issues
# GET /projects/:id/issues?state=opened
# GET /projects/:id/issues?state=opened
# GET /projects/:id/issues?state=closed
# 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
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
end
# Get a single project issue
# Get a single project issue
...
...
spec/requests/api/issues_spec.rb
View file @
260fd212
...
@@ -9,6 +9,7 @@ describe API::API, api: true do
...
@@ -9,6 +9,7 @@ describe API::API, api: true do
let!
(
:label
)
do
let!
(
:label
)
do
create
(
:label
,
title:
'label'
,
color:
'#FFAABB'
,
project:
project
)
create
(
:label
,
title:
'label'
,
color:
'#FFAABB'
,
project:
project
)
end
end
let!
(
:label_link
)
{
create
(
:label_link
,
label:
label
,
target:
issue
)
}
before
{
project
.
team
<<
[
user
,
:reporter
]
}
before
{
project
.
team
<<
[
user
,
:reporter
]
}
...
@@ -58,6 +59,45 @@ describe API::API, api: true do
...
@@ -58,6 +59,45 @@ describe API::API, api: true do
json_response
.
first
[
'id'
].
should
==
issue
.
id
json_response
.
first
[
'id'
].
should
==
issue
.
id
json_response
.
second
[
'id'
].
should
==
closed_issue
.
id
json_response
.
second
[
'id'
].
should
==
closed_issue
.
id
end
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
end
end
...
@@ -68,6 +108,29 @@ describe API::API, api: true do
...
@@ -68,6 +108,29 @@ describe API::API, api: true do
json_response
.
should
be_an
Array
json_response
.
should
be_an
Array
json_response
.
first
[
'title'
].
should
==
issue
.
title
json_response
.
first
[
'title'
].
should
==
issue
.
title
end
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
end
describe
"GET /projects/:id/issues/:issue_id"
do
describe
"GET /projects/:id/issues/:issue_id"
do
...
@@ -182,7 +245,7 @@ describe API::API, api: true do
...
@@ -182,7 +245,7 @@ describe API::API, api: true do
labels:
'label2'
,
state_event:
"close"
labels:
'label2'
,
state_event:
"close"
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
[
'labels'
].
should
==
[
'label2'
]
json_response
[
'labels'
].
should
include
'label2'
json_response
[
'state'
].
should
eq
"closed"
json_response
[
'state'
].
should
eq
"closed"
end
end
end
end
...
...
Write
Preview
Markdown
is supported
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