diff --git a/CHANGELOG b/CHANGELOG index 3a283aa5a45..1c9f3bbac40 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,5 @@ master + - [API] add project snippets list - [API] allow to authorize using private token in HTTP header - [API] add user creation diff --git a/doc/api/snippets.md b/doc/api/snippets.md index 0cd29ce530b..288fd5296f6 100644 --- a/doc/api/snippets.md +++ b/doc/api/snippets.md @@ -1,6 +1,14 @@ ## List snippets -Not implemented. +Get a list of project snippets. + +``` +GET /projects/:id/snippets +``` + +Parameters: + ++ `id` (required) - The ID or code name of a project ## Single snippet diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 5a1b1779ad5..0f013883c81 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -228,6 +228,16 @@ module Gitlab present CommitDecorator.decorate(commits), with: Entities::RepoCommit end + # Get a project snippets + # + # Parameters: + # id (required) - The ID or code name of a project + # Example Request: + # GET /projects/:id/snippets + get ":id/snippets" do + present paginate(user_project.snippets), with: Entities::ProjectSnippet + end + # Get a project snippet # # Parameters: diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 498bbad6179..94c9abb35e4 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -220,6 +220,15 @@ describe Gitlab::API do end end + describe "GET /projects/:id/snippets" do + it "should return a project snippet" do + get api("/projects/#{project.code}/snippets", user) + response.status.should == 200 + json_response.should be_an Array + json_response.first['title'].should == snippet.title + end + end + describe "GET /projects/:id/snippets/:snippet_id" do it "should return a project snippet" do get api("/projects/#{project.code}/snippets/#{snippet.id}", user)