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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
a9cf84e5
Commit
a9cf84e5
authored
Dec 29, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7675 from yglukhov/patch_notes_api
Implemented notes (body) patching in API.
parents
159ba9b9
1fbc0102
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
158 additions
and
1 deletion
+158
-1
app/services/notes/update_service.rb
app/services/notes/update_service.rb
+25
-0
doc/api/notes.md
doc/api/notes.md
+46
-1
lib/api/notes.rb
lib/api/notes.rb
+33
-0
spec/requests/api/notes_spec.rb
spec/requests/api/notes_spec.rb
+54
-0
No files found.
app/services/notes/update_service.rb
0 → 100644
View file @
a9cf84e5
module
Notes
class
UpdateService
<
BaseService
def
execute
note
=
project
.
notes
.
find
(
params
[
:note_id
])
note
.
note
=
params
[
:note
]
if
note
.
save
notification_service
.
new_note
(
note
)
# Skip system notes, like status changes and cross-references.
unless
note
.
system
event_service
.
leave_note
(
note
,
note
.
author
)
# Create a cross-reference note if this Note contains GFM that
# names an issue, merge request, or commit.
note
.
references
.
each
do
|
mentioned
|
Note
.
create_cross_reference_note
(
mentioned
,
note
.
noteable
,
note
.
author
,
note
.
project
)
end
end
end
note
end
end
end
doc/api/notes.md
View file @
a9cf84e5
...
@@ -78,6 +78,21 @@ Parameters:
...
@@ -78,6 +78,21 @@ Parameters:
-
`issue_id`
(required) - The ID of an issue
-
`issue_id`
(required) - The ID of an issue
-
`body`
(required) - The content of a note
-
`body`
(required) - The content of a note
### Modify existing issue note
Modify existing note of an issue.
```
PUT /projects/:id/issues/:issue_id/notes/:note_id
```
Parameters:
-
`id`
(required) - The ID of a project
-
`issue_id`
(required) - The ID of an issue
-
`note_id`
(required) - The ID of a note
-
`body`
(required) - The content of a note
## Snippets
## Snippets
### List all snippet notes
### List all snippet notes
...
@@ -137,7 +152,22 @@ POST /projects/:id/snippets/:snippet_id/notes
...
@@ -137,7 +152,22 @@ POST /projects/:id/snippets/:snippet_id/notes
Parameters:
Parameters:
-
`id`
(required) - The ID of a project
-
`id`
(required) - The ID of a project
-
`snippet_id`
(required) - The ID of an snippet
-
`snippet_id`
(required) - The ID of a snippet
-
`body`
(required) - The content of a note
### Modify existing snippet note
Modify existing note of a snippet.
```
PUT /projects/:id/snippets/:snippet_id/notes/:note_id
```
Parameters:
-
`id`
(required) - The ID of a project
-
`snippet_id`
(required) - The ID of a snippet
-
`note_id`
(required) - The ID of a note
-
`body`
(required) - The content of a note
-
`body`
(required) - The content of a note
## Merge Requests
## Merge Requests
...
@@ -199,3 +229,18 @@ Parameters:
...
@@ -199,3 +229,18 @@ Parameters:
-
`id`
(required) - The ID of a project
-
`id`
(required) - The ID of a project
-
`merge_request_id`
(required) - The ID of a merge request
-
`merge_request_id`
(required) - The ID of a merge request
-
`body`
(required) - The content of a note
-
`body`
(required) - The content of a note
### Modify existing merge request note
Modify existing note of a merge request.
```
PUT /projects/:id/merge_requests/:merge_request_id/notes/:note_id
```
Parameters:
-
`id`
(required) - The ID of a project
-
`merge_request_id`
(required) - The ID of a merge request
-
`note_id`
(required) - The ID of a note
-
`body`
(required) - The content of a note
lib/api/notes.rb
View file @
a9cf84e5
...
@@ -64,6 +64,39 @@ module API
...
@@ -64,6 +64,39 @@ module API
not_found!
not_found!
end
end
end
end
# Modify existing +noteable+ note
#
# Parameters:
# id (required) - The ID of a project
# noteable_id (required) - The ID of an issue or snippet
# node_id (required) - The ID of a note
# body (required) - New content of a note
# Example Request:
# PUT /projects/:id/issues/:noteable_id/notes/:note_id
# PUT /projects/:id/snippets/:noteable_id/notes/:node_id
put
":id/
#{
noteables_str
}
/:
#{
noteable_id_str
}
/notes/:note_id"
do
required_attributes!
[
:body
]
authorize!
:admin_note
,
user_project
.
notes
.
find
(
params
[
:note_id
])
opts
=
{
note:
params
[
:body
],
note_id:
params
[
:note_id
],
noteable_type:
noteables_str
.
classify
,
noteable_id:
params
[
noteable_id_str
]
}
@note
=
::
Notes
::
UpdateService
.
new
(
user_project
,
current_user
,
opts
).
execute
if
@note
.
valid?
present
@note
,
with:
Entities
::
Note
else
bad_request!
(
'Invalid note'
)
end
end
end
end
end
end
end
end
...
...
spec/requests/api/notes_spec.rb
View file @
a9cf84e5
...
@@ -131,4 +131,58 @@ describe API::API, api: true do
...
@@ -131,4 +131,58 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes"
,
user
),
body:
'hi!'
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes"
,
user
),
body:
'hi!'
end
end
end
end
describe
'PUT /projects/:id/noteable/:noteable_id/notes/:note_id'
do
context
'when noteable is an Issue'
do
it
'should return modified note'
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/"
\
"notes/
#{
issue_note
.
id
}
"
,
user
),
body:
'Hello!'
response
.
status
.
should
==
200
json_response
[
'body'
].
should
==
'Hello!'
end
it
'should return a 404 error when note id not found'
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes/123"
,
user
),
body:
'Hello!'
response
.
status
.
should
==
404
end
it
'should return a 400 bad request error if body not given'
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/"
\
"notes/
#{
issue_note
.
id
}
"
,
user
)
response
.
status
.
should
==
400
end
end
context
'when noteable is a Snippet'
do
it
'should return modified note'
do
put
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
\
"notes/
#{
snippet_note
.
id
}
"
,
user
),
body:
'Hello!'
response
.
status
.
should
==
200
json_response
[
'body'
].
should
==
'Hello!'
end
it
'should return a 404 error when note id not found'
do
put
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
\
"notes/123"
,
user
),
body:
"Hello!"
response
.
status
.
should
==
404
end
end
context
'when noteable is a Merge Request'
do
it
'should return modified note'
do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/"
\
"notes/
#{
merge_request_note
.
id
}
"
,
user
),
body:
'Hello!'
response
.
status
.
should
==
200
json_response
[
'body'
].
should
==
'Hello!'
end
it
'should return a 404 error when note id not found'
do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/"
\
"notes/123"
,
user
),
body:
"Hello!"
response
.
status
.
should
==
404
end
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