refactor projects API
This commit is contained in:
parent
0a6b64e6a9
commit
0f604e62fb
3 changed files with 13 additions and 21 deletions
|
@ -16,11 +16,7 @@ module Gitlab
|
||||||
expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :created_at
|
expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :created_at
|
||||||
end
|
end
|
||||||
|
|
||||||
class ProjectRepositoryBranches < Grape::Entity
|
class RepoObject < Grape::Entity
|
||||||
expose :name, :commit
|
|
||||||
end
|
|
||||||
|
|
||||||
class ProjectRepositoryTags < Grape::Entity
|
|
||||||
expose :name, :commit
|
expose :name, :commit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,10 @@ module Gitlab
|
||||||
@current_user ||= User.find_by_authentication_token(params[:private_token])
|
@current_user ||= User.find_by_authentication_token(params[:private_token])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def user_project
|
||||||
|
@project ||= current_user.projects.find_by_code(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
def authenticate!
|
def authenticate!
|
||||||
error!({'message' => '401 Unauthorized'}, 401) unless current_user
|
error!({'message' => '401 Unauthorized'}, 401) unless current_user
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,8 +20,7 @@ module Gitlab
|
||||||
# Example Request:
|
# Example Request:
|
||||||
# GET /projects/:id
|
# GET /projects/:id
|
||||||
get ":id" do
|
get ":id" do
|
||||||
@project = current_user.projects.find_by_code(params[:id])
|
present user_project, :with => Entities::Project
|
||||||
present @project, :with => Entities::Project
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get a project repository branches
|
# Get a project repository branches
|
||||||
|
@ -31,8 +30,7 @@ module Gitlab
|
||||||
# Example Request:
|
# Example Request:
|
||||||
# GET /projects/:id/repository/branches
|
# GET /projects/:id/repository/branches
|
||||||
get ":id/repository/branches" do
|
get ":id/repository/branches" do
|
||||||
@project = current_user.projects.find_by_code(params[:id])
|
present user_project.repo.heads.sort_by(&:name), :with => Entities::RepoObject
|
||||||
present @project.repo.heads.sort_by(&:name), :with => Entities::ProjectRepositoryBranches
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get a project repository tags
|
# Get a project repository tags
|
||||||
|
@ -42,8 +40,7 @@ module Gitlab
|
||||||
# Example Request:
|
# Example Request:
|
||||||
# GET /projects/:id/repository/tags
|
# GET /projects/:id/repository/tags
|
||||||
get ":id/repository/tags" do
|
get ":id/repository/tags" do
|
||||||
@project = current_user.projects.find_by_code(params[:id])
|
present user_project.repo.tags.sort_by(&:name).reverse, :with => Entities::RepoObject
|
||||||
present @project.repo.tags.sort_by(&:name).reverse, :with => Entities::ProjectRepositoryTags
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get a project snippet
|
# Get a project snippet
|
||||||
|
@ -54,8 +51,7 @@ module Gitlab
|
||||||
# Example Request:
|
# Example Request:
|
||||||
# GET /projects/:id/snippets/:snippet_id
|
# GET /projects/:id/snippets/:snippet_id
|
||||||
get ":id/snippets/:snippet_id" do
|
get ":id/snippets/:snippet_id" do
|
||||||
@project = current_user.projects.find_by_code(params[:id])
|
@snippet = user_project.snippets.find(params[:snippet_id])
|
||||||
@snippet = @project.snippets.find(params[:snippet_id])
|
|
||||||
present @snippet, :with => Entities::ProjectSnippet
|
present @snippet, :with => Entities::ProjectSnippet
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -70,8 +66,7 @@ module Gitlab
|
||||||
# Example Request:
|
# Example Request:
|
||||||
# POST /projects/:id/snippets
|
# POST /projects/:id/snippets
|
||||||
post ":id/snippets" do
|
post ":id/snippets" do
|
||||||
@project = current_user.projects.find_by_code(params[:id])
|
@snippet = user_project.snippets.new(
|
||||||
@snippet = @project.snippets.new(
|
|
||||||
:title => params[:title],
|
:title => params[:title],
|
||||||
:file_name => params[:file_name],
|
:file_name => params[:file_name],
|
||||||
:expires_at => params[:lifetime],
|
:expires_at => params[:lifetime],
|
||||||
|
@ -98,8 +93,7 @@ module Gitlab
|
||||||
# Example Request:
|
# Example Request:
|
||||||
# PUT /projects/:id/snippets/:snippet_id
|
# PUT /projects/:id/snippets/:snippet_id
|
||||||
put ":id/snippets/:snippet_id" do
|
put ":id/snippets/:snippet_id" do
|
||||||
@project = current_user.projects.find_by_code(params[:id])
|
@snippet = user_project.snippets.find(params[:snippet_id])
|
||||||
@snippet = @project.snippets.find(params[:snippet_id])
|
|
||||||
parameters = {
|
parameters = {
|
||||||
:title => (params[:title] || @snippet.title),
|
:title => (params[:title] || @snippet.title),
|
||||||
:file_name => (params[:file_name] || @snippet.file_name),
|
:file_name => (params[:file_name] || @snippet.file_name),
|
||||||
|
@ -122,8 +116,7 @@ module Gitlab
|
||||||
# Example Request:
|
# Example Request:
|
||||||
# DELETE /projects/:id/snippets/:snippet_id
|
# DELETE /projects/:id/snippets/:snippet_id
|
||||||
delete ":id/snippets/:snippet_id" do
|
delete ":id/snippets/:snippet_id" do
|
||||||
@project = current_user.projects.find_by_code(params[:id])
|
@snippet = user_project.snippets.find(params[:snippet_id])
|
||||||
@snippet = @project.snippets.find(params[:snippet_id])
|
|
||||||
@snippet.destroy
|
@snippet.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -135,8 +128,7 @@ module Gitlab
|
||||||
# Example Request:
|
# Example Request:
|
||||||
# GET /projects/:id/snippets/:snippet_id/raw
|
# GET /projects/:id/snippets/:snippet_id/raw
|
||||||
get ":id/snippets/:snippet_id/raw" do
|
get ":id/snippets/:snippet_id/raw" do
|
||||||
@project = current_user.projects.find_by_code(params[:id])
|
@snippet = user_project.snippets.find(params[:snippet_id])
|
||||||
@snippet = @project.snippets.find(params[:snippet_id])
|
|
||||||
present @snippet.content
|
present @snippet.content
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue