From 968c09ae919ce745a158764d49b3aff280324eb5 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Thu, 29 Nov 2012 13:42:22 -0800 Subject: [PATCH 1/4] API version returns last version set * fixed in grape v0.2.2 --- lib/api.rb | 3 +-- spec/support/api_helpers.rb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/api.rb b/lib/api.rb index 99e2074f306..d01d534cf6b 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -2,8 +2,7 @@ Dir["#{Rails.root}/lib/api/*.rb"].each {|file| require file} module Gitlab class API < Grape::API - VERSION = 'v2' - version VERSION, using: :path + version 'v2', using: :path rescue_from ActiveRecord::RecordNotFound do rack_response({'message' => '404 Not found'}.to_json, 404) diff --git a/spec/support/api_helpers.rb b/spec/support/api_helpers.rb index 7d9011971dd..c4514bf38be 100644 --- a/spec/support/api_helpers.rb +++ b/spec/support/api_helpers.rb @@ -18,7 +18,7 @@ module ApiHelpers # # Returns the relative path to the requested API resource def api(path, user = nil) - "/api/#{Gitlab::API::VERSION}#{path}" + + "/api/#{Gitlab::API.version}#{path}" + # Normalize query string (path.index('?') ? '' : '?') + From 42ef89c98ab39904d313571ec26c67506cdbab59 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Thu, 29 Nov 2012 14:59:56 -0800 Subject: [PATCH 2/4] API: expose created date for project hooks and user SSH keys --- CHANGELOG | 1 + lib/api/entities.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2c6152e77dd..73933e0be4b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,5 @@ v 4.0.0 + - [API] expose created date for hooks and SSH keys - [API] list, create issue notes - [API] list, create snippet notes - [API] list, create wall notes diff --git a/lib/api/entities.rb b/lib/api/entities.rb index f985636aa10..9e9d44594a2 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -14,7 +14,7 @@ module Gitlab end class Hook < Grape::Entity - expose :id, :url + expose :id, :url, :created_at end class Project < Grape::Entity @@ -61,7 +61,7 @@ module Gitlab end class SSHKey < Grape::Entity - expose :id, :title, :key + expose :id, :title, :key, :created_at end class MergeRequest < Grape::Entity From b17e94c37bd5868c44f3aa085bfc3e44e227dc07 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Sat, 1 Dec 2012 02:07:57 -0800 Subject: [PATCH 3/4] update contents of API README --- doc/api/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/api/README.md b/doc/api/README.md index 19b7ff20bf3..ca346418f23 100644 --- a/doc/api/README.md +++ b/doc/api/README.md @@ -25,7 +25,7 @@ The API uses JSON to serialize data. You don't need to specify `.json` at the en When listing resources you can pass the following parameters: + `page` (default: `1`) - page number -+ `per_page` (default: `20`, max: `100`) - how many items to list per page ++ `per_page` (default: `20`, max: `100`) - number of items to list per page ## Contents @@ -36,3 +36,4 @@ When listing resources you can pass the following parameters: + [Repositories](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/repositories.md) + [Issues](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/issues.md) + [Milestones](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/milestones.md) ++ [Notes](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/notes.md) From 270a43370a4cd9e5f222ad707f68f42088d5ae06 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Sat, 1 Dec 2012 02:20:45 -0800 Subject: [PATCH 4/4] API: get a single wall note --- doc/api/notes.md | 13 +++++++++++++ lib/api/notes.rb | 12 ++++++++++++ spec/requests/api/notes_spec.rb | 8 ++++++++ 3 files changed, 33 insertions(+) diff --git a/doc/api/notes.md b/doc/api/notes.md index 97899fa0f6e..7b226dea44c 100644 --- a/doc/api/notes.md +++ b/doc/api/notes.md @@ -57,6 +57,19 @@ Parameters: ## Single note +### Single wall note + +Get a wall note. + +``` +GET /projects/:id/notes/:note_id +``` + +Parameters: + ++ `id` (required) - The ID or code name of a project ++ `note_id` (required) - The ID of a wall note + ### Single issue note Get an issue note. diff --git a/lib/api/notes.rb b/lib/api/notes.rb index b47ff5c300f..a3e1858458d 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -17,6 +17,18 @@ module Gitlab present paginate(@notes), with: Entities::Note end + # Get a single project wall note + # + # Parameters: + # id (required) - The ID or code name of a project + # note_id (required) - The ID of a note + # Example Request: + # GET /projects/:id/notes/:note_id + get ":id/notes/:note_id" do + @note = user_project.common_notes.find(params[:note_id]) + present @note, with: Entities::Note + end + # Create a new project wall note # # Parameters: diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb index dc02e7a3efa..681ba01558e 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 "GET /projects/:id/notes/:note_id" do + it "should return a wall note by id" do + get api("/projects/#{project.id}/notes/#{wall_note.id}", user) + response.status.should == 200 + json_response['body'].should == wall_note.note + 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!'