diff options
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/commits.rb | 29 | ||||
-rw-r--r-- | lib/api/entities.rb | 13 | ||||
-rw-r--r-- | lib/api/keys.rb | 50 | ||||
-rw-r--r-- | lib/api/projects.rb | 18 | ||||
-rw-r--r-- | lib/api/users.rb | 59 |
5 files changed, 77 insertions, 92 deletions
diff --git a/lib/api/commits.rb b/lib/api/commits.rb deleted file mode 100644 index 47d96fc4906..00000000000 --- a/lib/api/commits.rb +++ /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 diff --git a/lib/api/entities.rb b/lib/api/entities.rb index fd19fa0e87f..ee693de699e 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -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 @@ -61,8 +60,8 @@ module Gitlab expose :closed, :updated_at, :created_at end - class Key < Grape::Entity - expose :id, :title, :key + class SSHKey < Grape::Entity + expose :id, :title, :key end end end diff --git a/lib/api/keys.rb b/lib/api/keys.rb deleted file mode 100644 index 4c302727c4f..00000000000 --- a/lib/api/keys.rb +++ /dev/null @@ -1,50 +0,0 @@ -module Gitlab - # Keys API - class Keys < Grape::API - before { authenticate! } - resource :keys do - # Get currently authenticated user's keys - # - # Example Request: - # GET /keys - get do - present current_user.keys, with: Entities::Key - end - # Get single key owned by currently authenticated user - # - # Example Request: - # GET /keys/:id - get "/:id" do - key = current_user.keys.find params[:id] - present key, with: Entities::Key - end - # Add new ssh key to currently authenticated user - # - # Parameters: - # key (required) - New SSH Key - # title (required) - New SSH Key's title - # Example Request: - # POST /keys - post do - attrs = attributes_for_keys [:title, :key] - key = current_user.keys.new attrs - if key.save - present key, with: Entities::Key - else - not_found! - end - end - # Delete existed ssh key of currently authenticated user - # - # Parameters: - # id (required) - SSH Key ID - # Example Request: - # DELETE /keys/:id - delete "/:id" do - key = current_user.keys.find params[:id] - key.delete - end - end - end -end - diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 0554d97c86b..c3dc3da6fac 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -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/lib/api/users.rb b/lib/api/users.rb index 98ced6f8e5b..0ca8fb2a1ae 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -25,12 +25,59 @@ module Gitlab end end - # Get currently authenticated user - # - # Example Request: - # GET /user - get "/user" do - present @current_user, with: Entities::User + resource :user do + # Get currently authenticated user + # + # Example Request: + # GET /user + get do + present @current_user, with: Entities::User + end + + # Get currently authenticated user's keys + # + # Example Request: + # GET /user/keys + get "keys" do + present current_user.keys, with: Entities::SSHKey + end + + # Get single key owned by currently authenticated user + # + # Example Request: + # GET /user/keys/:id + get "keys/:id" do + key = current_user.keys.find params[:id] + present key, with: Entities::SSHKey + end + + # Add new ssh key to currently authenticated user + # + # Parameters: + # key (required) - New SSH Key + # title (required) - New SSH Key's title + # Example Request: + # POST /user/keys + post "keys" do + attrs = attributes_for_keys [:title, :key] + key = current_user.keys.new attrs + if key.save + present key, with: Entities::SSHKey + else + not_found! + end + end + + # Delete existed ssh key of currently authenticated user + # + # Parameters: + # id (required) - SSH Key ID + # Example Request: + # DELETE /user/keys/:id + delete "keys/:id" do + key = current_user.keys.find params[:id] + key.delete + end end end end |