API: commits belong to project repository
This commit is contained in:
parent
131553627d
commit
4a072be2d7
|
@ -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"
|
||||
}
|
||||
]
|
||||
|
||||
```
|
|
@ -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.
|
||||
|
|
|
@ -19,6 +19,5 @@ module Gitlab
|
|||
mount Milestones
|
||||
mount Keys
|
||||
mount Session
|
||||
mount Commits
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue