Commit 634cbd71380f595f6f44ce93399b92fbee37f98f
1 parent
e6224942
Exists in
master
and in
4 other branches
Refactor API classes. So api classes like Gitlab::Issues become API::Issues
Showing
28 changed files
with
68 additions
and
68 deletions
Show diff stats
app/controllers/application_controller.rb
| ... | ... | @@ -152,7 +152,7 @@ class ApplicationController < ActionController::Base |
| 152 | 152 | |
| 153 | 153 | def add_gon_variables |
| 154 | 154 | gon.default_issues_tracker = Project.issues_tracker.default_value |
| 155 | - gon.api_version = Gitlab::API.version | |
| 155 | + gon.api_version = API::API.version | |
| 156 | 156 | gon.api_token = current_user.private_token if current_user |
| 157 | 157 | gon.gravatar_url = request.ssl? ? Gitlab.config.gravatar.ssl_url : Gitlab.config.gravatar.plain_url |
| 158 | 158 | gon.relative_url_root = Gitlab.config.gitlab.relative_url_root | ... | ... |
config/routes.rb
| 1 | 1 | require 'sidekiq/web' |
| 2 | +require 'api/api' | |
| 2 | 3 | |
| 3 | 4 | Gitlab::Application.routes.draw do |
| 4 | 5 | # |
| ... | ... | @@ -7,9 +8,8 @@ Gitlab::Application.routes.draw do |
| 7 | 8 | get 'search' => "search#show" |
| 8 | 9 | |
| 9 | 10 | # API |
| 10 | - require 'api' | |
| 11 | - Gitlab::API.logger Rails.logger | |
| 12 | - mount Gitlab::API => '/api' | |
| 11 | + API::API.logger Rails.logger | |
| 12 | + mount API::API => '/api' | |
| 13 | 13 | |
| 14 | 14 | constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.admin? } |
| 15 | 15 | constraints constraint do | ... | ... |
lib/api.rb
| ... | ... | @@ -1,38 +0,0 @@ |
| 1 | -Dir["#{Rails.root}/lib/api/*.rb"].each {|file| require file} | |
| 2 | - | |
| 3 | -module Gitlab | |
| 4 | - class API < Grape::API | |
| 5 | - version 'v3', using: :path | |
| 6 | - | |
| 7 | - rescue_from ActiveRecord::RecordNotFound do | |
| 8 | - rack_response({'message' => '404 Not found'}.to_json, 404) | |
| 9 | - end | |
| 10 | - | |
| 11 | - rescue_from :all do |exception| | |
| 12 | - # lifted from https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L60 | |
| 13 | - # why is this not wrapped in something reusable? | |
| 14 | - trace = exception.backtrace | |
| 15 | - | |
| 16 | - message = "\n#{exception.class} (#{exception.message}):\n" | |
| 17 | - message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code) | |
| 18 | - message << " " << trace.join("\n ") | |
| 19 | - | |
| 20 | - API.logger.add Logger::FATAL, message | |
| 21 | - rack_response({'message' => '500 Internal Server Error'}, 500) | |
| 22 | - end | |
| 23 | - | |
| 24 | - format :json | |
| 25 | - helpers APIHelpers | |
| 26 | - | |
| 27 | - mount Groups | |
| 28 | - mount Users | |
| 29 | - mount Projects | |
| 30 | - mount Issues | |
| 31 | - mount Milestones | |
| 32 | - mount Session | |
| 33 | - mount MergeRequests | |
| 34 | - mount Notes | |
| 35 | - mount Internal | |
| 36 | - mount SystemHooks | |
| 37 | - end | |
| 38 | -end |
| ... | ... | @@ -0,0 +1,38 @@ |
| 1 | +Dir["#{Rails.root}/lib/api/*.rb"].each {|file| require file} | |
| 2 | + | |
| 3 | +module API | |
| 4 | + class API < Grape::API | |
| 5 | + version 'v3', using: :path | |
| 6 | + | |
| 7 | + rescue_from ActiveRecord::RecordNotFound do | |
| 8 | + rack_response({'message' => '404 Not found'}.to_json, 404) | |
| 9 | + end | |
| 10 | + | |
| 11 | + rescue_from :all do |exception| | |
| 12 | + # lifted from https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L60 | |
| 13 | + # why is this not wrapped in something reusable? | |
| 14 | + trace = exception.backtrace | |
| 15 | + | |
| 16 | + message = "\n#{exception.class} (#{exception.message}):\n" | |
| 17 | + message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code) | |
| 18 | + message << " " << trace.join("\n ") | |
| 19 | + | |
| 20 | + API.logger.add Logger::FATAL, message | |
| 21 | + rack_response({'message' => '500 Internal Server Error'}, 500) | |
| 22 | + end | |
| 23 | + | |
| 24 | + format :json | |
| 25 | + helpers APIHelpers | |
| 26 | + | |
| 27 | + mount Groups | |
| 28 | + mount Users | |
| 29 | + mount Projects | |
| 30 | + mount Issues | |
| 31 | + mount Milestones | |
| 32 | + mount Session | |
| 33 | + mount MergeRequests | |
| 34 | + mount Notes | |
| 35 | + mount Internal | |
| 36 | + mount SystemHooks | |
| 37 | + end | |
| 38 | +end | ... | ... |
lib/api/entities.rb
lib/api/groups.rb
lib/api/helpers.rb
lib/api/internal.rb
| 1 | -module Gitlab | |
| 1 | +module API | |
| 2 | 2 | # Internal access API |
| 3 | 3 | class Internal < Grape::API |
| 4 | 4 | namespace 'internal' do |
| ... | ... | @@ -58,7 +58,7 @@ module Gitlab |
| 58 | 58 | |
| 59 | 59 | get "/check" do |
| 60 | 60 | { |
| 61 | - api_version: Gitlab::API.version, | |
| 61 | + api_version: API.version, | |
| 62 | 62 | gitlab_version: Gitlab::VERSION, |
| 63 | 63 | gitlab_rev: Gitlab::REVISION, |
| 64 | 64 | } | ... | ... |
lib/api/issues.rb
lib/api/merge_requests.rb
lib/api/milestones.rb
lib/api/notes.rb
lib/api/projects.rb
lib/api/session.rb
lib/api/system_hooks.rb
lib/api/users.rb
spec/requests/api/groups_spec.rb
spec/requests/api/internal_spec.rb
| 1 | 1 | require 'spec_helper' |
| 2 | 2 | |
| 3 | -describe Gitlab::API do | |
| 3 | +describe API::API do | |
| 4 | 4 | include ApiHelpers |
| 5 | 5 | |
| 6 | 6 | let(:user) { create(:user) } |
| ... | ... | @@ -12,7 +12,7 @@ describe Gitlab::API do |
| 12 | 12 | get api("/internal/check") |
| 13 | 13 | |
| 14 | 14 | response.status.should == 200 |
| 15 | - json_response['api_version'].should == Gitlab::API.version | |
| 15 | + json_response['api_version'].should == API::API.version | |
| 16 | 16 | end |
| 17 | 17 | end |
| 18 | 18 | ... | ... |
spec/requests/api/issues_spec.rb
spec/requests/api/merge_requests_spec.rb
spec/requests/api/milestones_spec.rb
spec/requests/api/notes_spec.rb
spec/requests/api/projects_spec.rb
spec/requests/api/session_spec.rb
spec/requests/api/system_hooks_spec.rb
spec/requests/api/users_spec.rb
spec/routing/routing_spec.rb
spec/support/api_helpers.rb
| ... | ... | @@ -18,7 +18,7 @@ module ApiHelpers |
| 18 | 18 | # |
| 19 | 19 | # Returns the relative path to the requested API resource |
| 20 | 20 | def api(path, user = nil) |
| 21 | - "/api/#{Gitlab::API.version}#{path}" + | |
| 21 | + "/api/#{API::API.version}#{path}" + | |
| 22 | 22 | |
| 23 | 23 | # Normalize query string |
| 24 | 24 | (path.index('?') ? '' : '?') + | ... | ... |