Commit cf12763d5b6bacd073586ba10579618a60d7ca52
Exists in
master
and in
4 other branches
Merge pull request #2127 from NARKOZ/notes-api
API: don't expose 'updated_at' for notes
Showing
5 changed files
with
47 additions
and
6 deletions
Show diff stats
CHANGELOG
1 | v 3.2.0 | 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 | - Remove project code - use path instead | 5 | - Remove project code - use path instead |
6 | - added username field to user | 6 | - added username field to user |
7 | - rake task to fill usernames based on emails create namespaces for users | 7 | - rake task to fill usernames based on emails create namespaces for users |
doc/api/notes.md
@@ -20,8 +20,7 @@ GET /projects/:id/notes | @@ -20,8 +20,7 @@ GET /projects/:id/notes | ||
20 | "blocked": false, | 20 | "blocked": false, |
21 | "created_at": "2012-05-23T08:00:58Z" | 21 | "created_at": "2012-05-23T08:00:58Z" |
22 | }, | 22 | }, |
23 | - "updated_at":"2012-11-27T19:16:44Z", | ||
24 | - "created_at":"2012-11-27T19:16:44Z" | 23 | + "created_at": "2012-11-27T19:16:44Z" |
25 | } | 24 | } |
26 | ] | 25 | ] |
27 | ``` | 26 | ``` |
@@ -88,6 +87,22 @@ Parameters: | @@ -88,6 +87,22 @@ Parameters: | ||
88 | 87 | ||
89 | ## New note | 88 | ## New note |
90 | 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 | + | ||
91 | ### New issue note | 106 | ### New issue note |
92 | 107 | ||
93 | Create a new issue note. | 108 | Create a new issue note. |
lib/api/entities.rb
@@ -73,7 +73,7 @@ module Gitlab | @@ -73,7 +73,7 @@ module Gitlab | ||
73 | expose :id | 73 | expose :id |
74 | expose :note, as: :body | 74 | expose :note, as: :body |
75 | expose :author, using: Entities::UserBasic | 75 | expose :author, using: Entities::UserBasic |
76 | - expose :updated_at, :created_at | 76 | + expose :created_at |
77 | end | 77 | end |
78 | 78 | ||
79 | class MRNote < Grape::Entity | 79 | class MRNote < Grape::Entity |
lib/api/notes.rb
@@ -17,6 +17,24 @@ module Gitlab | @@ -17,6 +17,24 @@ module Gitlab | ||
17 | present paginate(@notes), with: Entities::Note | 17 | present paginate(@notes), with: Entities::Note |
18 | end | 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 | NOTEABLE_TYPES.each do |noteable_type| | 38 | NOTEABLE_TYPES.each do |noteable_type| |
21 | noteables_str = noteable_type.to_s.underscore.pluralize | 39 | noteables_str = noteable_type.to_s.underscore.pluralize |
22 | noteable_id_str = "#{noteable_type.to_s.underscore}_id" | 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,6 +30,14 @@ describe Gitlab::API do | ||
30 | end | 30 | end |
31 | end | 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 | describe "GET /projects/:id/noteable/:noteable_id/notes" do | 41 | describe "GET /projects/:id/noteable/:noteable_id/notes" do |
34 | context "when noteable is an Issue" do | 42 | context "when noteable is an Issue" do |
35 | it "should return an array of issue notes" do | 43 | it "should return an array of issue notes" do |