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
01eab583
Commit
01eab583
authored
Nov 27, 2012
by
Nihad Abbasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API: list wall, snippet and issue notes
parent
aaa1c942
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
1 deletion
+94
-1
lib/api.rb
lib/api.rb
+1
-0
lib/api/entities.rb
lib/api/entities.rb
+3
-1
lib/api/notes.rb
lib/api/notes.rb
+38
-0
spec/requests/api/notes_spec.rb
spec/requests/api/notes_spec.rb
+52
-0
No files found.
lib/api.rb
View file @
01eab583
...
...
@@ -19,5 +19,6 @@ module Gitlab
mount
Milestones
mount
Session
mount
MergeRequests
mount
Notes
end
end
lib/api/entities.rb
View file @
01eab583
...
...
@@ -70,8 +70,10 @@ module Gitlab
end
class
Note
<
Grape
::
Entity
expose
:id
expose
:note
,
as: :body
expose
:author
,
using:
Entities
::
UserBasic
expose
:
note
expose
:
updated_at
,
:created_at
end
end
end
lib/api/notes.rb
0 → 100644
View file @
01eab583
module
Gitlab
# Notes API
class
Notes
<
Grape
::
API
before
{
authenticate!
}
NOTEABLE_TYPES
=
[
Issue
,
Snippet
]
resource
:projects
do
# Get a list of project wall notes
#
# Parameters:
# id (required) - The ID or code name of a project
# Example Request:
# GET /projects/:id/notes
get
":id/notes"
do
@notes
=
user_project
.
common_notes
present
paginate
(
@notes
),
with:
Entities
::
Note
end
NOTEABLE_TYPES
.
each
do
|
noteable_type
|
noteables_str
=
noteable_type
.
to_s
.
underscore
.
pluralize
noteable_id_str
=
"
#{
noteable_type
.
to_s
.
underscore
}
_id"
# Get a list of project +noteable+ notes
#
# Parameters:
# id (required) - The ID or code name of a project
# noteable_id (required) - The ID of an issue or snippet
# Example Request:
# GET /projects/:id/noteable/:noteable_id/notes
get
":id/
#{
noteables_str
}
/:
#{
noteable_id_str
}
/notes"
do
@noteable
=
user_project
.
send
(
:"
#{
noteables_str
}
"
).
find
(
params
[
:"
#{
noteable_id_str
}
"
])
present
paginate
(
@noteable
.
notes
),
with:
Entities
::
Note
end
end
end
end
end
spec/requests/api/notes_spec.rb
0 → 100644
View file @
01eab583
require
'spec_helper'
describe
Gitlab
::
API
do
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
owner:
user
)
}
let!
(
:issue
)
{
create
(
:issue
,
project:
project
,
author:
user
)
}
let!
(
:snippet
)
{
create
(
:snippet
,
project:
project
,
author:
user
)
}
let!
(
:issue_note
)
{
create
(
:note
,
noteable:
issue
,
project:
project
,
author:
user
)
}
let!
(
:snippet_note
)
{
create
(
:note
,
noteable:
snippet
,
project:
project
,
author:
user
)
}
let!
(
:wall_note
)
{
create
(
:note
,
project:
project
,
author:
user
)
}
before
{
project
.
add_access
(
user
,
:read
)
}
describe
"GET /projects/:id/notes"
do
context
"when unauthenticated"
do
it
"should return authentication error"
do
get
api
(
"/projects/
#{
project
.
id
}
/notes"
)
response
.
status
.
should
==
401
end
end
context
"when authenticated"
do
it
"should return project wall notes"
do
get
api
(
"/projects/
#{
project
.
id
}
/notes"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
first
[
'body'
].
should
==
wall_note
.
note
end
end
end
describe
"GET /projects/:id/noteable/:noteable_id/notes"
do
context
"when noteable is an Issue"
do
it
"should return an array of notes"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
first
[
'body'
].
should
==
issue_note
.
note
end
end
context
"when noteable is a Snippet"
do
it
"should return an array of notes"
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/notes"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
first
[
'body'
].
should
==
snippet_note
.
note
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