API: commits belong to project repository
This commit is contained in:
parent
131553627d
commit
4a072be2d7
8 changed files with 77 additions and 102 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue