APi for commits. Better api docs
This commit is contained in:
parent
4cc169d3ca
commit
10d3a30b25
10 changed files with 205 additions and 85 deletions
29
lib/api/commits.rb
Normal file
29
lib/api/commits.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
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,6 +17,11 @@ 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
|
||||
|
|
|
@ -61,7 +61,7 @@ module Gitlab
|
|||
error!({'message' => message}, status)
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
def abilities
|
||||
@abilities ||= begin
|
||||
|
|
|
@ -11,6 +11,8 @@ module Gitlab
|
|||
# Example Request:
|
||||
# GET /projects/:id/milestones
|
||||
get ":id/milestones" do
|
||||
authorize! :read_milestone, user_project
|
||||
|
||||
present paginate(user_project.milestones), with: Entities::Milestone
|
||||
end
|
||||
|
||||
|
@ -22,6 +24,8 @@ module Gitlab
|
|||
# Example Request:
|
||||
# GET /projects/:id/milestones/:milestone_id
|
||||
get ":id/milestones/:milestone_id" do
|
||||
authorize! :read_milestone, user_project
|
||||
|
||||
@milestone = user_project.milestones.find(params[:milestone_id])
|
||||
present @milestone, with: Entities::Milestone
|
||||
end
|
||||
|
@ -36,6 +40,8 @@ module Gitlab
|
|||
# Example Request:
|
||||
# POST /projects/:id/milestones
|
||||
post ":id/milestones" do
|
||||
authorize! :admin_milestone, user_project
|
||||
|
||||
attrs = attributes_for_keys [:title, :description, :due_date]
|
||||
@milestone = user_project.milestones.new attrs
|
||||
if @milestone.save
|
||||
|
|
|
@ -40,14 +40,14 @@ module Gitlab
|
|||
post do
|
||||
params[:code] ||= params[:name]
|
||||
params[:path] ||= params[:name]
|
||||
attrs = attributes_for_keys [:code,
|
||||
:path,
|
||||
:name,
|
||||
:description,
|
||||
:default_branch,
|
||||
:issues_enabled,
|
||||
:wall_enabled,
|
||||
:merge_requests_enabled,
|
||||
attrs = attributes_for_keys [:code,
|
||||
:path,
|
||||
:name,
|
||||
:description,
|
||||
:default_branch,
|
||||
:issues_enabled,
|
||||
:wall_enabled,
|
||||
:merge_requests_enabled,
|
||||
:wiki_enabled]
|
||||
@project = Project.create_by_user(attrs, current_user)
|
||||
if @project.saved?
|
||||
|
@ -207,6 +207,8 @@ module Gitlab
|
|||
# Example Request:
|
||||
# POST /projects/:id/snippets
|
||||
post ":id/snippets" do
|
||||
authorize! :write_snippet, user_project
|
||||
|
||||
attrs = attributes_for_keys [:title, :file_name]
|
||||
attrs[:expires_at] = params[:lifetime] if params[:lifetime].present?
|
||||
attrs[:content] = params[:code] if params[:code].present?
|
||||
|
@ -282,6 +284,8 @@ module Gitlab
|
|||
# Example Request:
|
||||
# GET /projects/:id/repository/commits/:sha/blob
|
||||
get ":id/repository/commits/:sha/blob" do
|
||||
authorize! :download_code, user_project
|
||||
|
||||
ref = params[:sha]
|
||||
|
||||
commit = user_project.commit ref
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue