diff --git a/CHANGELOG b/CHANGELOG index 4b28da4682b1b054df62effd4ad94b7d23276910..b88d11ca521096d0e87ba5cfb85c092496fcb034 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,7 @@ v 3.2.0 - - [API] create notes for snippets and issues - - [API] list notes for snippets and issues - - [API] list project wall notes + - [API] list, create issue notes + - [API] list, create snippet notes + - [API] list, create wall notes - Remove project code - use path instead - added username field to user - rake task to fill usernames based on emails create namespaces for users diff --git a/doc/api/notes.md b/doc/api/notes.md index 3d8309d3b9d774591196554abdd76400cd0f70fe..97899fa0f6e463e8d749d8248e10bc4134941ca9 100644 --- a/doc/api/notes.md +++ b/doc/api/notes.md @@ -20,8 +20,7 @@ GET /projects/:id/notes "blocked": false, "created_at": "2012-05-23T08:00:58Z" }, - "updated_at":"2012-11-27T19:16:44Z", - "created_at":"2012-11-27T19:16:44Z" + "created_at": "2012-11-27T19:16:44Z" } ] ``` @@ -88,6 +87,22 @@ Parameters: ## New note +### New wall note + +Create a new wall note. + +``` +POST /projects/:id/notes +``` + +Parameters: + ++ `id` (required) - The ID or code name of a project ++ `body` (required) - The content of a note + +Will return created note with status `201 Created` on success, or `404 Not found` on fail. + + ### New issue note Create a new issue note. diff --git a/lib/api/entities.rb b/lib/api/entities.rb index b792d3fbf8d733a559cb6d3f0f5ad31e5af820d3..f985636aa106326208b6264ff0d0ecbea7efff43 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -73,7 +73,7 @@ module Gitlab expose :id expose :note, as: :body expose :author, using: Entities::UserBasic - expose :updated_at, :created_at + expose :created_at end class MRNote < Grape::Entity diff --git a/lib/api/notes.rb b/lib/api/notes.rb index 924eeaa3618153444f0bafe43382d236695796f1..b47ff5c300f0cea4d3db23ee70b226ac6d59946e 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -17,6 +17,24 @@ module Gitlab present paginate(@notes), with: Entities::Note end + # Create a new project wall note + # + # Parameters: + # id (required) - The ID or code name of a project + # body (required) - The content of a note + # Example Request: + # POST /projects/:id/notes + post ":id/notes" do + @note = user_project.notes.new(note: params[:body]) + @note.author = current_user + + if @note.save + present @note, with: Entities::Note + else + not_found! + end + end + NOTEABLE_TYPES.each do |noteable_type| noteables_str = noteable_type.to_s.underscore.pluralize noteable_id_str = "#{noteable_type.to_s.underscore}_id" diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb index b7c8ffaf320dff5d5b40e6988b693c8bca55a91e..dc02e7a3efa13bd9a0b55993b1abe81a8a7362ef 100644 --- a/spec/requests/api/notes_spec.rb +++ b/spec/requests/api/notes_spec.rb @@ -30,6 +30,14 @@ describe Gitlab::API do end end + describe "POST /projects/:id/notes" do + it "should create a new wall note" do + post api("/projects/#{project.id}/notes", user), body: 'hi!' + response.status.should == 201 + json_response['body'].should == 'hi!' + end + end + describe "GET /projects/:id/noteable/:noteable_id/notes" do context "when noteable is an Issue" do it "should return an array of issue notes" do