Commit ee6187bd554f6f257600a67f65f8af95cf9afa9a
1 parent
2a98a060
Exists in
master
and in
4 other branches
API: ability to create a wall note
Showing
4 changed files
with
45 additions
and
3 deletions
Show diff stats
CHANGELOG
1 | 1 | v 3.2.0 |
2 | - - [API] create notes for snippets and issues | |
3 | - - [API] list notes for snippets and issues | |
4 | - - [API] list project wall notes | |
2 | + - [API] list, create issue notes | |
3 | + - [API] list, create snippet notes | |
4 | + - [API] list, create wall notes | |
5 | 5 | - Remove project code - use path instead |
6 | 6 | - added username field to user |
7 | 7 | - rake task to fill usernames based on emails create namespaces for users | ... | ... |
doc/api/notes.md
... | ... | @@ -87,6 +87,22 @@ Parameters: |
87 | 87 | |
88 | 88 | ## New note |
89 | 89 | |
90 | +### New wall note | |
91 | + | |
92 | +Create a new wall note. | |
93 | + | |
94 | +``` | |
95 | +POST /projects/:id/notes | |
96 | +``` | |
97 | + | |
98 | +Parameters: | |
99 | + | |
100 | ++ `id` (required) - The ID or code name of a project | |
101 | ++ `body` (required) - The content of a note | |
102 | + | |
103 | +Will return created note with status `201 Created` on success, or `404 Not found` on fail. | |
104 | + | |
105 | + | |
90 | 106 | ### New issue note |
91 | 107 | |
92 | 108 | Create a new issue note. | ... | ... |
lib/api/notes.rb
... | ... | @@ -17,6 +17,24 @@ module Gitlab |
17 | 17 | present paginate(@notes), with: Entities::Note |
18 | 18 | end |
19 | 19 | |
20 | + # Create a new project wall note | |
21 | + # | |
22 | + # Parameters: | |
23 | + # id (required) - The ID or code name of a project | |
24 | + # body (required) - The content of a note | |
25 | + # Example Request: | |
26 | + # POST /projects/:id/notes | |
27 | + post ":id/notes" do | |
28 | + @note = user_project.notes.new(note: params[:body]) | |
29 | + @note.author = current_user | |
30 | + | |
31 | + if @note.save | |
32 | + present @note, with: Entities::Note | |
33 | + else | |
34 | + not_found! | |
35 | + end | |
36 | + end | |
37 | + | |
20 | 38 | NOTEABLE_TYPES.each do |noteable_type| |
21 | 39 | noteables_str = noteable_type.to_s.underscore.pluralize |
22 | 40 | noteable_id_str = "#{noteable_type.to_s.underscore}_id" | ... | ... |
spec/requests/api/notes_spec.rb
... | ... | @@ -30,6 +30,14 @@ describe Gitlab::API do |
30 | 30 | end |
31 | 31 | end |
32 | 32 | |
33 | + describe "POST /projects/:id/notes" do | |
34 | + it "should create a new wall note" do | |
35 | + post api("/projects/#{project.id}/notes", user), body: 'hi!' | |
36 | + response.status.should == 201 | |
37 | + json_response['body'].should == 'hi!' | |
38 | + end | |
39 | + end | |
40 | + | |
33 | 41 | describe "GET /projects/:id/noteable/:noteable_id/notes" do |
34 | 42 | context "when noteable is an Issue" do |
35 | 43 | it "should return an array of issue notes" do | ... | ... |