diff --git a/doc/api/commits.md b/doc/api/commits.md deleted file mode 100644 index fccb35c33000..000000000000 --- a/doc/api/commits.md +++ /dev/null @@ -1,38 +0,0 @@ -## List Commits - -Get a list of project commits. - -``` -GET /projects/:id/commits -``` - -Parameters: - -+ `id` (required) - The ID or code name of a project -+ `ref_name` (optional) - branch/tag name -+ `page` (optional) -+ `per_page` (optional) - - -```json - -[ - { - "id": "ed899a2f4b50b4370feeea94676502b42383c746", - "short_id": "ed899a2f4b5", - "title": "Replace sanitize with escape once", - "author_name": "Dmitriy Zaporozhets", - "author_email": "dzaporozhets@sphereconsultinginc.com", - "created_at": "2012-09-20T11:50:22+03:00" - }, - { - "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", - "short_id": "6104942438c", - "title": "Sanitize for network graph", - "author_name": "randx", - "author_email": "dmitriy.zaporozhets@gmail.com", - "created_at": "2012-09-20T09:06:12+03:00" - } -] - -``` diff --git a/doc/api/projects.md b/doc/api/projects.md index 1e23df3ac899..2d67bfa96743 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -355,6 +355,40 @@ Parameters: ] ``` +## Project repository commits + +Get a list of repository commits in a project. + +``` +GET /projects/:id/repository/commits +``` + +Parameters: + ++ `id` (required) - The ID or code name of a project ++ `ref_name` (optional) - The name of a repository branch or tag + +```json +[ + { + "id": "ed899a2f4b50b4370feeea94676502b42383c746", + "short_id": "ed899a2f4b5", + "title": "Replace sanitize with escape once", + "author_name": "Dmitriy Zaporozhets", + "author_email": "dzaporozhets@sphereconsultinginc.com", + "created_at": "2012-09-20T11:50:22+03:00" + }, + { + "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", + "short_id": "6104942438c", + "title": "Sanitize for network graph", + "author_name": "randx", + "author_email": "dmitriy.zaporozhets@gmail.com", + "created_at": "2012-09-20T09:06:12+03:00" + } +] +``` + ## Raw blob content Get the raw file contents for a file. diff --git a/lib/api.rb b/lib/api.rb index f4e9e5fcc13a..3b62f31bf322 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -19,6 +19,5 @@ class API < Grape::API mount Milestones mount Keys mount Session - mount Commits end end diff --git a/lib/api/commits.rb b/lib/api/commits.rb deleted file mode 100644 index 47d96fc4906d..000000000000 --- a/lib/api/commits.rb +++ /dev/null @@ -1,29 +0,0 @@ -module Gitlab - # Commits API - class Commits < Grape::API - before { authenticate! } - - resource :projects do - # Get a list of project commits - # - # Parameters: - # id (required) - The ID or code name of a project - # ref_name (optional) - Name of branch or tag - # page (optional) - default is 0 - # per_page (optional) - default is 20 - # Example Request: - # GET /projects/:id/commits - get ":id/commits" do - authorize! :download_code, user_project - - page = params[:page] || 0 - per_page = params[:per_page] || 20 - ref = params[:ref_name] || user_project.try(:default_branch) || 'master' - - commits = user_project.commits(ref, nil, per_page, page * per_page) - - present CommitDecorator.decorate(commits), with: Entities::Commit - end - end - end -end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index fd19fa0e87fd..ee6f15f12186 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -17,11 +17,6 @@ class Hook < Grape::Entity expose :id, :url end - class Commit < Grape::Entity - expose :id, :short_id, :title, - :author_name, :author_email, :created_at - end - class Project < Grape::Entity expose :id, :code, :name, :description, :path, :default_branch expose :owner, using: Entities::UserBasic @@ -39,6 +34,10 @@ class RepoObject < Grape::Entity expose :name, :commit end + class RepoCommit < Grape::Entity + expose :id, :short_id, :title, :author_name, :author_email, :created_at + end + class ProjectSnippet < Grape::Entity expose :id, :title, :file_name expose :author, using: Entities::UserBasic diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 0554d97c86bd..c3dc3da6facd 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -211,6 +211,24 @@ class Projects < Grape::API present user_project.repo.tags.sort_by(&:name).reverse, with: Entities::RepoObject end + # Get a project repository commits + # + # Parameters: + # id (required) - The ID or code name of a project + # ref_name (optional) - The name of a repository branch or tag + # Example Request: + # GET /projects/:id/repository/commits + get ":id/repository/commits" do + authorize! :download_code, user_project + + page = params[:page] || 0 + per_page = params[:per_page] || 20 + ref = params[:ref_name] || user_project.try(:default_branch) || 'master' + + commits = user_project.commits(ref, nil, per_page, page * per_page) + present CommitDecorator.decorate(commits), with: Entities::RepoCommit + end + # Get a project snippet # # Parameters: diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb deleted file mode 100644 index 3af5ec21c432..000000000000 --- a/spec/requests/api/commits_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'spec_helper' - -describe Gitlab::API do - include ApiHelpers - - let(:user) { Factory :user } - let!(:project) { Factory :project, owner: user } - - describe "GET /projects/:id/commits" do - context "authorized user" do - before { project.add_access(user, :read) } - - it "should return project commits" do - get api("/projects/#{project.code}/commits", user) - response.status.should == 200 - - json_response.should be_an Array - json_response.first['id'].should == project.commit.id - end - end - - context "unauthorized user" do - it "should return project commits" do - get api("/projects/#{project.code}/commits") - response.status.should == 401 - end - end - end -end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 40a9147d726b..498bbad6179f 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -199,6 +199,27 @@ end end + describe "GET /projects/:id/repository/commits" do + context "authorized user" do + before { project.add_access(user2, :read) } + + it "should return project commits" do + get api("/projects/#{project.code}/repository/commits", user) + response.status.should == 200 + + json_response.should be_an Array + json_response.first['id'].should == project.commit.id + end + end + + context "unauthorized user" do + it "should not return project commits" do + get api("/projects/#{project.code}/repository/commits") + response.status.should == 401 + end + 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)