OSDN Git Service

API: commits belong to project repository
authorNihad Abbasov <narkoz.2008@gmail.com>
Fri, 21 Sep 2012 11:34:07 +0000 (04:34 -0700)
committerNihad Abbasov <narkoz.2008@gmail.com>
Fri, 21 Sep 2012 11:34:07 +0000 (04:34 -0700)
doc/api/commits.md [deleted file]
doc/api/projects.md
lib/api.rb
lib/api/commits.rb [deleted file]
lib/api/entities.rb
lib/api/projects.rb
spec/requests/api/commits_spec.rb [deleted file]
spec/requests/api/projects_spec.rb

diff --git a/doc/api/commits.md b/doc/api/commits.md
deleted file mode 100644 (file)
index fccb35c..0000000
+++ /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"
-  }
-]
-
-```
index 1e23df3..2d67bfa 100644 (file)
@@ -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.
index f4e9e5f..3b62f31 100644 (file)
@@ -19,6 +19,5 @@ module Gitlab
     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 (file)
index 47d96fc..0000000
+++ /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
index fd19fa0..ee6f15f 100644 (file)
@@ -17,11 +17,6 @@ module Gitlab
       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 @@ module Gitlab
       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
index 0554d97..c3dc3da 100644 (file)
@@ -211,6 +211,24 @@ module Gitlab
         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 (file)
index 3af5ec2..0000000
+++ /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
index 40a9147..498bbad 100644 (file)
@@ -199,6 +199,27 @@ describe Gitlab::API do
     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)