diff options
Diffstat (limited to 'lib/api')
100 files changed, 2607 insertions, 2598 deletions
diff --git a/lib/api/access_requests.rb b/lib/api/access_requests.rb index ee8dc822098..b0c12ad7d56 100644 --- a/lib/api/access_requests.rb +++ b/lib/api/access_requests.rb @@ -14,7 +14,7 @@ module API end resource source_type.pluralize, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do desc "Gets a list of access requests for a #{source_type}." do - detail 'This feature was introduced in GitLab 8.11.' + detail "This feature was introduced in GitLab 8.11." success Entities::AccessRequester end params do @@ -32,7 +32,7 @@ module API # rubocop: enable CodeReuse/ActiveRecord desc "Requests access for the authenticated user to a #{source_type}." do - detail 'This feature was introduced in GitLab 8.11.' + detail "This feature was introduced in GitLab 8.11." success Entities::AccessRequester end post ":id/access_requests" do @@ -46,16 +46,16 @@ module API end end - desc 'Approves an access request for the given user.' do - detail 'This feature was introduced in GitLab 8.11.' + desc "Approves an access request for the given user." do + detail "This feature was introduced in GitLab 8.11." success Entities::Member end params do - requires :user_id, type: Integer, desc: 'The user ID of the access requester' - optional :access_level, type: Integer, desc: 'A valid access level (defaults: `30`, developer access level)' + requires :user_id, type: Integer, desc: "The user ID of the access requester" + optional :access_level, type: Integer, desc: "A valid access level (defaults: `30`, developer access level)" end # rubocop: disable CodeReuse/ActiveRecord - put ':id/access_requests/:user_id/approve' do + put ":id/access_requests/:user_id/approve" do source = find_source(source_type, params[:id]) access_requester = source.requesters.find_by!(user_id: params[:user_id]) @@ -68,11 +68,11 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Denies an access request for the given user.' do - detail 'This feature was introduced in GitLab 8.11.' + desc "Denies an access request for the given user." do + detail "This feature was introduced in GitLab 8.11." end params do - requires :user_id, type: Integer, desc: 'The user ID of the access requester' + requires :user_id, type: Integer, desc: "The user ID of the access requester" end # rubocop: disable CodeReuse/ActiveRecord delete ":id/access_requests/:user_id" do diff --git a/lib/api/api.rb b/lib/api/api.rb index bf8ddba6f0d..3b89a541ca5 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -7,61 +7,61 @@ module API LOG_FILENAME = Rails.root.join("log", "api_json.log") NO_SLASH_URL_PART_REGEX = %r{[^/]+} - NAMESPACE_OR_PROJECT_REQUIREMENTS = { id: NO_SLASH_URL_PART_REGEX }.freeze + NAMESPACE_OR_PROJECT_REQUIREMENTS = {id: NO_SLASH_URL_PART_REGEX}.freeze COMMIT_ENDPOINT_REQUIREMENTS = NAMESPACE_OR_PROJECT_REQUIREMENTS.merge(sha: NO_SLASH_URL_PART_REGEX).freeze - USER_REQUIREMENTS = { user_id: NO_SLASH_URL_PART_REGEX }.freeze + USER_REQUIREMENTS = {user_id: NO_SLASH_URL_PART_REGEX}.freeze insert_before Grape::Middleware::Error, - GrapeLogging::Middleware::RequestLogger, - logger: Logger.new(LOG_FILENAME), - formatter: Gitlab::GrapeLogging::Formatters::LogrageWithTimestamp.new, - include: [ - GrapeLogging::Loggers::FilterParameters.new, - GrapeLogging::Loggers::ClientEnv.new, - Gitlab::GrapeLogging::Loggers::RouteLogger.new, - Gitlab::GrapeLogging::Loggers::UserLogger.new, - Gitlab::GrapeLogging::Loggers::QueueDurationLogger.new, - Gitlab::GrapeLogging::Loggers::PerfLogger.new, - Gitlab::GrapeLogging::Loggers::CorrelationIdLogger.new - ] + GrapeLogging::Middleware::RequestLogger, + logger: Logger.new(LOG_FILENAME), + formatter: Gitlab::GrapeLogging::Formatters::LogrageWithTimestamp.new, + include: [ + GrapeLogging::Loggers::FilterParameters.new, + GrapeLogging::Loggers::ClientEnv.new, + Gitlab::GrapeLogging::Loggers::RouteLogger.new, + Gitlab::GrapeLogging::Loggers::UserLogger.new, + Gitlab::GrapeLogging::Loggers::QueueDurationLogger.new, + Gitlab::GrapeLogging::Loggers::PerfLogger.new, + Gitlab::GrapeLogging::Loggers::CorrelationIdLogger.new, + ] allow_access_with_scope :api prefix :api - version 'v3', using: :path do - route :any, '*path' do - error!('API V3 is no longer supported. Use API V4 instead.', 410) + version "v3", using: :path do + route :any, "*path" do + error!("API V3 is no longer supported. Use API V4 instead.", 410) end end - version 'v4', using: :path + version "v4", using: :path before do - header['X-Frame-Options'] = 'SAMEORIGIN' - header['X-Content-Type-Options'] = 'nosniff' + header["X-Frame-Options"] = "SAMEORIGIN" + header["X-Content-Type-Options"] = "nosniff" end # The locale is set to the current user's locale when `current_user` is loaded after { Gitlab::I18n.use_default_locale } rescue_from Gitlab::Access::AccessDeniedError do - rack_response({ 'message' => '403 Forbidden' }.to_json, 403) + rack_response({"message" => "403 Forbidden"}.to_json, 403) end rescue_from ActiveRecord::RecordNotFound do - rack_response({ 'message' => '404 Not found' }.to_json, 404) + rack_response({"message" => "404 Not found"}.to_json, 404) end rescue_from ::Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError do - rack_response({ 'message' => '409 Conflict: Resource lock' }.to_json, 409) + rack_response({"message" => "409 Conflict: Resource lock"}.to_json, 409) end rescue_from UploadedFile::InvalidPathError do |e| - rack_response({ 'message' => e.message }.to_json, 400) + rack_response({"message" => e.message}.to_json, 400) end rescue_from ObjectStorage::RemoteStoreError do |e| - rack_response({ 'message' => e.message }.to_json, 500) + rack_response({"message" => e.message}.to_json, 500) end # Retain 405 error rather than a 500 error for Grape 0.15.0+. @@ -75,7 +75,7 @@ module API end rescue_from Gitlab::Auth::TooManyIps do |e| - rack_response({ 'message' => '403 Forbidden' }.to_json, 403) + rack_response({"message" => "403 Forbidden"}.to_json, 403) end rescue_from :all do |exception| @@ -168,8 +168,8 @@ module API mount ::API::Version mount ::API::Wikis - route :any, '*path' do - error!('404 Not Found', 404) + route :any, "*path" do + error!("404 Not Found", 404) end end end diff --git a/lib/api/api_guard.rb b/lib/api/api_guard.rb index af9b519ed9e..2deb50e287b 100644 --- a/lib/api/api_guard.rb +++ b/lib/api/api_guard.rb @@ -2,7 +2,7 @@ # Guard API with OAuth 2.0 Access Token -require 'rack/oauth2' +require "rack/oauth2" module API module APIGuard @@ -10,7 +10,7 @@ module API included do |base| # OAuth2 Resource Server Authentication - use Rack::OAuth2::Server::Resource::Bearer, 'The API' do |request| + use Rack::OAuth2::Server::Resource::Bearer, "The API" do |request| # The authenticator only fetches the raw token string # Must yield access token to store it in the env @@ -95,7 +95,7 @@ module API Gitlab::Auth::ExpiredError, Gitlab::Auth::RevokedError, Gitlab::Auth::ImpersonationDisabled, - Gitlab::Auth::InsufficientScopeError] + Gitlab::Auth::InsufficientScopeError,] base.__send__(:rescue_from, *error_classes, oauth2_bearer_token_error_handler) # rubocop:disable GitlabSecurity/PublicSend end @@ -110,22 +110,26 @@ module API when Gitlab::Auth::TokenNotFoundError Rack::OAuth2::Server::Resource::Bearer::Unauthorized.new( :invalid_token, - "Bad Access Token.") + "Bad Access Token." + ) when Gitlab::Auth::ExpiredError Rack::OAuth2::Server::Resource::Bearer::Unauthorized.new( :invalid_token, - "Token is expired. You can either do re-authorization or token refresh.") + "Token is expired. You can either do re-authorization or token refresh." + ) when Gitlab::Auth::RevokedError Rack::OAuth2::Server::Resource::Bearer::Unauthorized.new( :invalid_token, - "Token was revoked. You have to re-authorize from the user.") + "Token was revoked. You have to re-authorize from the user." + ) when Gitlab::Auth::ImpersonationDisabled Rack::OAuth2::Server::Resource::Bearer::Unauthorized.new( :invalid_token, - "Token is an impersonation token but impersonation was disabled.") + "Token is an impersonation token but impersonation was disabled." + ) when Gitlab::Auth::InsufficientScopeError # FIXME: ForbiddenError (inherited from Bearer::Forbidden of Rack::Oauth2) @@ -133,7 +137,8 @@ module API Rack::OAuth2::Server::Resource::Bearer::Forbidden.new( :insufficient_scope, Rack::OAuth2::Server::Resource::ErrorMethods::DEFAULT_DESCRIPTION[:insufficient_scope], - { scope: e.scopes }) + {scope: e.scopes} + ) end response.finish diff --git a/lib/api/applications.rb b/lib/api/applications.rb index 92717e04543..7d150196a6c 100644 --- a/lib/api/applications.rb +++ b/lib/api/applications.rb @@ -6,14 +6,14 @@ module API before { authenticated_as_admin! } resource :applications do - desc 'Create a new application' do - detail 'This feature was introduced in GitLab 10.5' + desc "Create a new application" do + detail "This feature was introduced in GitLab 10.5" success Entities::ApplicationWithSecret end params do - requires :name, type: String, desc: 'Application name' - requires :redirect_uri, type: String, desc: 'Application redirect URI' - requires :scopes, type: String, desc: 'Application scopes' + requires :name, type: String, desc: "Application name" + requires :redirect_uri, type: String, desc: "Application redirect URI" + requires :scopes, type: String, desc: "Application scopes" end post do application = Doorkeeper::Application.new(declared_params) @@ -25,7 +25,7 @@ module API end end - desc 'Get applications' do + desc "Get applications" do success Entities::Application end get do @@ -33,8 +33,8 @@ module API present applications, with: Entities::Application end - desc 'Delete an application' - delete ':id' do + desc "Delete an application" + delete ":id" do application = ApplicationsFinder.new(params).execute application.destroy diff --git a/lib/api/avatar.rb b/lib/api/avatar.rb index 0f14d003065..d05481c7a4f 100644 --- a/lib/api/avatar.rb +++ b/lib/api/avatar.rb @@ -3,15 +3,15 @@ module API class Avatar < Grape::API resource :avatar do - desc 'Return avatar url for a user' do + desc "Return avatar url for a user" do success Entities::Avatar end params do - requires :email, type: String, desc: 'Public email address of the user' - optional :size, type: Integer, desc: 'Single pixel dimension for Gravatar images' + requires :email, type: String, desc: "Public email address of the user" + optional :size, type: Integer, desc: "Single pixel dimension for Gravatar images" end get do - forbidden!('Unauthorized access') unless can?(current_user, :read_users_list) + forbidden!("Unauthorized access") unless can?(current_user, :read_users_list) user = User.find_by_public_email(params[:email]) user ||= User.new(email: params[:email]) diff --git a/lib/api/award_emoji.rb b/lib/api/award_emoji.rb index a1851ba3627..a47948b1a29 100644 --- a/lib/api/award_emoji.rb +++ b/lib/api/award_emoji.rb @@ -6,13 +6,13 @@ module API before { authenticate! } AWARDABLES = [ - { type: 'issue', find_by: :iid }, - { type: 'merge_request', find_by: :iid }, - { type: 'snippet', find_by: :id } + {type: "issue", find_by: :iid}, + {type: "merge_request", find_by: :iid}, + {type: "snippet", find_by: :id}, ].freeze params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do AWARDABLES.each do |awardable_params| @@ -25,11 +25,11 @@ module API [ ":id/#{awardable_string}/:#{awardable_id_string}/award_emoji", - ":id/#{awardable_string}/:#{awardable_id_string}/notes/:note_id/award_emoji" + ":id/#{awardable_string}/:#{awardable_id_string}/notes/:note_id/award_emoji", ].each do |endpoint| - desc 'Get a list of project +awardable+ award emoji' do - detail 'This feature was introduced in 8.9' + desc "Get a list of project +awardable+ award emoji" do + detail "This feature was introduced in 8.9" success Entities::AwardEmoji end params do @@ -44,12 +44,12 @@ module API end end - desc 'Get a specific award emoji' do - detail 'This feature was introduced in 8.9' + desc "Get a specific award emoji" do + detail "This feature was introduced in 8.9" success Entities::AwardEmoji end params do - requires :award_id, type: Integer, desc: 'The ID of the award' + requires :award_id, type: Integer, desc: "The ID of the award" end get "#{endpoint}/:award_id" do if can_read_awardable? @@ -59,15 +59,15 @@ module API end end - desc 'Award a new Emoji' do - detail 'This feature was introduced in 8.9' + desc "Award a new Emoji" do + detail "This feature was introduced in 8.9" success Entities::AwardEmoji end params do - requires :name, type: String, desc: 'The name of a award_emoji (without colons)' + requires :name, type: String, desc: "The name of a award_emoji (without colons)" end post endpoint do - not_found!('Award Emoji') unless can_read_awardable? && can_award_awardable? + not_found!("Award Emoji") unless can_read_awardable? && can_award_awardable? award = awardable.create_award_emoji(params[:name], current_user) @@ -78,12 +78,12 @@ module API end end - desc 'Delete a +awardables+ award emoji' do - detail 'This feature was introduced in 8.9' + desc "Delete a +awardables+ award emoji" do + detail "This feature was introduced in 8.9" success Entities::AwardEmoji end params do - requires :award_id, type: Integer, desc: 'The ID of an award emoji' + requires :award_id, type: Integer, desc: "The ID of an award emoji" end delete "#{endpoint}/:award_id" do award = awardable.award_emoji.find(params[:award_id]) diff --git a/lib/api/badges.rb b/lib/api/badges.rb index ba554e00a16..b512e2fa1da 100644 --- a/lib/api/badges.rb +++ b/lib/api/badges.rb @@ -24,7 +24,7 @@ module API end resource source_type.pluralize, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do desc "Gets a list of #{source_type} badges viewable by the authenticated user." do - detail 'This feature was introduced in GitLab 10.6.' + detail "This feature was introduced in GitLab 10.6." success Entities::Badge end params do @@ -37,12 +37,12 @@ module API end desc "Preview a badge from a #{source_type}." do - detail 'This feature was introduced in GitLab 10.6.' + detail "This feature was introduced in GitLab 10.6." success Entities::BasicBadgeDetails end params do - requires :link_url, type: String, desc: 'URL of the badge link' - requires :image_url, type: String, desc: 'URL of the badge image' + requires :link_url, type: String, desc: "URL of the badge link" + requires :image_url, type: String, desc: "URL of the badge image" end get ":id/badges/render" do authenticate! @@ -50,7 +50,7 @@ module API source = find_source_if_admin(source_type) badge = ::Badges::BuildService.new(declared_params(include_missing: false)) - .execute(source) + .execute(source) if badge.valid? present_badges(source, badge, with: Entities::BasicBadgeDetails) @@ -60,11 +60,11 @@ module API end desc "Gets a badge of a #{source_type}." do - detail 'This feature was introduced in GitLab 10.6.' + detail "This feature was introduced in GitLab 10.6." success Entities::Badge end params do - requires :badge_id, type: Integer, desc: 'The badge ID' + requires :badge_id, type: Integer, desc: "The badge ID" end get ":id/badges/:badge_id" do source = find_source(source_type, params[:id]) @@ -74,12 +74,12 @@ module API end desc "Adds a badge to a #{source_type}." do - detail 'This feature was introduced in GitLab 10.6.' + detail "This feature was introduced in GitLab 10.6." success Entities::Badge end params do - requires :link_url, type: String, desc: 'URL of the badge link' - requires :image_url, type: String, desc: 'URL of the badge image' + requires :link_url, type: String, desc: "URL of the badge link" + requires :image_url, type: String, desc: "URL of the badge image" end post ":id/badges" do source = find_source_if_admin(source_type) @@ -94,18 +94,18 @@ module API end desc "Updates a badge of a #{source_type}." do - detail 'This feature was introduced in GitLab 10.6.' + detail "This feature was introduced in GitLab 10.6." success Entities::Badge end params do - optional :link_url, type: String, desc: 'URL of the badge link' - optional :image_url, type: String, desc: 'URL of the badge image' + optional :link_url, type: String, desc: "URL of the badge link" + optional :image_url, type: String, desc: "URL of the badge image" end put ":id/badges/:badge_id" do source = find_source_if_admin(source_type) badge = ::Badges::UpdateService.new(declared_params(include_missing: false)) - .execute(find_badge(source)) + .execute(find_badge(source)) if badge.valid? present_badges(source, badge) @@ -114,18 +114,18 @@ module API end end - desc 'Removes a badge from a project or group.' do - detail 'This feature was introduced in GitLab 10.6.' + desc "Removes a badge from a project or group." do + detail "This feature was introduced in GitLab 10.6." end params do - requires :badge_id, type: Integer, desc: 'The badge ID' + requires :badge_id, type: Integer, desc: "The badge ID" end delete ":id/badges/:badge_id" do source = find_source_if_admin(source_type) badge = find_badge(source) if badge.is_a?(GroupBadge) && source.is_a?(Project) - error!('To delete a Group badge please use the Group endpoint', 403) + error!("To delete a Group badge please use the Group endpoint", 403) end destroy_conditionally!(badge) diff --git a/lib/api/boards.rb b/lib/api/boards.rb index b7c77730afb..ee7c2123e13 100644 --- a/lib/api/boards.rb +++ b/lib/api/boards.rb @@ -14,68 +14,68 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - segment ':id/boards' do - desc 'Get all project boards' do - detail 'This feature was introduced in 8.13' + segment ":id/boards" do + desc "Get all project boards" do + detail "This feature was introduced in 8.13" success Entities::Board end params do use :pagination end - get '/' do + get "/" do authorize!(:read_board, user_project) present paginate(board_parent.boards), with: Entities::Board end - desc 'Find a project board' do - detail 'This feature was introduced in 10.4' + desc "Find a project board" do + detail "This feature was introduced in 10.4" success Entities::Board end - get '/:board_id' do + get "/:board_id" do authorize!(:read_board, user_project) present board, with: Entities::Board end end params do - requires :board_id, type: Integer, desc: 'The ID of a board' + requires :board_id, type: Integer, desc: "The ID of a board" end - segment ':id/boards/:board_id' do - desc 'Get the lists of a project board' do - detail 'Does not include `done` list. This feature was introduced in 8.13' + segment ":id/boards/:board_id" do + desc "Get the lists of a project board" do + detail "Does not include `done` list. This feature was introduced in 8.13" success Entities::List end params do use :pagination end - get '/lists' do + get "/lists" do authorize!(:read_board, user_project) present paginate(board_lists), with: Entities::List end - desc 'Get a list of a project board' do - detail 'This feature was introduced in 8.13' + desc "Get a list of a project board" do + detail "This feature was introduced in 8.13" success Entities::List end params do - requires :list_id, type: Integer, desc: 'The ID of a list' + requires :list_id, type: Integer, desc: "The ID of a list" end - get '/lists/:list_id' do + get "/lists/:list_id" do authorize!(:read_board, user_project) present board_lists.find(params[:list_id]), with: Entities::List end - desc 'Create a new board list' do - detail 'This feature was introduced in 8.13' + desc "Create a new board list" do + detail "This feature was introduced in 8.13" success Entities::List end params do use :list_creation_params end - post '/lists' do + post "/lists" do authorize_list_type_resource! authorize!(:admin_list, user_project) @@ -83,15 +83,15 @@ module API create_list end - desc 'Moves a board list to a new position' do - detail 'This feature was introduced in 8.13' + desc "Moves a board list to a new position" do + detail "This feature was introduced in 8.13" success Entities::List end params do - requires :list_id, type: Integer, desc: 'The ID of a list' - requires :position, type: Integer, desc: 'The position of the list' + requires :list_id, type: Integer, desc: "The ID of a list" + requires :position, type: Integer, desc: "The position of the list" end - put '/lists/:list_id' do + put "/lists/:list_id" do list = board_lists.find(params[:list_id]) authorize!(:admin_list, user_project) @@ -99,12 +99,12 @@ module API move_list(list) end - desc 'Delete a board list' do - detail 'This feature was introduced in 8.13' + desc "Delete a board list" do + detail "This feature was introduced in 8.13" success Entities::List end params do - requires :list_id, type: Integer, desc: 'The ID of a board list' + requires :list_id, type: Integer, desc: "The ID of a board list" end delete "/lists/:list_id" do authorize!(:admin_list, user_project) diff --git a/lib/api/boards_responses.rb b/lib/api/boards_responses.rb index 86d9b24802f..0c0643ad9e1 100644 --- a/lib/api/boards_responses.rb +++ b/lib/api/boards_responses.rb @@ -33,12 +33,12 @@ module API def move_list(list) move_list_service = - ::Boards::Lists::MoveService.new(board_parent, current_user, { position: params[:position].to_i }) + ::Boards::Lists::MoveService.new(board_parent, current_user, {position: params[:position].to_i}) if move_list_service.execute(list) present list, with: Entities::List else - render_api_error!({ error: "List could not be moved!" }, 400) + render_api_error!({error: "List could not be moved!"}, 400) end end @@ -46,7 +46,7 @@ module API destroy_conditionally!(list) do |list| service = ::Boards::Lists::DestroyService.new(board_parent, current_user) unless service.execute(list) - render_api_error!({ error: 'List could not be deleted!' }, 400) + render_api_error!({error: "List could not be deleted!"}, 400) end end end @@ -54,13 +54,13 @@ module API # rubocop: disable CodeReuse/ActiveRecord def authorize_list_type_resource! unless available_labels_for(board_parent).exists?(params[:label_id]) - render_api_error!({ error: 'Label not found!' }, 400) + render_api_error!({error: "Label not found!"}, 400) end end # rubocop: enable CodeReuse/ActiveRecord params :list_creation_params do - requires :label_id, type: Integer, desc: 'The ID of an existing label' + requires :label_id, type: Integer, desc: "The ID of an existing label" end end end diff --git a/lib/api/branches.rb b/lib/api/branches.rb index 07f529b01bb..f0be2a78ab6 100644 --- a/lib/api/branches.rb +++ b/lib/api/branches.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'mime/types' +require "mime/types" module API class Branches < Grape::API @@ -12,24 +12,24 @@ module API helpers do params :filter_params do - optional :search, type: String, desc: 'Return list of branches matching the search criteria' - optional :sort, type: String, desc: 'Return list of branches sorted by the given field' + optional :search, type: String, desc: "Return list of branches matching the search criteria" + optional :sort, type: String, desc: "Return list of branches sorted by the given field" end end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get a project repository branches' do + desc "Get a project repository branches" do success Entities::Branch end params do use :pagination use :filter_params end - get ':id/repository/branches' do - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42329') + get ":id/repository/branches" do + Gitlab::QueryLimiting.whitelist("https://gitlab.com/gitlab-org/gitlab-ce/issues/42329") repository = user_project.repository @@ -46,12 +46,12 @@ module API ) end - resource ':id/repository/branches/:branch', requirements: BRANCH_ENDPOINT_REQUIREMENTS do - desc 'Get a single branch' do + resource ":id/repository/branches/:branch", requirements: BRANCH_ENDPOINT_REQUIREMENTS do + desc "Get a single branch" do success Entities::Branch end params do - requires :branch, type: String, desc: 'The name of the branch' + requires :branch, type: String, desc: "The name of the branch" end head do user_project.repository.branch_exists?(params[:branch]) ? status(204) : status(404) @@ -67,16 +67,16 @@ module API # Note: The internal data model moved from `developers_can_{merge,push}` to `allowed_to_{merge,push}` # in `gitlab-org/gitlab-ce!5081`. The API interface has not been changed (to maintain compatibility), # but it works with the changed data model to infer `developers_can_merge` and `developers_can_push`. - desc 'Protect a single branch' do + desc "Protect a single branch" do success Entities::Branch end params do - requires :branch, type: String, desc: 'The name of the branch', allow_blank: false - optional :developers_can_push, type: Boolean, desc: 'Flag if developers can push to that branch' - optional :developers_can_merge, type: Boolean, desc: 'Flag if developers can merge to that branch' + requires :branch, type: String, desc: "The name of the branch", allow_blank: false + optional :developers_can_push, type: Boolean, desc: "Flag if developers can push to that branch" + optional :developers_can_merge, type: Boolean, desc: "Flag if developers can merge to that branch" end # rubocop: disable CodeReuse/ActiveRecord - put ':id/repository/branches/:branch/protect', requirements: BRANCH_ENDPOINT_REQUIREMENTS do + put ":id/repository/branches/:branch/protect", requirements: BRANCH_ENDPOINT_REQUIREMENTS do authorize_admin_project branch = find_branch!(params[:branch]) @@ -86,16 +86,16 @@ module API protected_branch_params = { name: branch.name, developers_can_push: params[:developers_can_push], - developers_can_merge: params[:developers_can_merge] + developers_can_merge: params[:developers_can_merge], } service_args = [user_project, current_user, protected_branch_params] protected_branch = if protected_branch - ::ProtectedBranches::LegacyApiUpdateService.new(*service_args).execute(protected_branch) - else - ::ProtectedBranches::LegacyApiCreateService.new(*service_args).execute - end + ::ProtectedBranches::LegacyApiUpdateService.new(*service_args).execute(protected_branch) + else + ::ProtectedBranches::LegacyApiCreateService.new(*service_args).execute + end if protected_branch.valid? present branch, with: Entities::Branch, current_user: current_user, project: user_project @@ -106,14 +106,14 @@ module API # rubocop: enable CodeReuse/ActiveRecord # Note: This API will be deprecated in favor of the protected branches API. - desc 'Unprotect a single branch' do + desc "Unprotect a single branch" do success Entities::Branch end params do - requires :branch, type: String, desc: 'The name of the branch', allow_blank: false + requires :branch, type: String, desc: "The name of the branch", allow_blank: false end # rubocop: disable CodeReuse/ActiveRecord - put ':id/repository/branches/:branch/unprotect', requirements: BRANCH_ENDPOINT_REQUIREMENTS do + put ":id/repository/branches/:branch/unprotect", requirements: BRANCH_ENDPOINT_REQUIREMENTS do authorize_admin_project branch = find_branch!(params[:branch]) @@ -124,34 +124,34 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Create branch' do + desc "Create branch" do success Entities::Branch end params do - requires :branch, type: String, desc: 'The name of the branch', allow_blank: false - requires :ref, type: String, desc: 'Create branch from commit sha or existing branch', allow_blank: false + requires :branch, type: String, desc: "The name of the branch", allow_blank: false + requires :ref, type: String, desc: "Create branch from commit sha or existing branch", allow_blank: false end - post ':id/repository/branches' do + post ":id/repository/branches" do authorize_push_project result = CreateBranchService.new(user_project, current_user) - .execute(params[:branch], params[:ref]) + .execute(params[:branch], params[:ref]) if result[:status] == :success present result[:branch], - with: Entities::Branch, - current_user: current_user, - project: user_project + with: Entities::Branch, + current_user: current_user, + project: user_project else render_api_error!(result[:message], 400) end end - desc 'Delete a branch' + desc "Delete a branch" params do - requires :branch, type: String, desc: 'The name of the branch', allow_blank: false + requires :branch, type: String, desc: "The name of the branch", allow_blank: false end - delete ':id/repository/branches/:branch', requirements: BRANCH_ENDPOINT_REQUIREMENTS do + delete ":id/repository/branches/:branch", requirements: BRANCH_ENDPOINT_REQUIREMENTS do authorize_push_project branch = find_branch!(params[:branch]) @@ -160,7 +160,7 @@ module API destroy_conditionally!(commit, last_updated: commit.authored_date) do result = DeleteBranchService.new(user_project, current_user) - .execute(params[:branch]) + .execute(params[:branch]) if result[:status] != :success render_api_error!(result[:message], result[:return_code]) @@ -168,8 +168,8 @@ module API end end - desc 'Delete all merged branches' - delete ':id/repository/merged_branches' do + desc "Delete all merged branches" + delete ":id/repository/merged_branches" do DeleteMergedBranchesService.new(user_project, current_user).async_execute accepted! diff --git a/lib/api/broadcast_messages.rb b/lib/api/broadcast_messages.rb index 19148758fc5..2855e2e5fac 100644 --- a/lib/api/broadcast_messages.rb +++ b/lib/api/broadcast_messages.rb @@ -14,8 +14,8 @@ module API end end - desc 'Get all broadcast messages' do - detail 'This feature was introduced in GitLab 8.12.' + desc "Get all broadcast messages" do + detail "This feature was introduced in GitLab 8.12." success Entities::BroadcastMessage end params do @@ -27,16 +27,16 @@ module API present paginate(messages), with: Entities::BroadcastMessage end - desc 'Create a broadcast message' do - detail 'This feature was introduced in GitLab 8.12.' + desc "Create a broadcast message" do + detail "This feature was introduced in GitLab 8.12." success Entities::BroadcastMessage end params do - requires :message, type: String, desc: 'Message to display' - optional :starts_at, type: DateTime, desc: 'Starting time', default: -> { Time.zone.now } - optional :ends_at, type: DateTime, desc: 'Ending time', default: -> { 1.hour.from_now } - optional :color, type: String, desc: 'Background color' - optional :font, type: String, desc: 'Foreground color' + requires :message, type: String, desc: "Message to display" + optional :starts_at, type: DateTime, desc: "Starting time", default: -> { Time.zone.now } + optional :ends_at, type: DateTime, desc: "Ending time", default: -> { 1.hour.from_now } + optional :color, type: String, desc: "Background color" + optional :font, type: String, desc: "Foreground color" end post do message = BroadcastMessage.create(declared_params(include_missing: false)) @@ -48,32 +48,32 @@ module API end end - desc 'Get a specific broadcast message' do - detail 'This feature was introduced in GitLab 8.12.' + desc "Get a specific broadcast message" do + detail "This feature was introduced in GitLab 8.12." success Entities::BroadcastMessage end params do - requires :id, type: Integer, desc: 'Broadcast message ID' + requires :id, type: Integer, desc: "Broadcast message ID" end - get ':id' do + get ":id" do message = find_message present message, with: Entities::BroadcastMessage end - desc 'Update a broadcast message' do - detail 'This feature was introduced in GitLab 8.12.' + desc "Update a broadcast message" do + detail "This feature was introduced in GitLab 8.12." success Entities::BroadcastMessage end params do - requires :id, type: Integer, desc: 'Broadcast message ID' - optional :message, type: String, desc: 'Message to display' - optional :starts_at, type: DateTime, desc: 'Starting time' - optional :ends_at, type: DateTime, desc: 'Ending time' - optional :color, type: String, desc: 'Background color' - optional :font, type: String, desc: 'Foreground color' - end - put ':id' do + requires :id, type: Integer, desc: "Broadcast message ID" + optional :message, type: String, desc: "Message to display" + optional :starts_at, type: DateTime, desc: "Starting time" + optional :ends_at, type: DateTime, desc: "Ending time" + optional :color, type: String, desc: "Background color" + optional :font, type: String, desc: "Foreground color" + end + put ":id" do message = find_message if message.update(declared_params(include_missing: false)) @@ -83,14 +83,14 @@ module API end end - desc 'Delete a broadcast message' do - detail 'This feature was introduced in GitLab 8.12.' + desc "Delete a broadcast message" do + detail "This feature was introduced in GitLab 8.12." success Entities::BroadcastMessage end params do - requires :id, type: Integer, desc: 'Broadcast message ID' + requires :id, type: Integer, desc: "Broadcast message ID" end - delete ':id' do + delete ":id" do message = find_message destroy_conditionally!(message) diff --git a/lib/api/circuit_breakers.rb b/lib/api/circuit_breakers.rb index da756daadcc..202fe410918 100644 --- a/lib/api/circuit_breakers.rb +++ b/lib/api/circuit_breakers.rb @@ -7,28 +7,28 @@ module API resource :circuit_breakers do params do requires :type, - type: String, - desc: "The type of circuitbreaker", - values: ['repository_storage'] + type: String, + desc: "The type of circuitbreaker", + values: ["repository_storage"] end - resource ':type' do - namespace '', requirements: { type: 'repository_storage' } do - desc 'Get all git storages' do - detail 'This feature was introduced in GitLab 9.5' + resource ":type" do + namespace "", requirements: {type: "repository_storage"} do + desc "Get all git storages" do + detail "This feature was introduced in GitLab 9.5" end get do present [] end - desc 'Get all failing git storages' do - detail 'This feature was introduced in GitLab 9.5' + desc "Get all failing git storages" do + detail "This feature was introduced in GitLab 9.5" end - get 'failing' do + get "failing" do present [] end - desc 'Reset all storage failures and open circuitbreaker' do - detail 'This feature was introduced in GitLab 9.5' + desc "Reset all storage failures and open circuitbreaker" do + detail "This feature was introduced in GitLab 9.5" end delete do end diff --git a/lib/api/commit_statuses.rb b/lib/api/commit_statuses.rb index 08b4f8db8b0..205c8e0ff6a 100644 --- a/lib/api/commit_statuses.rb +++ b/lib/api/commit_statuses.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'mime/types' +require "mime/types" module API class CommitStatuses < Grape::API params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do include PaginationParams @@ -16,18 +16,18 @@ module API success Entities::CommitStatus end params do - requires :sha, type: String, desc: 'The commit hash' - optional :ref, type: String, desc: 'The ref' - optional :stage, type: String, desc: 'The stage' - optional :name, type: String, desc: 'The name' - optional :all, type: String, desc: 'Show all statuses, default: false' + requires :sha, type: String, desc: "The commit hash" + optional :ref, type: String, desc: "The ref" + optional :stage, type: String, desc: "The stage" + optional :name, type: String, desc: "The name" + optional :all, type: String, desc: "Show all statuses, default: false" use :pagination end # rubocop: disable CodeReuse/ActiveRecord - get ':id/repository/commits/:sha/statuses' do + get ":id/repository/commits/:sha/statuses" do authorize!(:read_commit_status, user_project) - not_found!('Commit') unless user_project.commit(params[:sha]) + not_found!("Commit") unless user_project.commit(params[:sha]) pipelines = user_project.ci_pipelines.where(sha: params[:sha]) statuses = ::CommitStatus.where(pipeline: pipelines) @@ -39,26 +39,26 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Post status to a commit' do + desc "Post status to a commit" do success Entities::CommitStatus end params do - requires :sha, type: String, desc: 'The commit hash' - requires :state, type: String, desc: 'The state of the status', - values: %w(pending running success failed canceled) - optional :ref, type: String, desc: 'The ref' - optional :target_url, type: String, desc: 'The target URL to associate with this status' - optional :description, type: String, desc: 'A short description of the status' + requires :sha, type: String, desc: "The commit hash" + requires :state, type: String, desc: "The state of the status", + values: %w[pending running success failed canceled] + optional :ref, type: String, desc: "The ref" + optional :target_url, type: String, desc: "The target URL to associate with this status" + optional :description, type: String, desc: "A short description of the status" optional :name, type: String, desc: 'A string label to differentiate this status from the status of other systems. Default: "default"' optional :context, type: String, desc: 'A string label to differentiate this status from the status of other systems. Default: "default"' - optional :coverage, type: Float, desc: 'The total code coverage' + optional :coverage, type: Float, desc: "The total code coverage" end # rubocop: disable CodeReuse/ActiveRecord - post ':id/statuses/:sha' do + post ":id/statuses/:sha" do authorize! :create_commit_status, user_project commit = @project.commit(params[:sha]) - not_found! 'Commit' unless commit + not_found! "Commit" unless commit # Since the CommitStatus is attached to Ci::Pipeline (in the future Pipeline) # We need to always have the pipeline object @@ -69,19 +69,18 @@ module API ref = params[:ref] ref ||= @project.repository.branch_names_contains(commit.sha).first - not_found! 'References for commit' unless ref + not_found! "References for commit" unless ref - name = params[:name] || params[:context] || 'default' + name = params[:name] || params[:context] || "default" pipeline = @project.pipeline_for(ref, commit.sha) - unless pipeline - pipeline = @project.ci_pipelines.create!( - source: :external, - sha: commit.sha, - ref: ref, - user: current_user, - protected: @project.protected_for?(ref)) - end + pipeline ||= @project.ci_pipelines.create!( + source: :external, + sha: commit.sha, + ref: ref, + user: current_user, + protected: @project.protected_for?(ref) + ) status = GenericCommitStatus.running_or_pending.find_or_initialize_by( project: @project, @@ -100,23 +99,25 @@ module API begin case params[:state] - when 'pending' + when "pending" status.enqueue! - when 'running' + when "running" status.enqueue status.run! - when 'success' + when "success" status.success! - when 'failed' + when "failed" status.drop!(:api_failure) - when 'canceled' + when "canceled" status.cancel! else - render_api_error!('invalid state', 400) + render_api_error!("invalid state", 400) end - MergeRequest.where(source_project: @project, source_branch: ref) - .update_all(head_pipeline_id: pipeline.id) if pipeline.latest? + if pipeline.latest? + MergeRequest.where(source_project: @project, source_branch: ref) + .update_all(head_pipeline_id: pipeline.id) + end present status, with: Entities::CommitStatus rescue StateMachines::InvalidTransition => e diff --git a/lib/api/commits.rb b/lib/api/commits.rb index 8defc59224d..a38d476b122 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'mime/types' +require "mime/types" module API class Commits < Grape::API @@ -21,37 +21,37 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get a project repository commits' do + desc "Get a project repository commits" do success Entities::Commit end params do - optional :ref_name, type: String, desc: 'The name of a repository branch or tag, if not given the default branch is used' - optional :since, type: DateTime, desc: 'Only commits after or on this date will be returned' - optional :until, type: DateTime, desc: 'Only commits before or on this date will be returned' - optional :path, type: String, desc: 'The file path' - optional :all, type: Boolean, desc: 'Every commit will be returned' - optional :with_stats, type: Boolean, desc: 'Stats about each commit will be added to the response' + optional :ref_name, type: String, desc: "The name of a repository branch or tag, if not given the default branch is used" + optional :since, type: DateTime, desc: "Only commits after or on this date will be returned" + optional :until, type: DateTime, desc: "Only commits before or on this date will be returned" + optional :path, type: String, desc: "The file path" + optional :all, type: Boolean, desc: "Every commit will be returned" + optional :with_stats, type: Boolean, desc: "Stats about each commit will be added to the response" use :pagination end - get ':id/repository/commits' do + get ":id/repository/commits" do path = params[:path] before = params[:until] after = params[:since] - ref = params[:ref_name] || user_project.try(:default_branch) || 'master' unless params[:all] + ref = params[:ref_name] || user_project.try(:default_branch) || "master" unless params[:all] offset = (params[:page] - 1) * params[:per_page] all = params[:all] with_stats = params[:with_stats] commits = user_project.repository.commits(ref, - path: path, - limit: params[:per_page], - offset: offset, - before: before, - after: after, - all: all) + path: path, + limit: params[:per_page], + offset: offset, + before: before, + after: after, + all: all) commit_count = if all || path || before || after @@ -68,39 +68,39 @@ module API present paginate(paginated_commits), with: serializer end - desc 'Commit multiple file changes as one commit' do + desc "Commit multiple file changes as one commit" do success Entities::CommitDetail - detail 'This feature was introduced in GitLab 8.13' + detail "This feature was introduced in GitLab 8.13" end params do - requires :branch, type: String, desc: 'Name of the branch to commit into. To create a new branch, also provide `start_branch`.', allow_blank: false - requires :commit_message, type: String, desc: 'Commit message' - requires :actions, type: Array, desc: 'Actions to perform in commit' do - requires :action, type: String, desc: 'The action to perform, `create`, `delete`, `move`, `update`, `chmod`', values: %w[create update move delete chmod].freeze - requires :file_path, type: String, desc: 'Full path to the file. Ex. `lib/class.rb`' - given action: ->(action) { action == 'move' } do - requires :previous_path, type: String, desc: 'Original full path to the file being moved. Ex. `lib/class1.rb`' + requires :branch, type: String, desc: "Name of the branch to commit into. To create a new branch, also provide `start_branch`.", allow_blank: false + requires :commit_message, type: String, desc: "Commit message" + requires :actions, type: Array, desc: "Actions to perform in commit" do + requires :action, type: String, desc: "The action to perform, `create`, `delete`, `move`, `update`, `chmod`", values: %w[create update move delete chmod].freeze + requires :file_path, type: String, desc: "Full path to the file. Ex. `lib/class.rb`" + given action: ->(action) { action == "move" } do + requires :previous_path, type: String, desc: "Original full path to the file being moved. Ex. `lib/class1.rb`" end given action: ->(action) { %w[create move].include? action } do - optional :content, type: String, desc: 'File content' + optional :content, type: String, desc: "File content" end - given action: ->(action) { action == 'update' } do - requires :content, type: String, desc: 'File content' + given action: ->(action) { action == "update" } do + requires :content, type: String, desc: "File content" end - optional :encoding, type: String, desc: '`text` or `base64`', default: 'text', values: %w[text base64] + optional :encoding, type: String, desc: "`text` or `base64`", default: "text", values: %w[text base64] given action: ->(action) { %w[update move delete].include? action } do - optional :last_commit_id, type: String, desc: 'Last known file commit id' + optional :last_commit_id, type: String, desc: "Last known file commit id" end - given action: ->(action) { action == 'chmod' } do - requires :execute_filemode, type: Boolean, desc: 'When `true/false` enables/disables the execute flag on the file.' + given action: ->(action) { action == "chmod" } do + requires :execute_filemode, type: Boolean, desc: "When `true/false` enables/disables the execute flag on the file." end end - optional :start_branch, type: String, desc: 'Name of the branch to start the new commit from' - optional :author_email, type: String, desc: 'Author email for commit' - optional :author_name, type: String, desc: 'Author name for commit' - optional :stats, type: Boolean, default: true, desc: 'Include commit stats' + optional :start_branch, type: String, desc: "Name of the branch to start the new commit from" + optional :author_email, type: String, desc: "Author email for commit" + optional :author_name, type: String, desc: "Author name for commit" + optional :stats, type: Boolean, default: true, desc: "Include commit stats" end - post ':id/repository/commits' do + post ":id/repository/commits" do authorize_push_to_branch!(params[:branch]) attrs = declared_params @@ -120,33 +120,33 @@ module API end end - desc 'Get a specific commit of a project' do + desc "Get a specific commit of a project" do success Entities::CommitDetail - failure [[404, 'Commit Not Found']] + failure [[404, "Commit Not Found"]] end params do - requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag' - optional :stats, type: Boolean, default: true, desc: 'Include commit stats' + requires :sha, type: String, desc: "A commit sha, or the name of a branch or tag" + optional :stats, type: Boolean, default: true, desc: "Include commit stats" end - get ':id/repository/commits/:sha', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do + get ":id/repository/commits/:sha", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do commit = user_project.commit(params[:sha]) - not_found! 'Commit' unless commit + not_found! "Commit" unless commit present commit, with: Entities::CommitDetail, stats: params[:stats] end - desc 'Get the diff for a specific commit of a project' do - failure [[404, 'Commit Not Found']] + desc "Get the diff for a specific commit of a project" do + failure [[404, "Commit Not Found"]] end params do - requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag' + requires :sha, type: String, desc: "A commit sha, or the name of a branch or tag" use :pagination end - get ':id/repository/commits/:sha/diff', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do + get ":id/repository/commits/:sha/diff", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do commit = user_project.commit(params[:sha]) - not_found! 'Commit' unless commit + not_found! "Commit" unless commit raw_diffs = ::Kaminari.paginate_array(commit.raw_diffs.to_a) @@ -155,43 +155,43 @@ module API desc "Get a commit's comments" do success Entities::CommitNote - failure [[404, 'Commit Not Found']] + failure [[404, "Commit Not Found"]] end params do use :pagination - requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag' + requires :sha, type: String, desc: "A commit sha, or the name of a branch or tag" end # rubocop: disable CodeReuse/ActiveRecord - get ':id/repository/commits/:sha/comments', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do + get ":id/repository/commits/:sha/comments", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do commit = user_project.commit(params[:sha]) - not_found! 'Commit' unless commit + not_found! "Commit" unless commit notes = commit.notes.order(:created_at) present paginate(notes), with: Entities::CommitNote end # rubocop: enable CodeReuse/ActiveRecord - desc 'Cherry pick commit into a branch' do - detail 'This feature was introduced in GitLab 8.15' + desc "Cherry pick commit into a branch" do + detail "This feature was introduced in GitLab 8.15" success Entities::Commit end params do - requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag to be cherry picked' - requires :branch, type: String, desc: 'The name of the branch', allow_blank: false + requires :sha, type: String, desc: "A commit sha, or the name of a branch or tag to be cherry picked" + requires :branch, type: String, desc: "The name of the branch", allow_blank: false end - post ':id/repository/commits/:sha/cherry_pick', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do + post ":id/repository/commits/:sha/cherry_pick", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do authorize_push_to_branch!(params[:branch]) commit = user_project.commit(params[:sha]) - not_found!('Commit') unless commit + not_found!("Commit") unless commit find_branch!(params[:branch]) commit_params = { commit: commit, start_branch: params[:branch], - branch_name: params[:branch] + branch_name: params[:branch], } result = ::Commits::CherryPickService @@ -206,26 +206,26 @@ module API end end - desc 'Revert a commit in a branch' do - detail 'This feature was introduced in GitLab 11.5' + desc "Revert a commit in a branch" do + detail "This feature was introduced in GitLab 11.5" success Entities::Commit end params do - requires :sha, type: String, desc: 'Commit SHA to revert' - requires :branch, type: String, desc: 'Target branch name', allow_blank: false + requires :sha, type: String, desc: "Commit SHA to revert" + requires :branch, type: String, desc: "Target branch name", allow_blank: false end - post ':id/repository/commits/:sha/revert', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do + post ":id/repository/commits/:sha/revert", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do authorize_push_to_branch!(params[:branch]) commit = user_project.commit(params[:sha]) - not_found!('Commit') unless commit + not_found!("Commit") unless commit find_branch!(params[:branch]) commit_params = { commit: commit, start_branch: params[:branch], - branch_name: params[:branch] + branch_name: params[:branch], } result = ::Commits::RevertService @@ -240,47 +240,47 @@ module API end end - desc 'Get all references a commit is pushed to' do - detail 'This feature was introduced in GitLab 10.6' + desc "Get all references a commit is pushed to" do + detail "This feature was introduced in GitLab 10.6" success Entities::BasicRef end params do - requires :sha, type: String, desc: 'A commit sha' - optional :type, type: String, values: %w[branch tag all], default: 'all', desc: 'Scope' + requires :sha, type: String, desc: "A commit sha" + optional :type, type: String, values: %w[branch tag all], default: "all", desc: "Scope" use :pagination end - get ':id/repository/commits/:sha/refs', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do + get ":id/repository/commits/:sha/refs", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do commit = user_project.commit(params[:sha]) - not_found!('Commit') unless commit + not_found!("Commit") unless commit refs = [] - refs.concat(user_project.repository.branch_names_contains(commit.id).map {|name| { type: 'branch', name: name }}) unless params[:type] == 'tag' - refs.concat(user_project.repository.tag_names_contains(commit.id).map {|name| { type: 'tag', name: name }}) unless params[:type] == 'branch' + refs.concat(user_project.repository.branch_names_contains(commit.id).map {|name| {type: "branch", name: name}}) unless params[:type] == "tag" + refs.concat(user_project.repository.tag_names_contains(commit.id).map {|name| {type: "tag", name: name}}) unless params[:type] == "branch" refs = Kaminari.paginate_array(refs) present paginate(refs), with: Entities::BasicRef end - desc 'Post comment to commit' do + desc "Post comment to commit" do success Entities::CommitNote end params do - requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag on which to post a comment' - requires :note, type: String, desc: 'The text of the comment' - optional :path, type: String, desc: 'The file path' + requires :sha, type: String, desc: "A commit sha, or the name of a branch or tag on which to post a comment" + requires :note, type: String, desc: "The text of the comment" + optional :path, type: String, desc: "The file path" given :path do - requires :line, type: Integer, desc: 'The line number' - requires :line_type, type: String, values: %w[new old], default: 'new', desc: 'The type of the line' + requires :line, type: Integer, desc: "The line number" + requires :line_type, type: String, values: %w[new old], default: "new", desc: "The type of the line" end end - post ':id/repository/commits/:sha/comments', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do + post ":id/repository/commits/:sha/comments", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do commit = user_project.commit(params[:sha]) - not_found! 'Commit' unless commit + not_found! "Commit" unless commit opts = { note: params[:note], - noteable_type: 'Commit', - commit_id: commit.id + noteable_type: "Commit", + commit_id: commit.id, } if params[:path] @@ -310,16 +310,16 @@ module API end end - desc 'Get Merge Requests associated with a commit' do + desc "Get Merge Requests associated with a commit" do success Entities::MergeRequestBasic end params do - requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag on which to find Merge Requests' + requires :sha, type: String, desc: "A commit sha, or the name of a branch or tag on which to find Merge Requests" use :pagination end - get ':id/repository/commits/:sha/merge_requests', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do + get ":id/repository/commits/:sha/merge_requests", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do commit = user_project.commit(params[:sha]) - not_found! 'Commit' unless commit + not_found! "Commit" unless commit present paginate(commit.merge_requests), with: Entities::MergeRequestBasic end @@ -328,14 +328,14 @@ module API success Entities::CommitSignature end params do - requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag' + requires :sha, type: String, desc: "A commit sha, or the name of a branch or tag" end - get ':id/repository/commits/:sha/signature', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do + get ":id/repository/commits/:sha/signature", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do commit = user_project.commit(params[:sha]) - not_found! 'Commit' unless commit + not_found! "Commit" unless commit signature = commit.signature - not_found! 'GPG Signature' unless signature + not_found! "GPG Signature" unless signature present signature, with: Entities::CommitSignature end diff --git a/lib/api/container_registry.rb b/lib/api/container_registry.rb index e4493910196..3e387d05e47 100644 --- a/lib/api/container_registry.rb +++ b/lib/api/container_registry.rb @@ -5,35 +5,36 @@ module API include PaginationParams REGISTRY_ENDPOINT_REQUIREMENTS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS.merge( - tag_name: API::NO_SLASH_URL_PART_REGEX) + tag_name: API::NO_SLASH_URL_PART_REGEX + ) - before { error!('404 Not Found', 404) unless Feature.enabled?(:container_registry_api, user_project, default_enabled: true) } + before { error!("404 Not Found", 404) unless Feature.enabled?(:container_registry_api, user_project, default_enabled: true) } before { authorize_read_container_images! } params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get a project container repositories' do - detail 'This feature was introduced in GitLab 11.8.' + desc "Get a project container repositories" do + detail "This feature was introduced in GitLab 11.8." success Entities::ContainerRegistry::Repository end params do use :pagination end - get ':id/registry/repositories' do + get ":id/registry/repositories" do repositories = user_project.container_repositories.ordered present paginate(repositories), with: Entities::ContainerRegistry::Repository end - desc 'Delete repository' do - detail 'This feature was introduced in GitLab 11.8.' + desc "Delete repository" do + detail "This feature was introduced in GitLab 11.8." end params do - requires :repository_id, type: Integer, desc: 'The ID of the repository' + requires :repository_id, type: Integer, desc: "The ID of the repository" end - delete ':id/registry/repositories/:repository_id', requirements: REGISTRY_ENDPOINT_REQUIREMENTS do + delete ":id/registry/repositories/:repository_id", requirements: REGISTRY_ENDPOINT_REQUIREMENTS do authorize_admin_container_image! DeleteContainerRepositoryWorker.perform_async(current_user.id, repository.id) @@ -41,31 +42,31 @@ module API status :accepted end - desc 'Get a list of repositories tags' do - detail 'This feature was introduced in GitLab 11.8.' + desc "Get a list of repositories tags" do + detail "This feature was introduced in GitLab 11.8." success Entities::ContainerRegistry::Tag end params do - requires :repository_id, type: Integer, desc: 'The ID of the repository' + requires :repository_id, type: Integer, desc: "The ID of the repository" use :pagination end - get ':id/registry/repositories/:repository_id/tags', requirements: REGISTRY_ENDPOINT_REQUIREMENTS do + get ":id/registry/repositories/:repository_id/tags", requirements: REGISTRY_ENDPOINT_REQUIREMENTS do authorize_read_container_image! tags = Kaminari.paginate_array(repository.tags) present paginate(tags), with: Entities::ContainerRegistry::Tag end - desc 'Delete repository tags (in bulk)' do - detail 'This feature was introduced in GitLab 11.8.' + desc "Delete repository tags (in bulk)" do + detail "This feature was introduced in GitLab 11.8." end params do - requires :repository_id, type: Integer, desc: 'The ID of the repository' - requires :name_regex, type: String, desc: 'The tag name regexp to delete, specify .* to delete all' - optional :keep_n, type: Integer, desc: 'Keep n of latest tags with matching name' - optional :older_than, type: String, desc: 'Delete older than: 1h, 1d, 1month' + requires :repository_id, type: Integer, desc: "The ID of the repository" + requires :name_regex, type: String, desc: "The tag name regexp to delete, specify .* to delete all" + optional :keep_n, type: Integer, desc: "Keep n of latest tags with matching name" + optional :older_than, type: String, desc: "Delete older than: 1h, 1d, 1month" end - delete ':id/registry/repositories/:repository_id/tags', requirements: REGISTRY_ENDPOINT_REQUIREMENTS do + delete ":id/registry/repositories/:repository_id/tags", requirements: REGISTRY_ENDPOINT_REQUIREMENTS do authorize_admin_container_image! CleanupContainerRepositoryWorker.perform_async(current_user.id, repository.id, @@ -74,29 +75,29 @@ module API status :accepted end - desc 'Get a details about repository tag' do - detail 'This feature was introduced in GitLab 11.8.' + desc "Get a details about repository tag" do + detail "This feature was introduced in GitLab 11.8." success Entities::ContainerRegistry::TagDetails end params do - requires :repository_id, type: Integer, desc: 'The ID of the repository' - requires :tag_name, type: String, desc: 'The name of the tag' + requires :repository_id, type: Integer, desc: "The ID of the repository" + requires :tag_name, type: String, desc: "The name of the tag" end - get ':id/registry/repositories/:repository_id/tags/:tag_name', requirements: REGISTRY_ENDPOINT_REQUIREMENTS do + get ":id/registry/repositories/:repository_id/tags/:tag_name", requirements: REGISTRY_ENDPOINT_REQUIREMENTS do authorize_read_container_image! validate_tag! present tag, with: Entities::ContainerRegistry::TagDetails end - desc 'Delete repository tag' do - detail 'This feature was introduced in GitLab 11.8.' + desc "Delete repository tag" do + detail "This feature was introduced in GitLab 11.8." end params do - requires :repository_id, type: Integer, desc: 'The ID of the repository' - requires :tag_name, type: String, desc: 'The name of the tag' + requires :repository_id, type: Integer, desc: "The ID of the repository" + requires :tag_name, type: String, desc: "The name of the tag" end - delete ':id/registry/repositories/:repository_id/tags/:tag_name', requirements: REGISTRY_ENDPOINT_REQUIREMENTS do + delete ":id/registry/repositories/:repository_id/tags/:tag_name", requirements: REGISTRY_ENDPOINT_REQUIREMENTS do authorize_destroy_container_image! validate_tag! @@ -136,7 +137,7 @@ module API end def validate_tag! - not_found!('Tag') unless tag.valid? + not_found!("Tag") unless tag.valid? end end end diff --git a/lib/api/custom_attributes_endpoints.rb b/lib/api/custom_attributes_endpoints.rb index 2149e04451e..d697d8b9f88 100644 --- a/lib/api/custom_attributes_endpoints.rb +++ b/lib/api/custom_attributes_endpoints.rb @@ -12,14 +12,14 @@ module API helpers do params :custom_attributes_key do - requires :key, type: String, desc: 'The key of the custom attribute' + requires :key, type: String, desc: "The key of the custom attribute" end end desc "Get all custom attributes on a #{attributable_name}" do success Entities::CustomAttribute end - get ':id/custom_attributes' do + get ":id/custom_attributes" do resource = public_send(attributable_finder, params[:id]) # rubocop:disable GitlabSecurity/PublicSend authorize! :read_custom_attribute @@ -33,7 +33,7 @@ module API use :custom_attributes_key end # rubocop: disable CodeReuse/ActiveRecord - get ':id/custom_attributes/:key' do + get ":id/custom_attributes/:key" do resource = public_send(attributable_finder, params[:id]) # rubocop:disable GitlabSecurity/PublicSend authorize! :read_custom_attribute @@ -46,10 +46,10 @@ module API desc "Set a custom attribute on a #{attributable_name}" params do use :custom_attributes_key - requires :value, type: String, desc: 'The value of the custom attribute' + requires :value, type: String, desc: "The value of the custom attribute" end # rubocop: disable CodeReuse/ActiveRecord - put ':id/custom_attributes/:key' do + put ":id/custom_attributes/:key" do resource = public_send(attributable_finder, params[:id]) # rubocop:disable GitlabSecurity/PublicSend authorize! :update_custom_attribute @@ -71,7 +71,7 @@ module API use :custom_attributes_key end # rubocop: disable CodeReuse/ActiveRecord - delete ':id/custom_attributes/:key' do + delete ":id/custom_attributes/:key" do resource = public_send(attributable_finder, params[:id]) # rubocop:disable GitlabSecurity/PublicSend authorize! :update_custom_attribute diff --git a/lib/api/deploy_keys.rb b/lib/api/deploy_keys.rb index df6d2721977..32256c726ec 100644 --- a/lib/api/deploy_keys.rb +++ b/lib/api/deploy_keys.rb @@ -18,7 +18,7 @@ module API # rubocop: enable CodeReuse/ActiveRecord end - desc 'Return all deploy keys' + desc "Return all deploy keys" params do use :pagination end @@ -29,7 +29,7 @@ module API end params do - requires :id, type: String, desc: 'The ID of the project' + requires :id, type: String, desc: "The ID of the project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do before { authorize_admin_project } @@ -48,11 +48,11 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get single deploy key' do + desc "Get single deploy key" do success Entities::DeployKeysProject end params do - requires :key_id, type: Integer, desc: 'The ID of the deploy key' + requires :key_id, type: Integer, desc: "The ID of the deploy key" end get ":id/deploy_keys/:key_id" do key = find_by_deploy_key(user_project, params[:key_id]) @@ -60,12 +60,12 @@ module API present key, with: Entities::DeployKeysProject end - desc 'Add new deploy key to a project' do + desc "Add new deploy key to a project" do success Entities::DeployKeysProject end params do - requires :key, type: String, desc: 'The new deploy key' - requires :title, type: String, desc: 'The name of the deploy key' + requires :key, type: String, desc: "The new deploy key" + requires :title, type: String, desc: "The name of the deploy key" optional :can_push, type: Boolean, desc: "Can deploy key push to the project's repository" end # rubocop: disable CodeReuse/ActiveRecord @@ -74,8 +74,8 @@ module API # Check for an existing key joined to this project deploy_key_project = user_project.deploy_keys_projects - .joins(:deploy_key) - .find_by(keys: { key: params[:key] }) + .joins(:deploy_key) + .find_by(keys: {key: params[:key]}) if deploy_key_project present deploy_key_project, with: Entities::DeployKeysProject @@ -103,12 +103,12 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Update an existing deploy key for a project' do + desc "Update an existing deploy key for a project" do success Entities::SSHKey end params do - requires :key_id, type: Integer, desc: 'The ID of the deploy key' - optional :title, type: String, desc: 'The name of the deploy key' + requires :key_id, type: Integer, desc: "The ID of the deploy key" + optional :title, type: String, desc: "The name of the deploy key" optional :can_push, type: Boolean, desc: "Can deploy key push to the project's repository" at_least_one_of :title, :can_push end @@ -121,8 +121,8 @@ module API title = params[:title] || deploy_keys_project.deploy_key.title result = deploy_keys_project.update(can_push: can_push, - deploy_key_attributes: { id: params[:key_id], - title: title }) + deploy_key_attributes: {id: params[:key_id], + title: title,}) if result present deploy_keys_project, with: Entities::DeployKeysProject @@ -131,34 +131,34 @@ module API end end - desc 'Enable a deploy key for a project' do - detail 'This feature was added in GitLab 8.11' + desc "Enable a deploy key for a project" do + detail "This feature was added in GitLab 8.11" success Entities::SSHKey end params do - requires :key_id, type: Integer, desc: 'The ID of the deploy key' + requires :key_id, type: Integer, desc: "The ID of the deploy key" end post ":id/deploy_keys/:key_id/enable" do key = ::Projects::EnableDeployKeyService.new(user_project, - current_user, declared_params).execute + current_user, declared_params).execute if key present key, with: Entities::SSHKey else - not_found!('Deploy Key') + not_found!("Deploy Key") end end - desc 'Delete deploy key for a project' do + desc "Delete deploy key for a project" do success Key end params do - requires :key_id, type: Integer, desc: 'The ID of the deploy key' + requires :key_id, type: Integer, desc: "The ID of the deploy key" end # rubocop: disable CodeReuse/ActiveRecord delete ":id/deploy_keys/:key_id" do deploy_key_project = user_project.deploy_keys_projects.find_by(deploy_key_id: params[:key_id]) - not_found!('Deploy Key') unless deploy_key_project + not_found!("Deploy Key") unless deploy_key_project destroy_conditionally!(deploy_key_project) end diff --git a/lib/api/deployments.rb b/lib/api/deployments.rb index eb45df31ff9..6deb89a6809 100644 --- a/lib/api/deployments.rb +++ b/lib/api/deployments.rb @@ -8,34 +8,34 @@ module API before { authenticate! } params do - requires :id, type: String, desc: 'The project ID' + requires :id, type: String, desc: "The project ID" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get all deployments of the project' do - detail 'This feature was introduced in GitLab 8.11.' + desc "Get all deployments of the project" do + detail "This feature was introduced in GitLab 8.11." success Entities::Deployment end params do use :pagination - optional :order_by, type: String, values: %w[id iid created_at ref], default: 'id', desc: 'Return deployments ordered by `id` or `iid` or `created_at` or `ref`' - optional :sort, type: String, values: %w[asc desc], default: 'asc', desc: 'Sort by asc (ascending) or desc (descending)' + optional :order_by, type: String, values: %w[id iid created_at ref], default: "id", desc: "Return deployments ordered by `id` or `iid` or `created_at` or `ref`" + optional :sort, type: String, values: %w[asc desc], default: "asc", desc: "Sort by asc (ascending) or desc (descending)" end # rubocop: disable CodeReuse/ActiveRecord - get ':id/deployments' do + get ":id/deployments" do authorize! :read_deployment, user_project present paginate(user_project.deployments.order(params[:order_by] => params[:sort])), with: Entities::Deployment end # rubocop: enable CodeReuse/ActiveRecord - desc 'Gets a specific deployment' do - detail 'This feature was introduced in GitLab 8.11.' + desc "Gets a specific deployment" do + detail "This feature was introduced in GitLab 8.11." success Entities::Deployment end params do - requires :deployment_id, type: Integer, desc: 'The deployment ID' + requires :deployment_id, type: Integer, desc: "The deployment ID" end - get ':id/deployments/:deployment_id' do + get ":id/deployments/:deployment_id" do authorize! :read_deployment, user_project deployment = user_project.deployments.find(params[:deployment_id]) diff --git a/lib/api/discussions.rb b/lib/api/discussions.rb index 91eb6a23701..06d9c53c2ab 100644 --- a/lib/api/discussions.rb +++ b/lib/api/discussions.rb @@ -22,7 +22,7 @@ module API success Entities::Discussion end params do - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' + requires :noteable_id, types: [Integer, String], desc: "The ID of the noteable" use :pagination end # rubocop: disable CodeReuse/ActiveRecord @@ -45,8 +45,8 @@ module API success Entities::Discussion end params do - requires :discussion_id, type: String, desc: 'The ID of a discussion' - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' + requires :discussion_id, type: String, desc: "The ID of a discussion" + requires :noteable_id, types: [Integer, String], desc: "The ID of the noteable" end get ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id" do noteable = find_noteable(parent_type, noteables_str, params[:noteable_id]) @@ -65,36 +65,36 @@ module API success Entities::Discussion end params do - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' - requires :body, type: String, desc: 'The content of a note' - optional :created_at, type: String, desc: 'The creation date of the note' + requires :noteable_id, types: [Integer, String], desc: "The ID of the noteable" + requires :body, type: String, desc: "The content of a note" + optional :created_at, type: String, desc: "The creation date of the note" optional :position, type: Hash do - requires :base_sha, type: String, desc: 'Base commit SHA in the source branch' - requires :start_sha, type: String, desc: 'SHA referencing commit in target branch' - requires :head_sha, type: String, desc: 'SHA referencing HEAD of this merge request' - requires :position_type, type: String, desc: 'Type of the position reference', values: %w(text image) - optional :new_path, type: String, desc: 'File path after change' - optional :new_line, type: Integer, desc: 'Line number after change' - optional :old_path, type: String, desc: 'File path before change' - optional :old_line, type: Integer, desc: 'Line number before change' - optional :width, type: Integer, desc: 'Width of the image' - optional :height, type: Integer, desc: 'Height of the image' - optional :x, type: Integer, desc: 'X coordinate in the image' - optional :y, type: Integer, desc: 'Y coordinate in the image' + requires :base_sha, type: String, desc: "Base commit SHA in the source branch" + requires :start_sha, type: String, desc: "SHA referencing commit in target branch" + requires :head_sha, type: String, desc: "SHA referencing HEAD of this merge request" + requires :position_type, type: String, desc: "Type of the position reference", values: %w[text image] + optional :new_path, type: String, desc: "File path after change" + optional :new_line, type: Integer, desc: "Line number after change" + optional :old_path, type: String, desc: "File path before change" + optional :old_line, type: Integer, desc: "Line number before change" + optional :width, type: Integer, desc: "Width of the image" + optional :height, type: Integer, desc: "Height of the image" + optional :x, type: Integer, desc: "X coordinate in the image" + optional :y, type: Integer, desc: "Y coordinate in the image" end end post ":id/#{noteables_path}/:noteable_id/discussions" do noteable = find_noteable(parent_type, noteables_str, params[:noteable_id]) - type = params[:position] ? 'DiffNote' : 'DiscussionNote' + type = params[:position] ? "DiffNote" : "DiscussionNote" id_key = noteable.is_a?(Commit) ? :commit_id : :noteable_id opts = { - note: params[:body], - created_at: params[:created_at], - type: type, - noteable_type: noteables_str.classify, - position: params[:position], - id_key => noteable.id + :note => params[:body], + :created_at => params[:created_at], + :type => type, + :noteable_type => noteables_str.classify, + :position => params[:position], + id_key => noteable.id, } note = create_note(noteable, opts) @@ -110,8 +110,8 @@ module API success Entities::Discussion end params do - requires :discussion_id, type: String, desc: 'The ID of a discussion' - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' + requires :discussion_id, type: String, desc: "The ID of a discussion" + requires :noteable_id, types: [Integer, String], desc: "The ID of the noteable" end get ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes" do noteable = find_noteable(parent_type, noteables_str, params[:noteable_id]) @@ -128,10 +128,10 @@ module API success Entities::Note end params do - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' - requires :discussion_id, type: String, desc: 'The ID of a discussion' - requires :body, type: String, desc: 'The content of a note' - optional :created_at, type: String, desc: 'The creation date of the note' + requires :noteable_id, types: [Integer, String], desc: "The ID of the noteable" + requires :discussion_id, type: String, desc: "The ID of a discussion" + requires :body, type: String, desc: "The content of a note" + optional :created_at, type: String, desc: "The creation date of the note" end post ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes" do noteable = find_noteable(parent_type, noteables_str, params[:noteable_id]) @@ -142,9 +142,9 @@ module API opts = { note: params[:body], - type: 'DiscussionNote', + type: "DiscussionNote", in_reply_to_discussion_id: params[:discussion_id], - created_at: params[:created_at] + created_at: params[:created_at], } note = create_note(noteable, opts) @@ -159,9 +159,9 @@ module API success Entities::Note end params do - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' - requires :discussion_id, type: String, desc: 'The ID of a discussion' - requires :note_id, type: Integer, desc: 'The ID of a note' + requires :noteable_id, types: [Integer, String], desc: "The ID of the noteable" + requires :discussion_id, type: String, desc: "The ID of a discussion" + requires :note_id, type: Integer, desc: "The ID of a note" end get ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes/:note_id" do noteable = find_noteable(parent_type, noteables_str, params[:noteable_id]) @@ -173,11 +173,11 @@ module API success Entities::Note end params do - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' - requires :discussion_id, type: String, desc: 'The ID of a discussion' - requires :note_id, type: Integer, desc: 'The ID of a note' - optional :body, type: String, desc: 'The content of a note' - optional :resolved, type: Boolean, desc: 'Mark note resolved/unresolved' + requires :noteable_id, types: [Integer, String], desc: "The ID of the noteable" + requires :discussion_id, type: String, desc: "The ID of a discussion" + requires :note_id, type: Integer, desc: "The ID of a note" + optional :body, type: String, desc: "The content of a note" + optional :resolved, type: Boolean, desc: "Mark note resolved/unresolved" exactly_one_of :body, :resolved end put ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes/:note_id" do @@ -194,9 +194,9 @@ module API success Entities::Note end params do - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' - requires :discussion_id, type: String, desc: 'The ID of a discussion' - requires :note_id, type: Integer, desc: 'The ID of a note' + requires :noteable_id, types: [Integer, String], desc: "The ID of the noteable" + requires :discussion_id, type: String, desc: "The ID of a discussion" + requires :note_id, type: Integer, desc: "The ID of a note" end delete ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes/:note_id" do noteable = find_noteable(parent_type, noteables_str, params[:noteable_id]) @@ -209,9 +209,9 @@ module API success Entities::Discussion end params do - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' - requires :discussion_id, type: String, desc: 'The ID of a discussion' - requires :resolved, type: Boolean, desc: 'Mark discussion resolved/unresolved' + requires :noteable_id, types: [Integer, String], desc: "The ID of the noteable" + requires :discussion_id, type: String, desc: "The ID of a discussion" + requires :resolved, type: Boolean, desc: "Mark discussion resolved/unresolved" end put ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id" do noteable = find_noteable(parent_type, noteables_str, params[:noteable_id]) diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 18f15632f2b..b01f65709bb 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -21,7 +21,7 @@ module API expose :link do expose :file_path, as: :url expose :markdown do |_entity| - self.markdown_link + markdown_link end end @@ -46,7 +46,7 @@ module API end expose :avatar_path, if: ->(user, options) { options.fetch(:only_path, false) && user.avatar_path } - expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes + expose :custom_attributes, using: "API::Entities::CustomAttribute", if: :with_custom_attributes expose :web_url do |user, options| Gitlab::Routing.url_helpers.user_url(user) @@ -176,7 +176,7 @@ module API end end - expose :license, with: 'API::Entities::LicenseBasic', if: :license do |project| + expose :license, with: "API::Entities::LicenseBasic", if: :license do |project| project.repository.license end @@ -186,8 +186,8 @@ module API expose :star_count, :forks_count expose :last_activity_at - expose :namespace, using: 'API::Entities::NamespaceBasic' - expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes + expose :namespace, using: "API::Entities::NamespaceBasic" + expose :custom_attributes, using: "API::Entities::CustomAttribute", if: :with_custom_attributes # rubocop: disable CodeReuse/ActiveRecord def self.preload_relation(projects_relation, options = {}) @@ -196,8 +196,8 @@ module API # N+1 is solved then by using `subject.tags.map(&:name)` # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20555 projects_relation.preload(:project_feature, :route) - .preload(:import_state, :tags) - .preload(namespace: [:route, :owner]) + .preload(:import_state, :tags) + .preload(namespace: [:route, :owner]) end # rubocop: enable CodeReuse/ActiveRecord end @@ -210,11 +210,11 @@ module API expose_url(api_v4_projects_path(id: project.id)) end - expose :issues, if: -> (project, options) { issues_available?(project, options) } do |project| + expose :issues, if: ->(project, options) { issues_available?(project, options) } do |project| expose_url(api_v4_projects_issues_path(id: project.id)) end - expose :merge_requests, if: -> (project, options) { mrs_available?(project, options) } do |project| + expose :merge_requests, if: ->(project, options) { mrs_available?(project, options) } do |project| expose_url(api_v4_projects_merge_requests_path(id: project.id)) end @@ -271,7 +271,7 @@ module API expose :printing_merge_request_link_enabled expose :merge_method - expose :statistics, using: 'API::Entities::ProjectStatistics', if: :statistics + expose :statistics, using: "API::Entities::ProjectStatistics", if: :statistics # rubocop: disable CodeReuse/ActiveRecord def self.preload_relation(projects_relation, options = {}) @@ -280,10 +280,10 @@ module API # N+1 is solved then by using `subject.tags.map(&:name)` # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20555 super(projects_relation).preload(:group) - .preload(project_group_links: { group: :route }, - fork_network: :root_project, - fork_network_member: :forked_from_project, - forked_from_project: [:route, :forks, :tags, namespace: :route]) + .preload(project_group_links: {group: :route}, + fork_network: :root_project, + fork_network_member: :forked_from_project, + forked_from_project: [:route, :forks, :tags, namespace: :route]) end # rubocop: enable CodeReuse/ActiveRecord @@ -342,10 +342,10 @@ module API expose :parent_id end - expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes + expose :custom_attributes, using: "API::Entities::CustomAttribute", if: :with_custom_attributes expose :statistics, if: :statistics do - with_options format_with: -> (value) { value.to_i } do + with_options format_with: ->(value) { value.to_i } do expose :storage_size expose :repository_size expose :lfs_objects_size @@ -359,7 +359,7 @@ module API projects = GroupProjectsFinder.new( group: group, current_user: options[:current_user], - options: { only_owned: true } + options: {only_owned: true} ).execute Entities::Project.prepare_relation(projects) @@ -369,7 +369,7 @@ module API projects = GroupProjectsFinder.new( group: group, current_user: options[:current_user], - options: { only_shared: true } + options: {only_shared: true} ).execute Entities::Project.prepare_relation(projects) @@ -400,7 +400,7 @@ module API class CommitDetail < Commit expose :stats, using: Entities::CommitStats, if: :stats expose :status - expose :last_pipeline, using: 'API::Entities::PipelineBasic' + expose :last_pipeline, using: "API::Entities::PipelineBasic" expose :project_id end @@ -521,8 +521,8 @@ module API class Milestone < Grape::Entity expose :id, :iid - expose :project_id, if: -> (entity, options) { entity&.project_id } - expose :group_id, if: -> (entity, options) { entity&.group_id } + expose :project_id, if: ->(entity, options) { entity&.project_id } + expose :group_id, if: ->(entity, options) { entity&.group_id } expose :title, :description expose :state, :created_at, :updated_at expose :due_date @@ -559,7 +559,7 @@ module API Gitlab::UrlBuilder.build(issue) end - expose :time_stats, using: 'API::Entities::IssuableTimeStats' do |issue| + expose :time_stats, using: "API::Entities::IssuableTimeStats" do |issue| issue end end @@ -648,10 +648,10 @@ module API merge_request.metrics&.latest_closed_at end - expose :title_html, if: -> (_, options) { options[:render_html] } do |entity| + expose :title_html, if: ->(_, options) { options[:render_html] } do |entity| MarkupHelper.markdown_field(entity, :title) end - expose :description_html, if: -> (_, options) { options[:render_html] } do |entity| + expose :description_html, if: ->(_, options) { options[:render_html] } do |entity| MarkupHelper.markdown_field(entity, :description) end expose :target_branch, :source_branch @@ -681,15 +681,15 @@ module API expose :discussion_locked expose :should_remove_source_branch?, as: :should_remove_source_branch expose :force_remove_source_branch?, as: :force_remove_source_branch - expose :allow_collaboration, if: -> (merge_request, _) { merge_request.for_fork? } + expose :allow_collaboration, if: ->(merge_request, _) { merge_request.for_fork? } # Deprecated - expose :allow_collaboration, as: :allow_maintainer_to_push, if: -> (merge_request, _) { merge_request.for_fork? } + expose :allow_collaboration, as: :allow_maintainer_to_push, if: ->(merge_request, _) { merge_request.for_fork? } expose :web_url do |merge_request| Gitlab::UrlBuilder.build(merge_request) end - expose :time_stats, using: 'API::Entities::IssuableTimeStats' do |merge_request| + expose :time_stats, using: "API::Entities::IssuableTimeStats" do |merge_request| merge_request end @@ -705,19 +705,19 @@ module API merge_request.merge_request_diff.real_size end - expose :latest_build_started_at, if: -> (_, options) { build_available?(options) } do |merge_request, _options| + expose :latest_build_started_at, if: ->(_, options) { build_available?(options) } do |merge_request, _options| merge_request.metrics&.latest_build_started_at end - expose :latest_build_finished_at, if: -> (_, options) { build_available?(options) } do |merge_request, _options| + expose :latest_build_finished_at, if: ->(_, options) { build_available?(options) } do |merge_request, _options| merge_request.metrics&.latest_build_finished_at end - expose :first_deployed_to_production_at, if: -> (_, options) { build_available?(options) } do |merge_request, _options| + expose :first_deployed_to_production_at, if: ->(_, options) { build_available?(options) } do |merge_request, _options| merge_request.metrics&.first_deployed_to_production_at end - expose :pipeline, using: Entities::PipelineBasic, if: -> (_, options) { build_available?(options) } do |merge_request, _options| + expose :pipeline, using: Entities::PipelineBasic, if: ->(_, options) { build_available?(options) } do |merge_request, _options| merge_request.metrics&.pipeline end @@ -725,9 +725,9 @@ module API # Allow the status of a rebase to be determined expose :merge_error - expose :rebase_in_progress?, as: :rebase_in_progress, if: -> (_, options) { options[:include_rebase_in_progress] } + expose :rebase_in_progress?, as: :rebase_in_progress, if: ->(_, options) { options[:include_rebase_in_progress] } - expose :diverged_commits_count, as: :diverged_commits_count, if: -> (_, options) { options[:include_diverged_commits_count] } + expose :diverged_commits_count, as: :diverged_commits_count, if: ->(_, options) { options[:include_diverged_commits_count] } def build_available?(options) options[:project]&.feature_available?(:builds, options[:current_user]) @@ -783,7 +783,7 @@ module API class Note < Grape::Entity # Only Issue and MergeRequest have iid - NOTEABLE_TYPES_WITH_IID = %w(Issue MergeRequest).freeze + NOTEABLE_TYPES_WITH_IID = %w[Issue MergeRequest].freeze expose :id expose :type @@ -842,7 +842,7 @@ module API class CommitStatus < Grape::Entity expose :id, :sha, :ref, :status, :name, :target_url, :description, - :created_at, :started_at, :finished_at, :allow_failure, :coverage + :created_at, :started_at, :finished_at, :allow_failure, :coverage expose :author, using: Entities::UserBasic end @@ -862,7 +862,7 @@ module API expose :push_event_payload, as: :push_data, using: PushEventPayload, - if: -> (event, _) { event.push? } + if: ->(event, _) { event.push? } expose :author_username do |event, options| event.author&.username @@ -875,8 +875,8 @@ module API class Todo < Grape::Entity expose :id - expose :project, using: Entities::ProjectIdentity, if: -> (todo, _) { todo.project_id } - expose :group, using: 'API::Entities::NamespaceBasic', if: -> (todo, _) { todo.group_id } + expose :project, using: Entities::ProjectIdentity, if: ->(todo, _) { todo.project_id } + expose :group, using: "API::Entities::NamespaceBasic", if: ->(todo, _) { todo.group_id } expose :author, using: Entities::UserBasic expose :action_name expose :target_type @@ -909,12 +909,12 @@ module API end class Namespace < NamespaceBasic - expose :members_count_with_descendants, if: -> (namespace, opts) { expose_members_count_with_descendants?(namespace, opts) } do |namespace, _| + expose :members_count_with_descendants, if: ->(namespace, opts) { expose_members_count_with_descendants?(namespace, opts) } do |namespace, _| namespace.users_with_descendants.count end def expose_members_count_with_descendants?(namespace, opts) - namespace.kind == 'group' && Ability.allowed?(opts[:current_user], :admin_group, namespace) + namespace.kind == "group" && Ability.allowed?(opts[:current_user], :admin_group, namespace) end end @@ -987,10 +987,10 @@ module API # MySQL doesn't support LIMIT inside an IN subquery if Gitlab::Database.mysql? - project_ids = relation.pluck('projects.id') + project_ids = relation.pluck("projects.id") namespace_ids = relation.pluck(:namespace_id) else - project_ids = relation.select('projects.id') + project_ids = relation.select("projects.id") namespace_ids = relation.select(:namespace_id) end @@ -1135,7 +1135,7 @@ module API MarkupHelper.markdown_field(entity, :description) end expose :created_at - expose :author, using: Entities::UserBasic, if: -> (release, _) { release.author.present? } + expose :author, using: Entities::UserBasic, if: ->(release, _) { release.author.present? } expose :commit, using: Entities::Commit expose :assets do @@ -1229,7 +1229,7 @@ module API class Job < JobBasic # artifacts_file is included in job_artifacts, but kept for backward compatibility (remove in api/v5) - expose :artifacts_file, using: JobArtifactFile, if: -> (job, opts) { job.artifacts? } + expose :artifacts_file, using: JobArtifactFile, if: ->(job, opts) { job.artifacts? } expose :job_artifacts, as: :artifacts, using: JobArtifact expose :runner, with: Runner expose :artifacts_expire_at @@ -1251,7 +1251,7 @@ module API class Variable < Grape::Entity expose :key, :value - expose :protected?, as: :protected, if: -> (entity, _) { entity.respond_to?(:protected?) } + expose :protected?, as: :protected, if: ->(entity, _) { entity.respond_to?(:protected?) } end class Pipeline < PipelineBasic @@ -1293,15 +1293,15 @@ module API class LicenseBasic < Grape::Entity expose :key, :name, :nickname expose :url, as: :html_url - expose(:source_url) { |license| license.meta['source'] } + expose(:source_url) { |license| license.meta["source"] } end class License < LicenseBasic expose :popular?, as: :popular - expose(:description) { |license| license.meta['description'] } - expose(:conditions) { |license| license.meta['conditions'] } - expose(:permissions) { |license| license.meta['permissions'] } - expose(:limitations) { |license| license.meta['limitations'] } + expose(:description) { |license| license.meta["description"] } + expose(:conditions) { |license| license.meta["conditions"] } + expose(:permissions) { |license| license.meta["permissions"] } + expose(:limitations) { |license| license.meta["limitations"] } expose :content end @@ -1348,7 +1348,7 @@ module API expose :name expose :state expose :gates, using: FeatureGate do |model| - model.gates.map do |gate| + model.gates.map { |gate| value = model.gate_values[gate.key] # By default all gate values are populated. Only show relevant ones. @@ -1356,8 +1356,8 @@ module API next end - { key: gate.key, value: value } - end.compact + {key: gate.key, value: value} + }.compact end end @@ -1532,7 +1532,7 @@ module API class Badge < BasicBadgeDetails expose :id expose :kind do |badge| - badge.type == 'ProjectBadge' ? 'project' : 'group' + badge.type == "ProjectBadge" ? "project" : "group" end end diff --git a/lib/api/environments.rb b/lib/api/environments.rb index 0278c6c54a5..b5dd47def3f 100644 --- a/lib/api/environments.rb +++ b/lib/api/environments.rb @@ -9,32 +9,32 @@ module API before { authenticate! } params do - requires :id, type: String, desc: 'The project ID' + requires :id, type: String, desc: "The project ID" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get all environments of the project' do - detail 'This feature was introduced in GitLab 8.11.' + desc "Get all environments of the project" do + detail "This feature was introduced in GitLab 8.11." success Entities::Environment end params do use :pagination end - get ':id/environments' do + get ":id/environments" do authorize! :read_environment, user_project present paginate(user_project.environments), with: Entities::Environment end - desc 'Creates a new environment' do - detail 'This feature was introduced in GitLab 8.11.' + desc "Creates a new environment" do + detail "This feature was introduced in GitLab 8.11." success Entities::Environment end params do - requires :name, type: String, desc: 'The name of the environment to be created' - optional :external_url, type: String, desc: 'URL on which this deployment is viewable' - optional :slug, absence: { message: "is automatically generated and cannot be changed" } + requires :name, type: String, desc: "The name of the environment to be created" + optional :external_url, type: String, desc: "URL on which this deployment is viewable" + optional :slug, absence: {message: "is automatically generated and cannot be changed"} end - post ':id/environments' do + post ":id/environments" do authorize! :create_environment, user_project environment = user_project.environments.create(declared_params) @@ -46,17 +46,17 @@ module API end end - desc 'Updates an existing environment' do - detail 'This feature was introduced in GitLab 8.11.' + desc "Updates an existing environment" do + detail "This feature was introduced in GitLab 8.11." success Entities::Environment end params do - requires :environment_id, type: Integer, desc: 'The environment ID' - optional :name, type: String, desc: 'The new environment name' - optional :external_url, type: String, desc: 'The new URL on which this deployment is viewable' - optional :slug, absence: { message: "is automatically generated and cannot be changed" } + requires :environment_id, type: Integer, desc: "The environment ID" + optional :name, type: String, desc: "The new environment name" + optional :external_url, type: String, desc: "The new URL on which this deployment is viewable" + optional :slug, absence: {message: "is automatically generated and cannot be changed"} end - put ':id/environments/:environment_id' do + put ":id/environments/:environment_id" do authorize! :update_environment, user_project environment = user_project.environments.find(params[:environment_id]) @@ -69,14 +69,14 @@ module API end end - desc 'Deletes an existing environment' do - detail 'This feature was introduced in GitLab 8.11.' + desc "Deletes an existing environment" do + detail "This feature was introduced in GitLab 8.11." success Entities::Environment end params do - requires :environment_id, type: Integer, desc: 'The environment ID' + requires :environment_id, type: Integer, desc: "The environment ID" end - delete ':id/environments/:environment_id' do + delete ":id/environments/:environment_id" do authorize! :update_environment, user_project environment = user_project.environments.find(params[:environment_id]) @@ -84,13 +84,13 @@ module API destroy_conditionally!(environment) end - desc 'Stops an existing environment' do + desc "Stops an existing environment" do success Entities::Environment end params do - requires :environment_id, type: Integer, desc: 'The environment ID' + requires :environment_id, type: Integer, desc: "The environment ID" end - post ':id/environments/:environment_id/stop' do + post ":id/environments/:environment_id/stop" do authorize! :read_environment, user_project environment = user_project.environments.find(params[:environment_id]) diff --git a/lib/api/events.rb b/lib/api/events.rb index b98aa9f31e1..0dcd2d0396b 100644 --- a/lib/api/events.rb +++ b/lib/api/events.rb @@ -7,15 +7,15 @@ module API helpers do params :event_filter_params do - optional :action, type: String, values: Event.actions, desc: 'Event action to filter on' - optional :target_type, type: String, values: Event.target_types, desc: 'Event target type to filter on' - optional :before, type: Date, desc: 'Include only events created before this date' - optional :after, type: Date, desc: 'Include only events created after this date' + optional :action, type: String, values: Event.actions, desc: "Event action to filter on" + optional :target_type, type: String, values: Event.target_types, desc: "Event target type to filter on" + optional :before, type: Date, desc: "Include only events created before this date" + optional :after, type: Date, desc: "Include only events created after this date" end params :sort_params do - optional :sort, type: String, values: %w[asc desc], default: 'desc', - desc: 'Return events sorted in ascending and descending order' + optional :sort, type: String, values: %w[asc desc], default: "desc", + desc: "Return events sorted in ascending and descending order" end def present_events(events) @@ -30,10 +30,10 @@ module API end resource :events do - allow_access_with_scope :read_user, if: -> (request) { request.get? } + allow_access_with_scope :read_user, if: ->(request) { request.get? } desc "List currently authenticated user's events" do - detail 'This feature was introduced in GitLab 9.3.' + detail "This feature was introduced in GitLab 9.3." success Entities::Event end params do @@ -52,13 +52,13 @@ module API end params do - requires :id, type: String, desc: 'The ID or Username of the user' + requires :id, type: String, desc: "The ID or Username of the user" end resource :users do - allow_access_with_scope :read_user, if: -> (request) { request.get? } + allow_access_with_scope :read_user, if: ->(request) { request.get? } - desc 'Get the contribution events of a specified user' do - detail 'This feature was introduced in GitLab 8.13.' + desc "Get the contribution events of a specified user" do + detail "This feature was introduced in GitLab 8.13." success Entities::Event end params do @@ -67,9 +67,9 @@ module API use :sort_params end - get ':id/events' do + get ":id/events" do user = find_user(params[:id]) - not_found!('User') unless user + not_found!("User") unless user events = find_events(user) @@ -78,7 +78,7 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do desc "List a Project's visible events" do diff --git a/lib/api/features.rb b/lib/api/features.rb index 4dc1834c644..3beccec88bf 100644 --- a/lib/api/features.rb +++ b/lib/api/features.rb @@ -7,9 +7,9 @@ module API helpers do def gate_value(params) case params[:value] - when 'true' + when "true" true - when '0', 'false' + when "0", "false" false else params[:value].to_i @@ -26,7 +26,7 @@ module API end resource :features do - desc 'Get a list of all features' do + desc "Get a list of all features" do success Entities::Feature end get do @@ -35,17 +35,17 @@ module API present features, with: Entities::Feature, current_user: current_user end - desc 'Set the gate value for the given feature' do + desc "Set the gate value for the given feature" do success Entities::Feature end params do - requires :value, type: String, desc: '`true` or `false` to enable/disable, an integer for percentage of time' - optional :feature_group, type: String, desc: 'A Feature group name' - optional :user, type: String, desc: 'A GitLab username' + requires :value, type: String, desc: "`true` or `false` to enable/disable, an integer for percentage of time" + optional :feature_group, type: String, desc: "A Feature group name" + optional :user, type: String, desc: "A GitLab username" optional :group, type: String, desc: "A GitLab group's path, such as 'gitlab-org'" - optional :project, type: String, desc: 'A projects path, like gitlab-org/gitlab-ce' + optional :project, type: String, desc: "A projects path, like gitlab-org/gitlab-ce" end - post ':name' do + post ":name" do feature = Feature.get(params[:name]) targets = gate_targets(params) value = gate_value(params) @@ -70,8 +70,8 @@ module API present feature, with: Entities::Feature, current_user: current_user end - desc 'Remove the gate value for the given feature' - delete ':name' do + desc "Remove the gate value for the given feature" + delete ":name" do Feature.get(params[:name]).remove status 204 diff --git a/lib/api/files.rb b/lib/api/files.rb index ca59d330e1c..c40fd29490e 100644 --- a/lib/api/files.rb +++ b/lib/api/files.rb @@ -22,7 +22,7 @@ module API file_content_encoding: attrs[:encoding], author_email: attrs[:author_email], author_name: attrs[:author_name], - last_commit_sha: attrs[:last_commit_id] + last_commit_sha: attrs[:last_commit_id], } end @@ -30,19 +30,19 @@ module API authorize! :download_code, user_project @commit = user_project.commit(params[:ref]) - not_found!('Commit') unless @commit + not_found!("Commit") unless @commit @repo = user_project.repository @blob = @repo.blob_at(@commit.sha, params[:file_path]) - not_found!('File') unless @blob + not_found!("File") unless @blob @blob.load_all_data! end def commit_response(attrs) { file_path: attrs[:file_path], - branch: attrs[:branch] + branch: attrs[:branch], } end @@ -56,37 +56,37 @@ module API ref: params[:ref], blob_id: @blob.id, commit_id: @commit.id, - last_commit_id: @repo.last_commit_id_for_path(@commit.sha, params[:file_path]) + last_commit_id: @repo.last_commit_id_for_path(@commit.sha, params[:file_path]), } end params :simple_file_params do - requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' - requires :branch, type: String, desc: 'Name of the branch to commit into. To create a new branch, also provide `start_branch`.', allow_blank: false - requires :commit_message, type: String, allow_blank: false, desc: 'Commit message' - optional :start_branch, type: String, desc: 'Name of the branch to start the new commit from' - optional :author_email, type: String, desc: 'The email of the author' - optional :author_name, type: String, desc: 'The name of the author' + requires :file_path, type: String, desc: "The url encoded path to the file. Ex. lib%2Fclass%2Erb" + requires :branch, type: String, desc: "Name of the branch to commit into. To create a new branch, also provide `start_branch`.", allow_blank: false + requires :commit_message, type: String, allow_blank: false, desc: "Commit message" + optional :start_branch, type: String, desc: "Name of the branch to start the new commit from" + optional :author_email, type: String, desc: "The email of the author" + optional :author_name, type: String, desc: "The name of the author" end params :extended_file_params do use :simple_file_params - requires :content, type: String, desc: 'File content' - optional :encoding, type: String, values: %w[base64], desc: 'File encoding' - optional :last_commit_id, type: String, desc: 'Last known commit id for this file' + requires :content, type: String, desc: "File content" + optional :encoding, type: String, values: %w[base64], desc: "File encoding" + optional :last_commit_id, type: String, desc: "Last known commit id for this file" end end params do - requires :id, type: String, desc: 'The project ID' + requires :id, type: String, desc: "The project ID" end resource :projects, requirements: FILE_ENDPOINT_REQUIREMENTS do - allow_access_with_scope :read_repository, if: -> (request) { request.get? || request.head? } + allow_access_with_scope :read_repository, if: ->(request) { request.get? || request.head? } - desc 'Get raw file metadata from repository' + desc "Get raw file metadata from repository" params do - requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' - requires :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false + requires :file_path, type: String, desc: "The url encoded path to the file. Ex. lib%2Fclass%2Erb" + requires :ref, type: String, desc: "The name of branch, tag or commit", allow_blank: false end head ":id/repository/files/:file_path/raw", requirements: FILE_ENDPOINT_REQUIREMENTS do assign_file_vars! @@ -94,10 +94,10 @@ module API set_http_headers(blob_data) end - desc 'Get raw file contents from the repository' + desc "Get raw file contents from the repository" params do - requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' - requires :ref, type: String, desc: 'The name of branch, tag commit', allow_blank: false + requires :file_path, type: String, desc: "The url encoded path to the file. Ex. lib%2Fclass%2Erb" + requires :ref, type: String, desc: "The name of branch, tag commit", allow_blank: false end get ":id/repository/files/:file_path/raw", requirements: FILE_ENDPOINT_REQUIREMENTS do assign_file_vars! @@ -107,10 +107,10 @@ module API send_git_blob @repo, @blob end - desc 'Get file metadata from repository' + desc "Get file metadata from repository" params do - requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' - requires :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false + requires :file_path, type: String, desc: "The url encoded path to the file. Ex. lib%2Fclass%2Erb" + requires :ref, type: String, desc: "The name of branch, tag or commit", allow_blank: false end head ":id/repository/files/:file_path", requirements: FILE_ENDPOINT_REQUIREMENTS do assign_file_vars! @@ -118,10 +118,10 @@ module API set_http_headers(blob_data) end - desc 'Get a file from the repository' + desc "Get a file from the repository" params do - requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' - requires :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false + requires :file_path, type: String, desc: "The url encoded path to the file. Ex. lib%2Fclass%2Erb" + requires :ref, type: String, desc: "The name of branch, tag or commit", allow_blank: false end get ":id/repository/files/:file_path", requirements: FILE_ENDPOINT_REQUIREMENTS do assign_file_vars! @@ -133,7 +133,7 @@ module API data.merge(content: Base64.strict_encode64(@blob.data)) end - desc 'Create new file in repository' + desc "Create new file in repository" params do use :extended_file_params end @@ -151,7 +151,7 @@ module API end end - desc 'Update existing file in repository' + desc "Update existing file in repository" params do use :extended_file_params end @@ -175,7 +175,7 @@ module API end end - desc 'Delete an existing file in repository' + desc "Delete an existing file in repository" params do use :simple_file_params end diff --git a/lib/api/group_boards.rb b/lib/api/group_boards.rb index 9a20ee8c8b9..0479b877e35 100644 --- a/lib/api/group_boards.rb +++ b/lib/api/group_boards.rb @@ -16,65 +16,65 @@ module API end params do - requires :id, type: String, desc: 'The ID of a group' + requires :id, type: String, desc: "The ID of a group" end resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - segment ':id/boards' do - desc 'Find a group board' do - detail 'This feature was introduced in 10.6' + segment ":id/boards" do + desc "Find a group board" do + detail "This feature was introduced in 10.6" success ::API::Entities::Board end - get '/:board_id' do + get "/:board_id" do present board, with: ::API::Entities::Board end - desc 'Get all group boards' do - detail 'This feature was introduced in 10.6' + desc "Get all group boards" do + detail "This feature was introduced in 10.6" success Entities::Board end params do use :pagination end - get '/' do + get "/" do present paginate(board_parent.boards), with: Entities::Board end end params do - requires :board_id, type: Integer, desc: 'The ID of a board' + requires :board_id, type: Integer, desc: "The ID of a board" end - segment ':id/boards/:board_id' do - desc 'Get the lists of a group board' do - detail 'Does not include backlog and closed lists. This feature was introduced in 10.6' + segment ":id/boards/:board_id" do + desc "Get the lists of a group board" do + detail "Does not include backlog and closed lists. This feature was introduced in 10.6" success Entities::List end params do use :pagination end - get '/lists' do + get "/lists" do present paginate(board_lists), with: Entities::List end - desc 'Get a list of a group board' do - detail 'This feature was introduced in 10.6' + desc "Get a list of a group board" do + detail "This feature was introduced in 10.6" success Entities::List end params do - requires :list_id, type: Integer, desc: 'The ID of a list' + requires :list_id, type: Integer, desc: "The ID of a list" end - get '/lists/:list_id' do + get "/lists/:list_id" do present board_lists.find(params[:list_id]), with: Entities::List end - desc 'Create a new board list' do - detail 'This feature was introduced in 10.6' + desc "Create a new board list" do + detail "This feature was introduced in 10.6" success Entities::List end params do use :list_creation_params end - post '/lists' do + post "/lists" do authorize_list_type_resource! authorize!(:admin_list, user_group) @@ -82,15 +82,15 @@ module API create_list end - desc 'Moves a board list to a new position' do - detail 'This feature was introduced in 10.6' + desc "Moves a board list to a new position" do + detail "This feature was introduced in 10.6" success Entities::List end params do - requires :list_id, type: Integer, desc: 'The ID of a list' - requires :position, type: Integer, desc: 'The position of the list' + requires :list_id, type: Integer, desc: "The ID of a list" + requires :position, type: Integer, desc: "The position of the list" end - put '/lists/:list_id' do + put "/lists/:list_id" do list = board_lists.find(params[:list_id]) authorize!(:admin_list, user_group) @@ -98,12 +98,12 @@ module API move_list(list) end - desc 'Delete a board list' do - detail 'This feature was introduced in 10.6' + desc "Delete a board list" do + detail "This feature was introduced in 10.6" success Entities::List end params do - requires :list_id, type: Integer, desc: 'The ID of a board list' + requires :list_id, type: Integer, desc: "The ID of a board list" end delete "/lists/:list_id" do authorize!(:admin_list, user_group) diff --git a/lib/api/group_labels.rb b/lib/api/group_labels.rb index 0dbc5f45a68..a78db7efe59 100644 --- a/lib/api/group_labels.rb +++ b/lib/api/group_labels.rb @@ -8,54 +8,54 @@ module API before { authenticate! } params do - requires :id, type: String, desc: 'The ID of a group' + requires :id, type: String, desc: "The ID of a group" end resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get all labels of the group' do - detail 'This feature was added in GitLab 11.8' + desc "Get all labels of the group" do + detail "This feature was added in GitLab 11.8" success Entities::GroupLabel end params do use :pagination end - get ':id/labels' do + get ":id/labels" do get_labels(user_group, Entities::GroupLabel) end - desc 'Create a new label' do - detail 'This feature was added in GitLab 11.8' + desc "Create a new label" do + detail "This feature was added in GitLab 11.8" success Entities::GroupLabel end params do use :label_create_params end - post ':id/labels' do + post ":id/labels" do create_label(user_group, Entities::GroupLabel) end - desc 'Update an existing label. At least one optional parameter is required.' do - detail 'This feature was added in GitLab 11.8' + desc "Update an existing label. At least one optional parameter is required." do + detail "This feature was added in GitLab 11.8" success Entities::GroupLabel end params do - requires :name, type: String, desc: 'The name of the label to be updated' - optional :new_name, type: String, desc: 'The new name of the label' + requires :name, type: String, desc: "The name of the label to be updated" + optional :new_name, type: String, desc: "The new name of the label" optional :color, type: String, desc: "The new color of the label given in 6-digit hex notation with leading '#' sign (e.g. #FFAABB) or one of the allowed CSS color names" - optional :description, type: String, desc: 'The new description of label' + optional :description, type: String, desc: "The new description of label" at_least_one_of :new_name, :color, :description end - put ':id/labels' do + put ":id/labels" do update_label(user_group, Entities::GroupLabel) end - desc 'Delete an existing label' do - detail 'This feature was added in GitLab 11.8' + desc "Delete an existing label" do + detail "This feature was added in GitLab 11.8" success Entities::GroupLabel end params do - requires :name, type: String, desc: 'The name of the label to be deleted' + requires :name, type: String, desc: "The name of the label to be deleted" end - delete ':id/labels' do + delete ":id/labels" do delete_label(user_group) end end diff --git a/lib/api/group_milestones.rb b/lib/api/group_milestones.rb index d4287e4a7c4..1fa7889840f 100644 --- a/lib/api/group_milestones.rb +++ b/lib/api/group_milestones.rb @@ -10,10 +10,10 @@ module API end params do - requires :id, type: String, desc: 'The ID of a group' + requires :id, type: String, desc: "The ID of a group" end resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get a list of group milestones' do + desc "Get a list of group milestones" do success Entities::Milestone end params do @@ -23,11 +23,11 @@ module API list_milestones_for(user_group) end - desc 'Get a single group milestone' do + desc "Get a single group milestone" do success Entities::Milestone end params do - requires :milestone_id, type: Integer, desc: 'The ID of a group milestone' + requires :milestone_id, type: Integer, desc: "The ID of a group milestone" end get ":id/milestones/:milestone_id" do authorize! :read_group, user_group @@ -35,11 +35,11 @@ module API get_milestone_for(user_group) end - desc 'Create a new group milestone' do + desc "Create a new group milestone" do success Entities::Milestone end params do - requires :title, type: String, desc: 'The title of the milestone' + requires :title, type: String, desc: "The title of the milestone" use :optional_params end post ":id/milestones" do @@ -48,7 +48,7 @@ module API create_milestone_for(user_group) end - desc 'Update an existing group milestone' do + desc "Update an existing group milestone" do success Entities::Milestone end params do @@ -60,7 +60,7 @@ module API update_milestone_for(user_group) end - desc 'Remove a project milestone' + desc "Remove a project milestone" delete ":id/milestones/:milestone_id" do authorize! :admin_milestone, user_group @@ -70,26 +70,26 @@ module API status(204) end - desc 'Get all issues for a single group milestone' do + desc "Get all issues for a single group milestone" do success Entities::IssueBasic end params do - requires :milestone_id, type: Integer, desc: 'The ID of a group milestone' + requires :milestone_id, type: Integer, desc: "The ID of a group milestone" use :pagination end get ":id/milestones/:milestone_id/issues" do milestone_issuables_for(user_group, :issue) end - desc 'Get all merge requests for a single group milestone' do - detail 'This feature was introduced in GitLab 9.' + desc "Get all merge requests for a single group milestone" do + detail "This feature was introduced in GitLab 9." success Entities::MergeRequestBasic end params do - requires :milestone_id, type: Integer, desc: 'The ID of a group milestone' + requires :milestone_id, type: Integer, desc: "The ID of a group milestone" use :pagination end - get ':id/milestones/:milestone_id/merge_requests' do + get ":id/milestones/:milestone_id/merge_requests" do milestone_issuables_for(user_group, :merge_request) end end diff --git a/lib/api/group_variables.rb b/lib/api/group_variables.rb index 3f048e0dc56..a45353a907b 100644 --- a/lib/api/group_variables.rb +++ b/lib/api/group_variables.rb @@ -8,47 +8,47 @@ module API before { authorize! :admin_build, user_group } params do - requires :id, type: String, desc: 'The ID of a group' + requires :id, type: String, desc: "The ID of a group" end resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get group-level variables' do + desc "Get group-level variables" do success Entities::Variable end params do use :pagination end - get ':id/variables' do + get ":id/variables" do variables = user_group.variables present paginate(variables), with: Entities::Variable end - desc 'Get a specific variable from a group' do + desc "Get a specific variable from a group" do success Entities::Variable end params do - requires :key, type: String, desc: 'The key of the variable' + requires :key, type: String, desc: "The key of the variable" end # rubocop: disable CodeReuse/ActiveRecord - get ':id/variables/:key' do + get ":id/variables/:key" do key = params[:key] variable = user_group.variables.find_by(key: key) - break not_found!('GroupVariable') unless variable + break not_found!("GroupVariable") unless variable present variable, with: Entities::Variable end # rubocop: enable CodeReuse/ActiveRecord - desc 'Create a new variable in a group' do + desc "Create a new variable in a group" do success Entities::Variable end params do - requires :key, type: String, desc: 'The key of the variable' - requires :value, type: String, desc: 'The value of the variable' - optional :protected, type: String, desc: 'Whether the variable is protected' + requires :key, type: String, desc: "The key of the variable" + requires :value, type: String, desc: "The value of the variable" + optional :protected, type: String, desc: "Whether the variable is protected" end - post ':id/variables' do + post ":id/variables" do variable_params = declared_params(include_missing: false) variable = user_group.variables.create(variable_params) @@ -60,19 +60,19 @@ module API end end - desc 'Update an existing variable from a group' do + desc "Update an existing variable from a group" do success Entities::Variable end params do - optional :key, type: String, desc: 'The key of the variable' - optional :value, type: String, desc: 'The value of the variable' - optional :protected, type: String, desc: 'Whether the variable is protected' + optional :key, type: String, desc: "The key of the variable" + optional :value, type: String, desc: "The value of the variable" + optional :protected, type: String, desc: "Whether the variable is protected" end # rubocop: disable CodeReuse/ActiveRecord - put ':id/variables/:key' do + put ":id/variables/:key" do variable = user_group.variables.find_by(key: params[:key]) - break not_found!('GroupVariable') unless variable + break not_found!("GroupVariable") unless variable variable_params = declared_params(include_missing: false).except(:key) @@ -84,16 +84,16 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Delete an existing variable from a group' do + desc "Delete an existing variable from a group" do success Entities::Variable end params do - requires :key, type: String, desc: 'The key of the variable' + requires :key, type: String, desc: "The key of the variable" end # rubocop: disable CodeReuse/ActiveRecord - delete ':id/variables/:key' do + delete ":id/variables/:key" do variable = user_group.variables.find_by(key: params[:key]) - not_found!('GroupVariable') unless variable + not_found!("GroupVariable") unless variable destroy_conditionally!(variable) end diff --git a/lib/api/groups.rb b/lib/api/groups.rb index 64958ff982a..c8042326cab 100644 --- a/lib/api/groups.rb +++ b/lib/api/groups.rb @@ -9,15 +9,16 @@ module API helpers do params :optional_params_ce do - optional :description, type: String, desc: 'The description of the group' + optional :description, type: String, desc: "The description of the group" optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, default: Gitlab::VisibilityLevel.string_level( - Gitlab::CurrentSettings.current_application_settings.default_group_visibility), - desc: 'The visibility of the group' - optional :lfs_enabled, type: Boolean, desc: 'Enable/disable LFS for the projects in this group' - optional :request_access_enabled, type: Boolean, desc: 'Allow users to request member access' - optional :share_with_group_lock, type: Boolean, desc: 'Prevent sharing a project with another group within this group' + Gitlab::CurrentSettings.current_application_settings.default_group_visibility + ), + desc: "The visibility of the group" + optional :lfs_enabled, type: Boolean, desc: "Enable/disable LFS for the projects in this group" + optional :request_access_enabled, type: Boolean, desc: "Allow users to request member access" + optional :share_with_group_lock, type: Boolean, desc: "Prevent sharing a project with another group within this group" end params :optional_params do @@ -25,18 +26,18 @@ module API end params :statistics_params do - optional :statistics, type: Boolean, default: false, desc: 'Include project statistics' + optional :statistics, type: Boolean, default: false, desc: "Include project statistics" end params :group_list_params do use :statistics_params - optional :skip_groups, type: Array[Integer], desc: 'Array of group ids to exclude from list' - optional :all_available, type: Boolean, desc: 'Show all group that you have access to' - optional :search, type: String, desc: 'Search for a specific group' - optional :owned, type: Boolean, default: false, desc: 'Limit by owned by authenticated user' - optional :order_by, type: String, values: %w[name path id], default: 'name', desc: 'Order by name, path or id' - optional :sort, type: String, values: %w[asc desc], default: 'asc', desc: 'Sort by asc (ascending) or desc (descending)' - optional :min_access_level, type: Integer, values: Gitlab::Access.all_values, desc: 'Minimum access level of authenticated user' + optional :skip_groups, type: Array[Integer], desc: "Array of group ids to exclude from list" + optional :all_available, type: Boolean, desc: "Show all group that you have access to" + optional :search, type: String, desc: "Search for a specific group" + optional :owned, type: Boolean, default: false, desc: "Limit by owned by authenticated user" + optional :order_by, type: String, values: %w[name path id], default: "name", desc: "Order by name, path or id" + optional :sort, type: String, values: %w[asc desc], default: "asc", desc: "Sort by asc (ascending) or desc (descending)" + optional :min_access_level, type: Integer, values: Gitlab::Access.all_values, desc: "Minimum access level of authenticated user" use :pagination end @@ -50,7 +51,7 @@ module API groups = GroupsFinder.new(current_user, find_params).execute groups = groups.search(params[:search]) if params[:search].present? groups = groups.where.not(id: params[:skip_groups]) if params[:skip_groups].present? - order_options = { params[:order_by] => params[:sort] } + order_options = {params[:order_by] => params[:sort]} order_options["id"] ||= "asc" groups = groups.reorder(order_options) @@ -62,7 +63,7 @@ module API group = find_group!(params[:id]) options = { only_owned: !params[:with_shared], - include_subgroups: params[:include_subgroups] + include_subgroups: params[:include_subgroups], } projects = GroupProjectsFinder.new( @@ -81,7 +82,7 @@ module API options = { with: Entities::Group, current_user: current_user, - statistics: params[:statistics] && current_user.admin? + statistics: params[:statistics] && current_user.admin?, } groups = groups.with_statistics if options[:statistics] @@ -94,7 +95,7 @@ module API resource :groups do include CustomAttributesEndpoints - desc 'Get a groups list' do + desc "Get a groups list" do success Entities::Group end params do @@ -106,15 +107,15 @@ module API present_groups params, groups end - desc 'Create a group. Available only for users who can create groups.' do + desc "Create a group. Available only for users who can create groups." do success Entities::Group end params do - requires :name, type: String, desc: 'The name of the group' - requires :path, type: String, desc: 'The path of the group' + requires :name, type: String, desc: "The name of the group" + requires :path, type: String, desc: "The path of the group" if ::Group.supports_nested_objects? - optional :parent_id, type: Integer, desc: 'The parent group id for creating nested group' + optional :parent_id, type: Integer, desc: "The parent group id for creating nested group" end use :optional_params @@ -138,18 +139,18 @@ module API end params do - requires :id, type: String, desc: 'The ID of a group' + requires :id, type: String, desc: "The ID of a group" end resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Update a group. Available only for users who can administrate groups.' do + desc "Update a group. Available only for users who can administrate groups." do success Entities::Group end params do - optional :name, type: String, desc: 'The name of the group' - optional :path, type: String, desc: 'The path of the group' + optional :name, type: String, desc: "The name of the group" + optional :path, type: String, desc: "The path of the group" use :optional_params end - put ':id' do + put ":id" do group = find_group!(params[:id]) authorize! :admin_group, group @@ -160,19 +161,19 @@ module API end end - desc 'Get a single group, with containing projects.' do + desc "Get a single group, with containing projects." do success Entities::GroupDetail end params do use :with_custom_attributes - optional :with_projects, type: Boolean, default: true, desc: 'Omit project details' + optional :with_projects, type: Boolean, default: true, desc: "Omit project details" end get ":id" do group = find_group!(params[:id]) options = { with: params[:with_projects] ? Entities::GroupDetail : Entities::Group, - current_user: current_user + current_user: current_user, } group, options = with_custom_attributes(group, options) @@ -180,12 +181,12 @@ module API present group, options end - desc 'Remove a group.' + desc "Remove a group." delete ":id" do group = find_group!(params[:id]) authorize! :admin_group, group - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/46285') + Gitlab::QueryLimiting.whitelist("https://gitlab.com/gitlab-org/gitlab-ce/issues/46285") destroy_conditionally!(group) do |group| ::Groups::DestroyService.new(group, current_user).async_execute end @@ -193,26 +194,26 @@ module API accepted! end - desc 'Get a list of projects in this group.' do + desc "Get a list of projects in this group." do success Entities::Project end params do - optional :archived, type: Boolean, default: false, desc: 'Limit by archived status' + optional :archived, type: Boolean, default: false, desc: "Limit by archived status" optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, - desc: 'Limit by visibility' - optional :search, type: String, desc: 'Return list of authorized projects matching the search criteria' + desc: "Limit by visibility" + optional :search, type: String, desc: "Return list of authorized projects matching the search criteria" optional :order_by, type: String, values: %w[id name path created_at updated_at last_activity_at], - default: 'created_at', desc: 'Return projects ordered by field' - optional :sort, type: String, values: %w[asc desc], default: 'desc', - desc: 'Return projects sorted in ascending and descending order' + default: "created_at", desc: "Return projects ordered by field" + optional :sort, type: String, values: %w[asc desc], default: "desc", + desc: "Return projects sorted in ascending and descending order" optional :simple, type: Boolean, default: false, - desc: 'Return only the ID, URL, name, and path of each project' - optional :owned, type: Boolean, default: false, desc: 'Limit by owned by authenticated user' - optional :starred, type: Boolean, default: false, desc: 'Limit by starred status' - optional :with_issues_enabled, type: Boolean, default: false, desc: 'Limit by enabled issues feature' - optional :with_merge_requests_enabled, type: Boolean, default: false, desc: 'Limit by enabled merge requests feature' - optional :with_shared, type: Boolean, default: true, desc: 'Include projects shared to this group' - optional :include_subgroups, type: Boolean, default: false, desc: 'Includes projects in subgroups of this group' + desc: "Return only the ID, URL, name, and path of each project" + optional :owned, type: Boolean, default: false, desc: "Limit by owned by authenticated user" + optional :starred, type: Boolean, default: false, desc: "Limit by starred status" + optional :with_issues_enabled, type: Boolean, default: false, desc: "Limit by enabled issues feature" + optional :with_merge_requests_enabled, type: Boolean, default: false, desc: "Limit by enabled merge requests feature" + optional :with_shared, type: Boolean, default: true, desc: "Include projects shared to this group" + optional :include_subgroups, type: Boolean, default: false, desc: "Includes projects in subgroups of this group" use :pagination use :with_custom_attributes @@ -222,7 +223,7 @@ module API options = { with: params[:simple] ? Entities::BasicProjectDetails : Entities::Project, - current_user: current_user + current_user: current_user, } projects, options = with_custom_attributes(projects, options) @@ -230,7 +231,7 @@ module API present options[:with].prepare_relation(projects), options end - desc 'Get a list of subgroups in this group.' do + desc "Get a list of subgroups in this group." do success Entities::Group end params do @@ -242,13 +243,13 @@ module API present_groups params, groups end - desc 'Transfer a project to the group namespace. Available only for admin.' do + desc "Transfer a project to the group namespace. Available only for admin." do success Entities::GroupDetail end params do - requires :project_id, type: String, desc: 'The ID or path of the project' + requires :project_id, type: String, desc: "The ID or path of the project" end - post ":id/projects/:project_id", requirements: { project_id: /.+/ } do + post ":id/projects/:project_id", requirements: {project_id: /.+/} do authenticated_as_admin! group = find_group!(params[:id]) project = find_project!(params[:project_id]) diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 54cd4cd9cdb..596c7e8b534 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -5,20 +5,24 @@ module API include Gitlab::Utils include Helpers::Pagination - SUDO_HEADER = "HTTP_SUDO".freeze + SUDO_HEADER = "HTTP_SUDO" SUDO_PARAM = :sudo - API_USER_ENV = 'gitlab.api.user'.freeze + API_USER_ENV = "gitlab.api.user" def declared_params(options = {}) - options = { include_parent_namespaces: false }.merge(options) + options = {include_parent_namespaces: false}.merge(options) declared(params, options).to_h.symbolize_keys end def check_unmodified_since!(last_modified) - if_unmodified_since = Time.parse(headers['If-Unmodified-Since']) rescue nil + if_unmodified_since = begin + Time.parse(headers["If-Unmodified-Since"]) + rescue + nil + end if if_unmodified_since && last_modified && last_modified > if_unmodified_since - render_api_error!('412 Precondition Failed', 412) + render_api_error!("412 Precondition Failed", 412) end end @@ -59,7 +63,7 @@ module API # rubocop:enable Gitlab/ModuleWithInstanceVariables def save_current_user_in_env(user) - env[API_USER_ENV] = { user_id: user.id, username: user.username } + env[API_USER_ENV] = {user_id: user.id, username: user.username} end def sudo? @@ -81,16 +85,17 @@ module API def wiki_page page = ProjectWiki.new(user_project, current_user).find_page(params[:slug]) - page || not_found!('Wiki Page') + page || not_found!("Wiki Page") end def available_labels_for(label_parent, include_ancestor_groups: true) - search_params = { include_ancestor_groups: include_ancestor_groups } + search_params = {include_ancestor_groups: include_ancestor_groups} if label_parent.is_a?(Project) search_params[:project_id] = label_parent.id else - search_params.merge!(group_id: label_parent.id, only_group_labels: true) + search_params[:group_id] = label_parent.id + search_params[:only_group_labels] = true end LabelsFinder.new(current_user, search_params).execute @@ -118,13 +123,13 @@ module API if can?(current_user, :read_project, project) project else - not_found!('Project') + not_found!("Project") end end # rubocop: disable CodeReuse/ActiveRecord def find_group(id) - if id.to_s =~ /^\d+$/ + if /^\d+$/.match?(id.to_s) Group.find_by(id: id) else Group.find_by_full_path(id) @@ -138,13 +143,13 @@ module API if can?(current_user, :read_group, group) group else - not_found!('Group') + not_found!("Group") end end # rubocop: disable CodeReuse/ActiveRecord def find_namespace(id) - if id.to_s =~ /^\d+$/ + if /^\d+$/.match?(id.to_s) Namespace.find_by(id: id) else Namespace.find_by_full_path(id) @@ -158,15 +163,15 @@ module API if can?(current_user, :read_namespace, namespace) namespace else - not_found!('Namespace') + not_found!("Namespace") end end def find_branch!(branch_name) if Gitlab::GitRefValidator.validate(branch_name) - user_project.repository.find_branch(branch_name) || not_found!('Branch') + user_project.repository.find_branch(branch_name) || not_found!("Branch") else - render_api_error!('The branch refname is invalid', 400) + render_api_error!("The branch refname is invalid", 400) end end @@ -187,7 +192,7 @@ module API end def find_project_snippet(id) - finder_params = { project: user_project } + finder_params = {project: user_project} SnippetsFinder.new(current_user, finder_params).find(id) end @@ -212,7 +217,7 @@ module API end def authenticate_by_gitlab_shell_token! - input = params['secret_token'].try(:chomp) + input = params["secret_token"].try(:chomp) unless Devise.secure_compare(secret_token, input) unauthorized! end @@ -249,8 +254,8 @@ module API end def require_gitlab_workhorse! - unless env['HTTP_GITLAB_WORKHORSE'].present? - forbidden!('Request should be executed via GitLab Workhorse') + unless env["HTTP_GITLAB_WORKHORSE"].present? + forbidden!("Request should be executed via GitLab Workhorse") end end @@ -300,72 +305,72 @@ module API end def order_options_with_tie_breaker - order_options = { params[:order_by] => params[:sort] } - order_options['id'] ||= 'desc' + order_options = {params[:order_by] => params[:sort]} + order_options["id"] ||= "desc" order_options end # error helpers def forbidden!(reason = nil) - message = ['403 Forbidden'] + message = ["403 Forbidden"] message << " - #{reason}" if reason - render_api_error!(message.join(' '), 403) + render_api_error!(message.join(" "), 403) end def bad_request!(attribute) message = ["400 (Bad request)"] message << "\"" + attribute.to_s + "\" not given" if attribute - render_api_error!(message.join(' '), 400) + render_api_error!(message.join(" "), 400) end def not_found!(resource = nil) message = ["404"] message << resource if resource message << "Not Found" - render_api_error!(message.join(' '), 404) + render_api_error!(message.join(" "), 404) end def unauthorized! - render_api_error!('401 Unauthorized', 401) + render_api_error!("401 Unauthorized", 401) end def not_allowed! - render_api_error!('405 Method Not Allowed', 405) + render_api_error!("405 Method Not Allowed", 405) end def conflict!(message = nil) - render_api_error!(message || '409 Conflict', 409) + render_api_error!(message || "409 Conflict", 409) end def file_to_large! - render_api_error!('413 Request Entity Too Large', 413) + render_api_error!("413 Request Entity Too Large", 413) end def not_modified! - render_api_error!('304 Not Modified', 304) + render_api_error!("304 Not Modified", 304) end def no_content! - render_api_error!('204 No Content', 204) + render_api_error!("204 No Content", 204) end def accepted! - render_api_error!('202 Accepted', 202) + render_api_error!("202 Accepted", 202) end def render_validation_error!(model) if model.errors.any? - render_api_error!(model.errors.messages || '400 Bad Request', 400) + render_api_error!(model.errors.messages || "400 Bad Request", 400) end end def render_spam_error! - render_api_error!({ error: 'Spam detected' }, 400) + render_api_error!({error: "Spam detected"}, 400) end def render_api_error!(message, status) - error!({ 'message' => message }, status, header) + error!({"message" => message}, status, header) end def handle_api_exception(exception) @@ -389,10 +394,10 @@ module API if Rails.env.test? message else - '500 Internal Server Error' + "500 Internal Server Error" end - rack_response({ 'message' => response_message }.to_json, 500) + rack_response({"message" => response_message}.to_json, 500) end # project helpers @@ -404,7 +409,7 @@ module API # rubocop: enable CodeReuse/ActiveRecord def project_finder_params - finder_params = { without_deleted: true } + finder_params = {without_deleted: true} finder_params[:owned] = true if params[:owned].present? finder_params[:non_public] = true if params[:membership].present? finder_params[:starred] = true if params[:starred].present? @@ -419,16 +424,16 @@ module API # file helpers - def present_disk_file!(path, filename, content_type = 'application/octet-stream') + def present_disk_file!(path, filename, content_type = "application/octet-stream") filename ||= File.basename(path) - header['Content-Disposition'] = ::Gitlab::ContentDisposition.format(disposition: 'attachment', filename: filename) - header['Content-Transfer-Encoding'] = 'binary' + header["Content-Disposition"] = ::Gitlab::ContentDisposition.format(disposition: "attachment", filename: filename) + header["Content-Transfer-Encoding"] = "binary" content_type content_type # Support download acceleration - case headers['X-Sendfile-Type'] - when 'X-Sendfile' - header['X-Sendfile'] = path + case headers["X-Sendfile-Type"] + when "X-Sendfile" + header["X-Sendfile"] = path body else file path @@ -469,11 +474,11 @@ module API unauthorized! unless initial_current_user unless initial_current_user.admin? - forbidden!('Must be admin to use sudo') + forbidden!("Must be admin to use sudo") end unless access_token - forbidden!('Must be authenticated using an OAuth or Personal Access Token to use sudo') + forbidden!("Must be authenticated using an OAuth or Personal Access Token to use sudo") end validate_access_token!(scopes: [:sudo]) @@ -493,9 +498,9 @@ module API end def send_git_blob(repository, blob) - env['api.format'] = :txt - content_type 'text/plain' - header['Content-Disposition'] = ::Gitlab::ContentDisposition.format(disposition: 'inline', filename: blob.name) + env["api.format"] = :txt + content_type "text/plain" + header["Content-Disposition"] = ::Gitlab::ContentDisposition.format(disposition: "inline", filename: blob.name) # Let Workhorse examine the content and determine the better content disposition header[Gitlab::Workhorse::DETECT_HEADER] = "true" @@ -515,8 +520,8 @@ module API # `request`. We workaround this by defining methods that returns the right # values. def define_params_for_grape_middleware - self.define_singleton_method(:request) { ActionDispatch::Request.new(env) } - self.define_singleton_method(:params) { request.params.symbolize_keys } + define_singleton_method(:request) { ActionDispatch::Request.new(env) } + define_singleton_method(:params) { request.params.symbolize_keys } end # We could get a Grape or a standard Ruby exception. We should only report anything that @@ -528,7 +533,7 @@ module API end def archived_param - return 'only' if params[:archived] + return "only" if params[:archived] params[:archived] end diff --git a/lib/api/helpers/badges_helpers.rb b/lib/api/helpers/badges_helpers.rb index 46ce5b4e7b5..2f63a6ac37e 100644 --- a/lib/api/helpers/badges_helpers.rb +++ b/lib/api/helpers/badges_helpers.rb @@ -18,12 +18,12 @@ module API def badge_source_params(source) project = if source.is_a?(Project) - source - else - GroupProjectsFinder.new(group: source, current_user: current_user).execute.first - end + source + else + GroupProjectsFinder.new(group: source, current_user: current_user).execute.first + end - { project: project } + {project: project} end end end diff --git a/lib/api/helpers/custom_attributes.rb b/lib/api/helpers/custom_attributes.rb index 88208226c40..7e5775f115c 100644 --- a/lib/api/helpers/custom_attributes.rb +++ b/lib/api/helpers/custom_attributes.rb @@ -8,10 +8,10 @@ module API included do helpers do params :with_custom_attributes do - optional :with_custom_attributes, type: Boolean, default: false, desc: 'Include custom attributes in the response' + optional :with_custom_attributes, type: Boolean, default: false, desc: "Include custom attributes in the response" optional :custom_attributes, type: Hash, - desc: 'Filter with custom attributes' + desc: "Filter with custom attributes" end # rubocop: disable CodeReuse/ActiveRecord diff --git a/lib/api/helpers/custom_validators.rb b/lib/api/helpers/custom_validators.rb index 1058f4e8a5e..6c62501cbc9 100644 --- a/lib/api/helpers/custom_validators.rb +++ b/lib/api/helpers/custom_validators.rb @@ -16,7 +16,7 @@ module API value = params[attr_name] return if value.is_a?(Integer) || - [IssuableFinder::FILTER_NONE, IssuableFinder::FILTER_ANY].include?(value.to_s.downcase) + [IssuableFinder::FILTER_NONE, IssuableFinder::FILTER_ANY].include?(value.to_s.downcase) raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: "should be an integer, 'None' or 'Any'" diff --git a/lib/api/helpers/headers_helpers.rb b/lib/api/helpers/headers_helpers.rb index 7553af9d156..3af44a230b3 100644 --- a/lib/api/helpers/headers_helpers.rb +++ b/lib/api/helpers/headers_helpers.rb @@ -9,7 +9,7 @@ module API raise ArgumentError.new("Header value should be a string") end - header "X-Gitlab-#{key.to_s.split('_').collect(&:capitalize).join('-')}", value.to_s + header "X-Gitlab-#{key.to_s.split("_").collect(&:capitalize).join("-")}", value.to_s end end end diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb index fe78049af87..1e5e22417c9 100644 --- a/lib/api/helpers/internal_helpers.rb +++ b/lib/api/helpers/internal_helpers.rb @@ -19,7 +19,7 @@ module API [ :read_project, :download_code, - :push_code + :push_code, ] end @@ -34,7 +34,7 @@ module API def log_user_activity(actor) commands = Gitlab::GitAccess::DOWNLOAD_COMMANDS - ::Users::ActivityService.new(actor, 'Git SSH').execute if commands.include?(params[:action]) + ::Users::ActivityService.new(actor, "Git SSH").execute if commands.include?(params[:action]) end def merge_request_urls @@ -44,7 +44,7 @@ module API def redis_ping result = Gitlab::Redis::SharedState.with { |redis| redis.ping } - result == 'PONG' + result == "PONG" rescue => e Rails.logger.warn("GitLab: An unexpected error occurred in pinging to Redis: #{e}") false @@ -106,7 +106,7 @@ module API { repository: repository.gitaly_repository, address: Gitlab::GitalyClient.address(project.repository_storage), - token: Gitlab::GitalyClient.token(project.repository_storage) + token: Gitlab::GitalyClient.token(project.repository_storage), } end end diff --git a/lib/api/helpers/label_helpers.rb b/lib/api/helpers/label_helpers.rb index c11e7d614ab..69cdc25aa00 100644 --- a/lib/api/helpers/label_helpers.rb +++ b/lib/api/helpers/label_helpers.rb @@ -6,16 +6,16 @@ module API extend Grape::API::Helpers params :label_create_params do - requires :name, type: String, desc: 'The name of the label to be created' + requires :name, type: String, desc: "The name of the label to be created" requires :color, type: String, desc: "The color of the label given in 6-digit hex notation with leading '#' sign (e.g. #FFAABB) or one of the allowed CSS color names" - optional :description, type: String, desc: 'The description of label to be created' + optional :description, type: String, desc: "The description of label to be created" end def find_label(parent, id, include_ancestor_groups: true) labels = available_labels_for(parent, include_ancestor_groups: include_ancestor_groups) label = labels.find_by_id(id) || labels.find_by_title(id) - label || not_found!('Label') + label || not_found!("Label") end def get_labels(parent, entity) @@ -26,7 +26,7 @@ module API authorize! :admin_label, parent label = available_labels_for(parent).find_by_title(params[:name]) - conflict!('Label already exists') if label + conflict!("Label already exists") if label priority = params.delete(:priority) label_params = declared_params(include_missing: false) diff --git a/lib/api/helpers/members_helpers.rb b/lib/api/helpers/members_helpers.rb index 73d58ee7f37..93b14278fb4 100644 --- a/lib/api/helpers/members_helpers.rb +++ b/lib/api/helpers/members_helpers.rb @@ -14,7 +14,7 @@ module API end def find_all_members(source_type, source) - members = source_type == 'project' ? find_all_members_for_project(source) : find_all_members_for_group(source) + members = source_type == "project" ? find_all_members_for_project(source) : find_all_members_for_group(source) members.non_invite .non_request end @@ -28,7 +28,7 @@ module API .compact Member.includes(:user) .joins(user: :project_authorizations) - .where(project_authorizations: { project_id: project.id }) + .where(project_authorizations: {project_id: project.id}) .where(source_id: source_ids) end # rubocop: enable CodeReuse/ActiveRecord @@ -38,7 +38,7 @@ module API source_ids = group.self_and_ancestors.pluck(:id) Member.includes(:user) .where(source_id: source_ids) - .where(source_type: 'Namespace') + .where(source_type: "Namespace") end # rubocop: enable CodeReuse/ActiveRecord end diff --git a/lib/api/helpers/notes_helpers.rb b/lib/api/helpers/notes_helpers.rb index 216b2c45741..0d8aeb30d6a 100644 --- a/lib/api/helpers/notes_helpers.rb +++ b/lib/api/helpers/notes_helpers.rb @@ -9,7 +9,7 @@ module API authorize! :admin_note, note opts = { - note: params[:body] + note: params[:body], } parent = noteable_parent(noteable) project = parent if parent.is_a?(Project) diff --git a/lib/api/helpers/pagination.rb b/lib/api/helpers/pagination.rb index d00e61678b5..a125020d6eb 100644 --- a/lib/api/helpers/pagination.rb +++ b/lib/api/helpers/pagination.rb @@ -4,11 +4,11 @@ module API module Helpers module Pagination def paginate(relation) - strategy = if params[:pagination] == 'keyset' && Feature.enabled?('api_keyset_pagination') - KeysetPaginationStrategy - else - DefaultPaginationStrategy - end + strategy = if params[:pagination] == "keyset" && Feature.enabled?("api_keyset_pagination") + KeysetPaginationStrategy + else + DefaultPaginationStrategy + end strategy.new(self).paginate(relation) end @@ -66,12 +66,12 @@ module API # Sort direction (`:asc` or `:desc`) def sort @sort ||= if order_by_primary_key? - # Default order is by id DESC - :desc - else - # API defaults to DESC order if param `sort` not present - request_context.params[:sort]&.to_sym || :desc - end + # Default order is by id DESC + :desc + else + # API defaults to DESC order if param `sort` not present + request_context.params[:sort]&.to_sym || :desc + end end # Do we only sort by primary key? @@ -100,9 +100,9 @@ module API # All values present in request parameters that correspond to #keys. def values - @values ||= keys.map do |key| + @values ||= keys.map { |key| request_context.params["ks_prev_#{key}".to_sym] - end + } end # All keys relevant to pagination. @@ -151,30 +151,30 @@ module API return nil if fields.empty? - placeholder = fields.map { '?' } + placeholder = fields.map { "?" } comp = if pagination.sort_ascending? - '>' - else - '<' - end + ">" + else + "<" + end [ # Row value comparison: # (A, B) < (a, b) <=> (A < a) OR (A = a AND B < b) # <=> A <= a AND ((A < a) OR (A = a AND B < b)) - "(#{fields.keys.join(',')}) #{comp} (#{placeholder.join(',')})", - *fields.values + "(#{fields.keys.join(",")}) #{comp} (#{placeholder.join(",")})", + *fields.values, ] end def add_default_pagination_headers - header 'X-Per-Page', per_page.to_s + header "X-Per-Page", per_page.to_s end def add_navigation_links(next_page_params) - header 'X-Next-Page', page_href(next_page_params) - header 'Link', link_for('next', next_page_params) + header "X-Next-Page", page_href(next_page_params) + header "Link", link_for("next", next_page_params) end def link_for(rel, next_page_params) @@ -220,16 +220,16 @@ module API end def add_pagination_headers(paginated_data) - header 'X-Per-Page', paginated_data.limit_value.to_s - header 'X-Page', paginated_data.current_page.to_s - header 'X-Next-Page', paginated_data.next_page.to_s - header 'X-Prev-Page', paginated_data.prev_page.to_s - header 'Link', pagination_links(paginated_data) + header "X-Per-Page", paginated_data.limit_value.to_s + header "X-Page", paginated_data.current_page.to_s + header "X-Next-Page", paginated_data.next_page.to_s + header "X-Prev-Page", paginated_data.prev_page.to_s + header "Link", pagination_links(paginated_data) return if data_without_counts?(paginated_data) - header 'X-Total', paginated_data.total_count.to_s - header 'X-Total-Pages', total_pages(paginated_data).to_s + header "X-Total", paginated_data.total_count.to_s + header "X-Total-Pages", total_pages(paginated_data).to_s end def pagination_links(paginated_data) @@ -239,7 +239,7 @@ module API links << %(<#{page_href(page: 1)}>; rel="first") links << %(<#{page_href(page: total_pages(paginated_data))}>; rel="last") unless data_without_counts?(paginated_data) - end.join(', ') + end.join(", ") end def total_pages(paginated_data) diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb index e6a72b949f9..07eb7f4a5d7 100644 --- a/lib/api/helpers/projects_helpers.rb +++ b/lib/api/helpers/projects_helpers.rb @@ -8,26 +8,26 @@ module API included do helpers do params :optional_project_params_ce do - optional :description, type: String, desc: 'The description of the project' - optional :ci_config_path, type: String, desc: 'The path to CI config file. Defaults to `.gitlab-ci.yml`' - optional :issues_enabled, type: Boolean, desc: 'Flag indication if the issue tracker is enabled' - optional :merge_requests_enabled, type: Boolean, desc: 'Flag indication if merge requests are enabled' - optional :wiki_enabled, type: Boolean, desc: 'Flag indication if the wiki is enabled' - optional :jobs_enabled, type: Boolean, desc: 'Flag indication if jobs are enabled' - optional :snippets_enabled, type: Boolean, desc: 'Flag indication if snippets are enabled' - optional :shared_runners_enabled, type: Boolean, desc: 'Flag indication if shared runners are enabled for that project' - optional :resolve_outdated_diff_discussions, type: Boolean, desc: 'Automatically resolve merge request diffs discussions on lines changed with a push' - optional :container_registry_enabled, type: Boolean, desc: 'Flag indication if the container registry is enabled for that project' - optional :lfs_enabled, type: Boolean, desc: 'Flag indication if Git LFS is enabled for that project' - optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The visibility of the project.' - optional :public_builds, type: Boolean, desc: 'Perform public builds' - optional :request_access_enabled, type: Boolean, desc: 'Allow users to request member access' - optional :only_allow_merge_if_pipeline_succeeds, type: Boolean, desc: 'Only allow to merge if builds succeed' - optional :only_allow_merge_if_all_discussions_are_resolved, type: Boolean, desc: 'Only allow to merge if all discussions are resolved' - optional :tag_list, type: Array[String], desc: 'The list of tags for a project' - optional :avatar, type: File, desc: 'Avatar image for project' - optional :printing_merge_request_link_enabled, type: Boolean, desc: 'Show link to create/view merge request when pushing from the command line' - optional :merge_method, type: String, values: %w(ff rebase_merge merge), desc: 'The merge method used when merging merge requests' + optional :description, type: String, desc: "The description of the project" + optional :ci_config_path, type: String, desc: "The path to CI config file. Defaults to `.gitlab-ci.yml`" + optional :issues_enabled, type: Boolean, desc: "Flag indication if the issue tracker is enabled" + optional :merge_requests_enabled, type: Boolean, desc: "Flag indication if merge requests are enabled" + optional :wiki_enabled, type: Boolean, desc: "Flag indication if the wiki is enabled" + optional :jobs_enabled, type: Boolean, desc: "Flag indication if jobs are enabled" + optional :snippets_enabled, type: Boolean, desc: "Flag indication if snippets are enabled" + optional :shared_runners_enabled, type: Boolean, desc: "Flag indication if shared runners are enabled for that project" + optional :resolve_outdated_diff_discussions, type: Boolean, desc: "Automatically resolve merge request diffs discussions on lines changed with a push" + optional :container_registry_enabled, type: Boolean, desc: "Flag indication if the container registry is enabled for that project" + optional :lfs_enabled, type: Boolean, desc: "Flag indication if Git LFS is enabled for that project" + optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: "The visibility of the project." + optional :public_builds, type: Boolean, desc: "Perform public builds" + optional :request_access_enabled, type: Boolean, desc: "Allow users to request member access" + optional :only_allow_merge_if_pipeline_succeeds, type: Boolean, desc: "Only allow to merge if builds succeed" + optional :only_allow_merge_if_all_discussions_are_resolved, type: Boolean, desc: "Only allow to merge if all discussions are resolved" + optional :tag_list, type: Array[String], desc: "The list of tags for a project" + optional :avatar, type: File, desc: "Avatar image for project" + optional :printing_merge_request_link_enabled, type: Boolean, desc: "Show link to create/view merge request when pushing from the command line" + optional :merge_method, type: String, values: %w[ff rebase_merge merge], desc: "The merge method used when merging merge requests" optional :initialize_with_readme, type: Boolean, desc: "Initialize a project with a README.md" end diff --git a/lib/api/helpers/related_resources_helpers.rb b/lib/api/helpers/related_resources_helpers.rb index 793ae11b41d..7c4934da73b 100644 --- a/lib/api/helpers/related_resources_helpers.rb +++ b/lib/api/helpers/related_resources_helpers.rb @@ -20,7 +20,7 @@ module API # Using a blank component at the beginning of the join we ensure # that the resulted path will start with '/'. If the resulted path # does not start with '/', URI::Generic#build will fail - path_with_script_name = File.join('', [script_name, path].select(&:present?)) + path_with_script_name = File.join("", [script_name, path].select(&:present?)) URI::Generic.build(scheme: protocol, host: host, port: port, path: path_with_script_name).to_s end diff --git a/lib/api/helpers/runner.rb b/lib/api/helpers/runner.rb index ff73a49d5e8..4afa8183d89 100644 --- a/lib/api/helpers/runner.rb +++ b/lib/api/helpers/runner.rb @@ -3,12 +3,12 @@ module API module Helpers module Runner - JOB_TOKEN_HEADER = 'HTTP_JOB_TOKEN'.freeze + JOB_TOKEN_HEADER = "HTTP_JOB_TOKEN" JOB_TOKEN_PARAM = :token def runner_registration_token_valid? ActiveSupport::SecurityUtils.variable_size_secure_compare(params[:token], - Gitlab::CurrentSettings.runners_registration_token) + Gitlab::CurrentSettings.runners_registration_token) end def authenticate_runner! @@ -19,14 +19,14 @@ module API end def get_runner_details_from_request - return get_runner_ip unless params['info'].present? + return get_runner_ip unless params["info"].present? - attributes_for_keys(%w(name version revision platform architecture), params['info']) + attributes_for_keys(%w[name version revision platform architecture], params["info"]) .merge(get_runner_ip) end def get_runner_ip - { ip_address: env["action_dispatch.remote_ip"].to_s || request.ip } + {ip_address: env["action_dispatch.remote_ip"].to_s || request.ip} end def current_runner @@ -39,8 +39,8 @@ module API yield if block_given? project = job.project - forbidden!('Project has been deleted!') if project.nil? || project.pending_delete? - forbidden!('Job has been erased!') if job.erased? + forbidden!("Project has been deleted!") if project.nil? || project.pending_delete? + forbidden!("Job has been erased!") if job.erased? end def authenticate_job! @@ -63,7 +63,7 @@ module API end def job_forbidden!(job, reason) - header 'Job-Status', job.status + header "Job-Status", job.status forbidden!(reason) end end diff --git a/lib/api/helpers/version.rb b/lib/api/helpers/version.rb index 7f53094e90c..2a80d5e71f5 100644 --- a/lib/api/helpers/version.rb +++ b/lib/api/helpers/version.rb @@ -9,12 +9,12 @@ module API @version = version.to_s unless API.versions.include?(version) - raise ArgumentError, 'Unknown API version!' + raise ArgumentError, "Unknown API version!" end end def root_path - File.join('/', API.prefix.to_s, @version) + File.join("/", API.prefix.to_s, @version) end def root_url diff --git a/lib/api/import_github.rb b/lib/api/import_github.rb index bb4e536cf57..1638a9914b3 100644 --- a/lib/api/import_github.rb +++ b/lib/api/import_github.rb @@ -10,7 +10,7 @@ module API end def access_params - { github_access_token: params[:personal_access_token] } + {github_access_token: params[:personal_access_token]} end def client_options @@ -22,24 +22,24 @@ module API end end - desc 'Import a GitHub project' do - detail 'This feature was introduced in GitLab 11.3.4.' + desc "Import a GitHub project" do + detail "This feature was introduced in GitLab 11.3.4." success Entities::ProjectEntity end params do - requires :personal_access_token, type: String, desc: 'GitHub personal access token' - requires :repo_id, type: Integer, desc: 'GitHub repository ID' - optional :new_name, type: String, desc: 'New repo name' - requires :target_namespace, type: String, desc: 'Namespace to import repo into' + requires :personal_access_token, type: String, desc: "GitHub personal access token" + requires :repo_id, type: Integer, desc: "GitHub repository ID" + optional :new_name, type: String, desc: "New repo name" + requires :target_namespace, type: String, desc: "Namespace to import repo into" end - post 'import/github' do + post "import/github" do result = Import::GithubService.new(client, current_user, params).execute(access_params, provider) if result[:status] == :success present ProjectSerializer.new.represent(result[:project]) else status result[:http_status] - { errors: result[:message] } + {errors: result[:message]} end end end diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 70b32f7d758..88183d7f10a 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -8,16 +8,16 @@ module API helpers ::API::Helpers::InternalHelpers helpers ::Gitlab::Identifier - UNKNOWN_CHECK_RESULT_ERROR = 'Unknown check result'.freeze + UNKNOWN_CHECK_RESULT_ERROR = "Unknown check result" helpers do def response_with_status(code: 200, success: true, message: nil, **extra_options) status code - { status: success, message: message }.merge(extra_options).compact + {status: success, message: message}.merge(extra_options).compact end end - namespace 'internal' do + namespace "internal" do # Check if git command is allowed for project # # Params: @@ -84,9 +84,9 @@ module API # This repository_path is a bogus value but gitlab-shell still requires # its presence. https://gitlab.com/gitlab-org/gitlab-shell/issues/135 - repository_path: '/', + repository_path: "/", - gitaly: gitaly_payload(params[:action]) + gitaly: gitaly_payload(params[:action]), } # Custom option for git-receive-pack command @@ -131,9 +131,9 @@ module API # # rubocop: disable CodeReuse/ActiveRecord get "/authorized_keys" do - fingerprint = params.fetch(:fingerprint) do + fingerprint = params.fetch(:fingerprint) { Gitlab::InsecureKeyFingerprint.new(params.fetch(:key)).fingerprint - end + } key = Key.find_by(fingerprint: fingerprint) not_found!("Key") if key.nil? present key, with: Entities::SSHKey @@ -163,7 +163,7 @@ module API api_version: API.version, gitlab_version: Gitlab::VERSION, gitlab_rev: Gitlab.revision, - redis: redis_ping + redis: redis_ping, } end @@ -184,7 +184,7 @@ module API end # rubocop: disable CodeReuse/ActiveRecord - post '/two_factor_recovery_codes' do + post "/two_factor_recovery_codes" do status 200 if params[:key_id] @@ -193,28 +193,28 @@ module API if key key.update_last_used_at else - break { 'success' => false, 'message' => 'Could not find the given key' } + break {"success" => false, "message" => "Could not find the given key"} end if key.is_a?(DeployKey) - break { success: false, message: 'Deploy keys cannot be used to retrieve recovery codes' } + break {success: false, message: "Deploy keys cannot be used to retrieve recovery codes"} end user = key.user unless user - break { success: false, message: 'Could not find a user for the given key' } + break {success: false, message: "Could not find a user for the given key"} end elsif params[:user_id] user = User.find_by(id: params[:user_id]) unless user - break { success: false, message: 'Could not find the given user' } + break {success: false, message: "Could not find the given user"} end end unless user.two_factor_enabled? - break { success: false, message: 'Two-factor authentication is not enabled for this user' } + break {success: false, message: "Two-factor authentication is not enabled for this user"} end codes = nil @@ -223,16 +223,16 @@ module API codes = user.generate_otp_backup_codes! end - { success: true, recovery_codes: codes } + {success: true, recovery_codes: codes} end # rubocop: enable CodeReuse/ActiveRecord - post '/pre_receive' do + post "/pre_receive" do status 200 reference_counter_increased = Gitlab::ReferenceCounter.new(params[:gl_repository]).increase - { reference_counter_increased: reference_counter_increased } + {reference_counter_increased: reference_counter_increased} end post "/notify_post_receive" do @@ -249,7 +249,7 @@ module API # end end - post '/post_receive' do + post "/post_receive" do status 200 PostReceive.perform_async(params[:gl_repository], params[:identifier], @@ -260,7 +260,7 @@ module API output = { merge_request_urls: merge_request_urls, broadcast_message: broadcast_message, - reference_counter_decreased: reference_counter_decreased + reference_counter_decreased: reference_counter_decreased, } project = Gitlab::GlRepository.parse(params[:gl_repository]).first diff --git a/lib/api/issues.rb b/lib/api/issues.rb index f43f4d961d6..a942c510c33 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -34,40 +34,40 @@ module API # rubocop: enable CodeReuse/ActiveRecord params :issues_params do - optional :labels, type: String, desc: 'Comma-separated list of label names' - optional :milestone, type: String, desc: 'Milestone title' - optional :order_by, type: String, values: %w[created_at updated_at], default: 'created_at', - desc: 'Return issues ordered by `created_at` or `updated_at` fields.' - optional :sort, type: String, values: %w[asc desc], default: 'desc', - desc: 'Return issues sorted in `asc` or `desc` order.' - optional :milestone, type: String, desc: 'Return issues for a specific milestone' - optional :iids, type: Array[Integer], desc: 'The IID array of issues' - optional :search, type: String, desc: 'Search issues for text present in the title, description, or any combination of these' - optional :in, type: String, desc: '`title`, `description`, or a string joining them with comma' - optional :created_after, type: DateTime, desc: 'Return issues created after the specified time' - optional :created_before, type: DateTime, desc: 'Return issues created before the specified time' - optional :updated_after, type: DateTime, desc: 'Return issues updated after the specified time' - optional :updated_before, type: DateTime, desc: 'Return issues updated before the specified time' - optional :author_id, type: Integer, desc: 'Return issues which are authored by the user with the given ID' + optional :labels, type: String, desc: "Comma-separated list of label names" + optional :milestone, type: String, desc: "Milestone title" + optional :order_by, type: String, values: %w[created_at updated_at], default: "created_at", + desc: "Return issues ordered by `created_at` or `updated_at` fields." + optional :sort, type: String, values: %w[asc desc], default: "desc", + desc: "Return issues sorted in `asc` or `desc` order." + optional :milestone, type: String, desc: "Return issues for a specific milestone" + optional :iids, type: Array[Integer], desc: "The IID array of issues" + optional :search, type: String, desc: "Search issues for text present in the title, description, or any combination of these" + optional :in, type: String, desc: "`title`, `description`, or a string joining them with comma" + optional :created_after, type: DateTime, desc: "Return issues created after the specified time" + optional :created_before, type: DateTime, desc: "Return issues created before the specified time" + optional :updated_after, type: DateTime, desc: "Return issues updated after the specified time" + optional :updated_before, type: DateTime, desc: "Return issues updated before the specified time" + optional :author_id, type: Integer, desc: "Return issues which are authored by the user with the given ID" optional :assignee_id, types: [Integer, String], integer_none_any: true, - desc: 'Return issues which are assigned to the user with the given ID' + desc: "Return issues which are assigned to the user with the given ID" optional :scope, type: String, values: %w[created-by-me assigned-to-me created_by_me assigned_to_me all], - desc: 'Return issues for the given scope: `created_by_me`, `assigned_to_me` or `all`' - optional :my_reaction_emoji, type: String, desc: 'Return issues reacted by the authenticated user by the given emoji' - optional :confidential, type: Boolean, desc: 'Filter confidential or public issues' + desc: "Return issues for the given scope: `created_by_me`, `assigned_to_me` or `all`" + optional :my_reaction_emoji, type: String, desc: "Return issues reacted by the authenticated user by the given emoji" + optional :confidential, type: Boolean, desc: "Filter confidential or public issues" use :pagination use :issues_params_ee end params :issue_params do - optional :description, type: String, desc: 'The description of an issue' - optional :assignee_ids, type: Array[Integer], desc: 'The array of user IDs to assign issue' - optional :assignee_id, type: Integer, desc: '[Deprecated] The ID of a user to assign issue' - optional :milestone_id, type: Integer, desc: 'The ID of a milestone to assign issue' - optional :labels, type: String, desc: 'Comma-separated list of label names' - optional :due_date, type: String, desc: 'Date string in the format YEAR-MONTH-DAY' - optional :confidential, type: Boolean, desc: 'Boolean parameter if the issue should be confidential' + optional :description, type: String, desc: "The description of an issue" + optional :assignee_ids, type: Array[Integer], desc: "The array of user IDs to assign issue" + optional :assignee_id, type: Integer, desc: "[Deprecated] The ID of a user to assign issue" + optional :milestone_id, type: Integer, desc: "The ID of a milestone to assign issue" + optional :labels, type: String, desc: "Comma-separated list of label names" + optional :due_date, type: String, desc: "Date string in the format YEAR-MONTH-DAY" + optional :confidential, type: Boolean, desc: "Boolean parameter if the issue should be confidential" optional :discussion_locked, type: Boolean, desc: " Boolean parameter indicating if the issue's discussion is locked" use :issue_params_ee @@ -79,20 +79,20 @@ module API success Entities::IssueBasic end params do - optional :state, type: String, values: %w[opened closed all], default: 'all', - desc: 'Return opened, closed, or all issues' + optional :state, type: String, values: %w[opened closed all], default: "all", + desc: "Return opened, closed, or all issues" use :issues_params - optional :scope, type: String, values: %w[created-by-me assigned-to-me created_by_me assigned_to_me all], default: 'created_by_me', - desc: 'Return issues for the given scope: `created_by_me`, `assigned_to_me` or `all`' + optional :scope, type: String, values: %w[created-by-me assigned-to-me created_by_me assigned_to_me all], default: "created_by_me", + desc: "Return issues for the given scope: `created_by_me`, `assigned_to_me` or `all`" end get do - authenticate! unless params[:scope] == 'all' + authenticate! unless params[:scope] == "all" issues = paginate(find_issues) options = { with: Entities::IssueBasic, current_user: current_user, - issuable_metadata: issuable_meta_data(issues, 'Issue') + issuable_metadata: issuable_meta_data(issues, "Issue"), } present issues, options @@ -100,15 +100,15 @@ module API end params do - requires :id, type: String, desc: 'The ID of a group' + requires :id, type: String, desc: "The ID of a group" end resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get a list of group issues' do + desc "Get a list of group issues" do success Entities::IssueBasic end params do - optional :state, type: String, values: %w[opened closed all], default: 'all', - desc: 'Return opened, closed, or all issues' + optional :state, type: String, values: %w[opened closed all], default: "all", + desc: "Return opened, closed, or all issues" use :issues_params end get ":id/issues" do @@ -119,7 +119,7 @@ module API options = { with: Entities::IssueBasic, current_user: current_user, - issuable_metadata: issuable_meta_data(issues, 'Issue') + issuable_metadata: issuable_meta_data(issues, "Issue"), } present issues, options @@ -127,17 +127,17 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do include TimeTrackingEndpoints - desc 'Get a list of project issues' do + desc "Get a list of project issues" do success Entities::IssueBasic end params do - optional :state, type: String, values: %w[opened closed all], default: 'all', - desc: 'Return opened, closed, or all issues' + optional :state, type: String, values: %w[opened closed all], default: "all", + desc: "Return opened, closed, or all issues" use :issues_params end get ":id/issues" do @@ -149,41 +149,41 @@ module API with: Entities::IssueBasic, current_user: current_user, project: user_project, - issuable_metadata: issuable_meta_data(issues, 'Issue') + issuable_metadata: issuable_meta_data(issues, "Issue"), } present issues, options end - desc 'Get a single project issue' do + desc "Get a single project issue" do success Entities::Issue end params do - requires :issue_iid, type: Integer, desc: 'The internal ID of a project issue' + requires :issue_iid, type: Integer, desc: "The internal ID of a project issue" end get ":id/issues/:issue_iid", as: :api_v4_project_issue do issue = find_project_issue(params[:issue_iid]) present issue, with: Entities::Issue, current_user: current_user, project: user_project end - desc 'Create a new project issue' do + desc "Create a new project issue" do success Entities::Issue end params do - requires :title, type: String, desc: 'The title of an issue' + requires :title, type: String, desc: "The title of an issue" optional :created_at, type: DateTime, - desc: 'Date time when the issue was created. Available only for admins and project owners.' + desc: "Date time when the issue was created. Available only for admins and project owners." optional :merge_request_to_resolve_discussions_of, type: Integer, - desc: 'The IID of a merge request for which to resolve discussions' + desc: "The IID of a merge request for which to resolve discussions" optional :discussion_to_resolve, type: String, - desc: 'The ID of a discussion to resolve, also pass `merge_request_to_resolve_discussions_of`' + desc: "The ID of a discussion to resolve, also pass `merge_request_to_resolve_discussions_of`" optional :iid, type: Integer, - desc: 'The internal ID of a project issue. Available only for admins and project owners.' + desc: "The internal ID of a project issue. Available only for admins and project owners." use :issue_params end - post ':id/issues' do - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42320') + post ":id/issues" do + Gitlab::QueryLimiting.whitelist("https://gitlab.com/gitlab-org/gitlab-ce/issues/42320") authorize! :create_issue, user_project @@ -195,11 +195,11 @@ module API issue_params = convert_parameters_from_legacy_format(issue_params) issue = ::Issues::CreateService.new(user_project, - current_user, - issue_params.merge(request: request, api: true)).execute + current_user, + issue_params.merge(request: request, api: true)).execute if issue.spam? - render_api_error!({ error: 'Spam detected' }, 400) + render_api_error!({error: "Spam detected"}, 400) end if issue.valid? @@ -209,22 +209,22 @@ module API end end - desc 'Update an existing issue' do + desc "Update an existing issue" do success Entities::Issue end params do - requires :issue_iid, type: Integer, desc: 'The internal ID of a project issue' - optional :title, type: String, desc: 'The title of an issue' + requires :issue_iid, type: Integer, desc: "The internal ID of a project issue" + optional :title, type: String, desc: "The title of an issue" optional :updated_at, type: DateTime, - desc: 'Date time when the issue was updated. Available only for admins and project owners.' - optional :state_event, type: String, values: %w[reopen close], desc: 'State of the issue' + desc: "Date time when the issue was updated. Available only for admins and project owners." + optional :state_event, type: String, values: %w[reopen close], desc: "State of the issue" use :issue_params at_least_one_of :title, :description, :assignee_ids, :assignee_id, :milestone_id, :discussion_locked, - :labels, :created_at, :due_date, :confidential, :state_event + :labels, :created_at, :due_date, :confidential, :state_event end # rubocop: disable CodeReuse/ActiveRecord - put ':id/issues/:issue_iid' do - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42322') + put ":id/issues/:issue_iid" do + Gitlab::QueryLimiting.whitelist("https://gitlab.com/gitlab-org/gitlab-ce/issues/42322") issue = user_project.issues.find_by!(iid: params.delete(:issue_iid)) authorize! :update_issue, issue @@ -239,8 +239,8 @@ module API update_params = convert_parameters_from_legacy_format(update_params) issue = ::Issues::UpdateService.new(user_project, - current_user, - update_params).execute(issue) + current_user, + update_params).execute(issue) render_spam_error! if issue.spam? @@ -252,22 +252,22 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Move an existing issue' do + desc "Move an existing issue" do success Entities::Issue end params do - requires :issue_iid, type: Integer, desc: 'The internal ID of a project issue' - requires :to_project_id, type: Integer, desc: 'The ID of the new project' + requires :issue_iid, type: Integer, desc: "The internal ID of a project issue" + requires :to_project_id, type: Integer, desc: "The ID of the new project" end # rubocop: disable CodeReuse/ActiveRecord - post ':id/issues/:issue_iid/move' do - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42323') + post ":id/issues/:issue_iid/move" do + Gitlab::QueryLimiting.whitelist("https://gitlab.com/gitlab-org/gitlab-ce/issues/42323") issue = user_project.issues.find_by(iid: params[:issue_iid]) - not_found!('Issue') unless issue + not_found!("Issue") unless issue new_project = Project.find_by(id: params[:to_project_id]) - not_found!('Project') unless new_project + not_found!("Project") unless new_project begin issue = ::Issues::MoveService.new(user_project, current_user).execute(issue, new_project) @@ -278,14 +278,14 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Delete a project issue' + desc "Delete a project issue" params do - requires :issue_iid, type: Integer, desc: 'The internal ID of a project issue' + requires :issue_iid, type: Integer, desc: "The internal ID of a project issue" end # rubocop: disable CodeReuse/ActiveRecord delete ":id/issues/:issue_iid" do issue = user_project.issues.find_by(iid: params[:issue_iid]) - not_found!('Issue') unless issue + not_found!("Issue") unless issue authorize!(:destroy_issue, issue) @@ -295,13 +295,13 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'List merge requests that are related to the issue' do + desc "List merge requests that are related to the issue" do success Entities::MergeRequestBasic end params do - requires :issue_iid, type: Integer, desc: 'The internal ID of a project issue' + requires :issue_iid, type: Integer, desc: "The internal ID of a project issue" end - get ':id/issues/:issue_iid/related_merge_requests' do + get ":id/issues/:issue_iid/related_merge_requests" do issue = find_project_issue(params[:issue_iid]) merge_requests = ::Issues::ReferencedMergeRequestsService.new(user_project, current_user) @@ -314,14 +314,14 @@ module API project: user_project end - desc 'List merge requests closing issue' do + desc "List merge requests closing issue" do success Entities::MergeRequestBasic end params do - requires :issue_iid, type: Integer, desc: 'The internal ID of a project issue' + requires :issue_iid, type: Integer, desc: "The internal ID of a project issue" end # rubocop: disable CodeReuse/ActiveRecord - get ':id/issues/:issue_iid/closed_by' do + get ":id/issues/:issue_iid/closed_by" do issue = find_project_issue(params[:issue_iid]) merge_request_ids = MergeRequestsClosingIssues.where(issue_id: issue).select(:merge_request_id) @@ -331,31 +331,31 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'List participants for an issue' do + desc "List participants for an issue" do success Entities::UserBasic end params do - requires :issue_iid, type: Integer, desc: 'The internal ID of a project issue' + requires :issue_iid, type: Integer, desc: "The internal ID of a project issue" end - get ':id/issues/:issue_iid/participants' do + get ":id/issues/:issue_iid/participants" do issue = find_project_issue(params[:issue_iid]) participants = ::Kaminari.paginate_array(issue.participants) present paginate(participants), with: Entities::UserBasic, current_user: current_user, project: user_project end - desc 'Get the user agent details for an issue' do + desc "Get the user agent details for an issue" do success Entities::UserAgentDetail end params do - requires :issue_iid, type: Integer, desc: 'The internal ID of a project issue' + requires :issue_iid, type: Integer, desc: "The internal ID of a project issue" end get ":id/issues/:issue_iid/user_agent_detail" do authenticated_as_admin! issue = find_project_issue(params[:issue_iid]) - break not_found!('UserAgentDetail') unless issue.user_agent_detail + break not_found!("UserAgentDetail") unless issue.user_agent_detail present issue.user_agent_detail, with: Entities::UserAgentDetail end diff --git a/lib/api/job_artifacts.rb b/lib/api/job_artifacts.rb index 933bd067e26..d100f2c431a 100644 --- a/lib/api/job_artifacts.rb +++ b/lib/api/job_artifacts.rb @@ -12,19 +12,19 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Download the artifacts archive from a job' do - detail 'This feature was introduced in GitLab 8.10' + desc "Download the artifacts archive from a job" do + detail "This feature was introduced in GitLab 8.10" end params do - requires :ref_name, type: String, desc: 'The ref from repository' - requires :job, type: String, desc: 'The name for the job' + requires :ref_name, type: String, desc: "The ref from repository" + requires :job, type: String, desc: "The name for the job" end route_setting :authentication, job_token_allowed: true - get ':id/jobs/artifacts/:ref_name/download', - requirements: { ref_name: /.+/ } do + get ":id/jobs/artifacts/:ref_name/download", + requirements: {ref_name: /.+/} do authorize_download_artifacts! latest_build = user_project.latest_successful_build_for!(params[:job], params[:ref_name]) @@ -32,37 +32,37 @@ module API present_carrierwave_file!(latest_build.artifacts_file) end - desc 'Download a specific file from artifacts archive from a ref' do - detail 'This feature was introduced in GitLab 11.5' + desc "Download a specific file from artifacts archive from a ref" do + detail "This feature was introduced in GitLab 11.5" end params do - requires :ref_name, type: String, desc: 'The ref from repository' - requires :job, type: String, desc: 'The name for the job' - requires :artifact_path, type: String, desc: 'Artifact path' + requires :ref_name, type: String, desc: "The ref from repository" + requires :job, type: String, desc: "The name for the job" + requires :artifact_path, type: String, desc: "Artifact path" end - get ':id/jobs/artifacts/:ref_name/raw/*artifact_path', - format: false, - requirements: { ref_name: /.+/ } do + get ":id/jobs/artifacts/:ref_name/raw/*artifact_path", + format: false, + requirements: {ref_name: /.+/} do authorize_download_artifacts! build = user_project.latest_successful_build_for!(params[:job], params[:ref_name]) path = Gitlab::Ci::Build::Artifacts::Path - .new(params[:artifact_path]) + .new(params[:artifact_path]) bad_request! unless path.valid? send_artifacts_entry(build, path) end - desc 'Download the artifacts archive from a job' do - detail 'This feature was introduced in GitLab 8.5' + desc "Download the artifacts archive from a job" do + detail "This feature was introduced in GitLab 8.5" end params do - requires :job_id, type: Integer, desc: 'The ID of a job' + requires :job_id, type: Integer, desc: "The ID of a job" end route_setting :authentication, job_token_allowed: true - get ':id/jobs/:job_id/artifacts' do + get ":id/jobs/:job_id/artifacts" do authorize_download_artifacts! build = find_build!(params[:job_id]) @@ -70,14 +70,14 @@ module API present_carrierwave_file!(build.artifacts_file) end - desc 'Download a specific file from artifacts archive' do - detail 'This feature was introduced in GitLab 10.0' + desc "Download a specific file from artifacts archive" do + detail "This feature was introduced in GitLab 10.0" end params do - requires :job_id, type: Integer, desc: 'The ID of a job' - requires :artifact_path, type: String, desc: 'Artifact path' + requires :job_id, type: Integer, desc: "The ID of a job" + requires :artifact_path, type: String, desc: "Artifact path" end - get ':id/jobs/:job_id/artifacts/*artifact_path', format: false do + get ":id/jobs/:job_id/artifacts/*artifact_path", format: false do authorize_read_builds! build = find_build!(params[:job_id]) @@ -91,13 +91,13 @@ module API send_artifacts_entry(build, path) end - desc 'Keep the artifacts to prevent them from being deleted' do + desc "Keep the artifacts to prevent them from being deleted" do success Entities::Job end params do - requires :job_id, type: Integer, desc: 'The ID of a job' + requires :job_id, type: Integer, desc: "The ID of a job" end - post ':id/jobs/:job_id/artifacts/keep' do + post ":id/jobs/:job_id/artifacts/keep" do authorize_update_builds! build = find_build!(params[:job_id]) diff --git a/lib/api/jobs.rb b/lib/api/jobs.rb index 59f0dbe8a9b..b30242bda9b 100644 --- a/lib/api/jobs.rb +++ b/lib/api/jobs.rb @@ -7,12 +7,12 @@ module API before { authenticate! } params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do helpers do params :optional_scope do - optional :scope, types: [String, Array[String]], desc: 'The scope of builds to show', + optional :scope, types: [String, Array[String]], desc: "The scope of builds to show", values: ::CommitStatus::AVAILABLE_STATUSES, coerce_with: ->(scope) { case scope @@ -23,13 +23,13 @@ module API when ::Array scope else - ['unknown'] + ["unknown"] end } end end - desc 'Get a projects jobs' do + desc "Get a projects jobs" do success Entities::Job end params do @@ -37,10 +37,10 @@ module API use :pagination end # rubocop: disable CodeReuse/ActiveRecord - get ':id/jobs' do + get ":id/jobs" do authorize_read_builds! - builds = user_project.builds.order('id DESC') + builds = user_project.builds.order("id DESC") builds = filter_builds(builds, params[:scope]) builds = builds.preload(:user, :job_artifacts_archive, :job_artifacts, :runner, pipeline: :project) @@ -48,16 +48,16 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get pipeline jobs' do + desc "Get pipeline jobs" do success Entities::Job end params do - requires :pipeline_id, type: Integer, desc: 'The pipeline ID' + requires :pipeline_id, type: Integer, desc: "The pipeline ID" use :optional_scope use :pagination end # rubocop: disable CodeReuse/ActiveRecord - get ':id/pipelines/:pipeline_id/jobs' do + get ":id/pipelines/:pipeline_id/jobs" do authorize!(:read_pipeline, user_project) pipeline = user_project.ci_pipelines.find(params[:pipeline_id]) authorize!(:read_build, pipeline) @@ -70,13 +70,13 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get a specific job of a project' do + desc "Get a specific job of a project" do success Entities::Job end params do - requires :job_id, type: Integer, desc: 'The ID of a job' + requires :job_id, type: Integer, desc: "The ID of a job" end - get ':id/jobs/:job_id' do + get ":id/jobs/:job_id" do authorize_read_builds! build = find_build!(params[:job_id]) @@ -87,30 +87,30 @@ module API # TODO: We should use `present_disk_file!` and leave this implementation for backward compatibility (when build trace # is saved in the DB instead of file). But before that, we need to consider how to replace the value of # `runners_token` with some mask (like `xxxxxx`) when sending trace file directly by workhorse. - desc 'Get a trace of a specific job of a project' + desc "Get a trace of a specific job of a project" params do - requires :job_id, type: Integer, desc: 'The ID of a job' + requires :job_id, type: Integer, desc: "The ID of a job" end - get ':id/jobs/:job_id/trace' do + get ":id/jobs/:job_id/trace" do authorize_read_builds! build = find_build!(params[:job_id]) - header 'Content-Disposition', "infile; filename=\"#{build.id}.log\"" - content_type 'text/plain' - env['api.format'] = :binary + header "Content-Disposition", "infile; filename=\"#{build.id}.log\"" + content_type "text/plain" + env["api.format"] = :binary trace = build.trace.raw body trace end - desc 'Cancel a specific job of a project' do + desc "Cancel a specific job of a project" do success Entities::Job end params do - requires :job_id, type: Integer, desc: 'The ID of a job' + requires :job_id, type: Integer, desc: "The ID of a job" end - post ':id/jobs/:job_id/cancel' do + post ":id/jobs/:job_id/cancel" do authorize_update_builds! build = find_build!(params[:job_id]) @@ -121,47 +121,47 @@ module API present build, with: Entities::Job end - desc 'Retry a specific build of a project' do + desc "Retry a specific build of a project" do success Entities::Job end params do - requires :job_id, type: Integer, desc: 'The ID of a build' + requires :job_id, type: Integer, desc: "The ID of a build" end - post ':id/jobs/:job_id/retry' do + post ":id/jobs/:job_id/retry" do authorize_update_builds! build = find_build!(params[:job_id]) authorize!(:update_build, build) - break forbidden!('Job is not retryable') unless build.retryable? + break forbidden!("Job is not retryable") unless build.retryable? build = Ci::Build.retry(build, current_user) present build, with: Entities::Job end - desc 'Erase job (remove artifacts and the trace)' do + desc "Erase job (remove artifacts and the trace)" do success Entities::Job end params do - requires :job_id, type: Integer, desc: 'The ID of a build' + requires :job_id, type: Integer, desc: "The ID of a build" end - post ':id/jobs/:job_id/erase' do + post ":id/jobs/:job_id/erase" do authorize_update_builds! build = find_build!(params[:job_id]) authorize!(:erase_build, build) - break forbidden!('Job is not erasable!') unless build.erasable? + break forbidden!("Job is not erasable!") unless build.erasable? build.erase(erased_by: current_user) present build, with: Entities::Job end - desc 'Trigger a actionable job (manual, delayed, etc)' do + desc "Trigger a actionable job (manual, delayed, etc)" do success Entities::Job - detail 'This feature was added in GitLab 8.11' + detail "This feature was added in GitLab 8.11" end params do - requires :job_id, type: Integer, desc: 'The ID of a Job' + requires :job_id, type: Integer, desc: "The ID of a Job" end post ":id/jobs/:job_id/play" do authorize_read_builds! @@ -186,7 +186,7 @@ module API available_statuses = ::CommitStatus::AVAILABLE_STATUSES unknown = scope - available_statuses - render_api_error!('Scope contains invalid value(s)', 400) unless unknown.empty? + render_api_error!("Scope contains invalid value(s)", 400) unless unknown.empty? builds.where(status: available_statuses && scope) end diff --git a/lib/api/keys.rb b/lib/api/keys.rb index d5280a0035d..404417bbdca 100644 --- a/lib/api/keys.rb +++ b/lib/api/keys.rb @@ -6,7 +6,7 @@ module API before { authenticate! } resource :keys do - desc 'Get single ssh key by id. Only available to admin users' do + desc "Get single ssh key by id. Only available to admin users" do success Entities::SSHKeyWithUser end get ":id" do diff --git a/lib/api/labels.rb b/lib/api/labels.rb index d729d3ee625..84d48d74263 100644 --- a/lib/api/labels.rb +++ b/lib/api/labels.rb @@ -8,52 +8,52 @@ module API before { authenticate! } params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get all labels of the project' do + desc "Get all labels of the project" do success Entities::ProjectLabel end params do use :pagination end - get ':id/labels' do + get ":id/labels" do get_labels(user_project, Entities::ProjectLabel) end - desc 'Create a new label' do + desc "Create a new label" do success Entities::ProjectLabel end params do use :label_create_params - optional :priority, type: Integer, desc: 'The priority of the label', allow_blank: true + optional :priority, type: Integer, desc: "The priority of the label", allow_blank: true end - post ':id/labels' do + post ":id/labels" do create_label(user_project, Entities::ProjectLabel) end - desc 'Update an existing label. At least one optional parameter is required.' do + desc "Update an existing label. At least one optional parameter is required." do success Entities::ProjectLabel end params do - requires :name, type: String, desc: 'The name of the label to be updated' - optional :new_name, type: String, desc: 'The new name of the label' + requires :name, type: String, desc: "The name of the label to be updated" + optional :new_name, type: String, desc: "The new name of the label" optional :color, type: String, desc: "The new color of the label given in 6-digit hex notation with leading '#' sign (e.g. #FFAABB) or one of the allowed CSS color names" - optional :description, type: String, desc: 'The new description of label' - optional :priority, type: Integer, desc: 'The priority of the label', allow_blank: true + optional :description, type: String, desc: "The new description of label" + optional :priority, type: Integer, desc: "The priority of the label", allow_blank: true at_least_one_of :new_name, :color, :description, :priority end - put ':id/labels' do + put ":id/labels" do update_label(user_project, Entities::ProjectLabel) end - desc 'Delete an existing label' do + desc "Delete an existing label" do success Entities::ProjectLabel end params do - requires :name, type: String, desc: 'The name of the label to be deleted' + requires :name, type: String, desc: "The name of the label to be deleted" end - delete ':id/labels' do + delete ":id/labels" do delete_label(user_project) end end diff --git a/lib/api/lint.rb b/lib/api/lint.rb index a7672021db0..a5995d6dcb3 100644 --- a/lib/api/lint.rb +++ b/lib/api/lint.rb @@ -3,20 +3,20 @@ module API class Lint < Grape::API namespace :ci do - desc 'Validation of .gitlab-ci.yml content' + desc "Validation of .gitlab-ci.yml content" params do - requires :content, type: String, desc: 'Content of .gitlab-ci.yml' + requires :content, type: String, desc: "Content of .gitlab-ci.yml" end - post '/lint' do + post "/lint" do error = Gitlab::Ci::YamlProcessor.validation_message(params[:content], user: current_user) status 200 if error.blank? - { status: 'valid', errors: [] } + {status: "valid", errors: []} else - { status: 'invalid', errors: [error] } + {status: "invalid", errors: [error]} end end end diff --git a/lib/api/markdown.rb b/lib/api/markdown.rb index de77bef43ce..41bddc820fb 100644 --- a/lib/api/markdown.rb +++ b/lib/api/markdown.rb @@ -12,7 +12,7 @@ module API detail "This feature was introduced in GitLab 11.0." end post do - context = { only_path: false, current_user: current_user } + context = {only_path: false, current_user: current_user} context[:pipeline] = params[:gfm] ? :full : :plain_markdown if params[:project] @@ -25,7 +25,7 @@ module API context[:skip_project_check] = true end - { html: Banzai.render_and_post_process(params[:text], context) } + {html: Banzai.render_and_post_process(params[:text], context)} end end end diff --git a/lib/api/members.rb b/lib/api/members.rb index 461ffe71a62..e12be5cd0bc 100644 --- a/lib/api/members.rb +++ b/lib/api/members.rb @@ -13,11 +13,11 @@ module API requires :id, type: String, desc: "The #{source_type} ID" end resource source_type.pluralize, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Gets a list of group or project members viewable by the authenticated user.' do + desc "Gets a list of group or project members viewable by the authenticated user." do success Entities::Member end params do - optional :query, type: String, desc: 'A query string to search for members' + optional :query, type: String, desc: "A query string to search for members" use :pagination end # rubocop: disable CodeReuse/ActiveRecord @@ -32,11 +32,11 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Gets a list of group or project members viewable by the authenticated user, including those who gained membership through ancestor group.' do + desc "Gets a list of group or project members viewable by the authenticated user, including those who gained membership through ancestor group." do success Entities::Member end params do - optional :query, type: String, desc: 'A query string to search for members' + optional :query, type: String, desc: "A query string to search for members" use :pagination end # rubocop: disable CodeReuse/ActiveRecord @@ -51,11 +51,11 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Gets a member of a group or project.' do + desc "Gets a member of a group or project." do success Entities::Member end params do - requires :user_id, type: Integer, desc: 'The user ID of the member' + requires :user_id, type: Integer, desc: "The user ID of the member" end # rubocop: disable CodeReuse/ActiveRecord get ":id/members/:user_id" do @@ -68,13 +68,13 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Adds a member to a group or project.' do + desc "Adds a member to a group or project." do success Entities::Member end params do - requires :user_id, type: Integer, desc: 'The user ID of the new member' - requires :access_level, type: Integer, desc: 'A valid access level (defaults: `30`, developer access level)' - optional :expires_at, type: DateTime, desc: 'Date string in the format YEAR-MONTH-DAY' + requires :user_id, type: Integer, desc: "The user ID of the new member" + requires :access_level, type: Integer, desc: "A valid access level (defaults: `30`, developer access level)" + optional :expires_at, type: DateTime, desc: "Date string in the format YEAR-MONTH-DAY" end # rubocop: disable CodeReuse/ActiveRecord post ":id/members" do @@ -82,10 +82,10 @@ module API authorize_admin_source!(source_type, source) member = source.members.find_by(user_id: params[:user_id]) - conflict!('Member already exists') if member + conflict!("Member already exists") if member user = User.find_by_id(params[:user_id]) - not_found!('User') unless user + not_found!("User") unless user member = source.add_user(user, params[:access_level], current_user: current_user, expires_at: params[:expires_at]) @@ -99,13 +99,13 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Updates a member of a group or project.' do + desc "Updates a member of a group or project." do success Entities::Member end params do - requires :user_id, type: Integer, desc: 'The user ID of the new member' - requires :access_level, type: Integer, desc: 'A valid access level' - optional :expires_at, type: DateTime, desc: 'Date string in the format YEAR-MONTH-DAY' + requires :user_id, type: Integer, desc: "The user ID of the new member" + requires :access_level, type: Integer, desc: "A valid access level" + optional :expires_at, type: DateTime, desc: "Date string in the format YEAR-MONTH-DAY" end # rubocop: disable CodeReuse/ActiveRecord put ":id/members/:user_id" do @@ -126,9 +126,9 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Removes a user from a group or project.' + desc "Removes a user from a group or project." params do - requires :user_id, type: Integer, desc: 'The user ID of the member' + requires :user_id, type: Integer, desc: "The user ID of the member" end # rubocop: disable CodeReuse/ActiveRecord delete ":id/members/:user_id" do diff --git a/lib/api/merge_request_diffs.rb b/lib/api/merge_request_diffs.rb index 6ad30aa56e0..ba7e442a4a3 100644 --- a/lib/api/merge_request_diffs.rb +++ b/lib/api/merge_request_diffs.rb @@ -8,16 +8,16 @@ module API before { authenticate! } params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get a list of merge request diff versions' do - detail 'This feature was introduced in GitLab 8.12.' + desc "Get a list of merge request diff versions" do + detail "This feature was introduced in GitLab 8.12." success Entities::MergeRequestDiff end params do - requires :merge_request_iid, type: Integer, desc: 'The IID of a merge request' + requires :merge_request_iid, type: Integer, desc: "The IID of a merge request" use :pagination end get ":id/merge_requests/:merge_request_iid/versions" do @@ -26,14 +26,14 @@ module API present paginate(merge_request.merge_request_diffs.order_id_desc), with: Entities::MergeRequestDiff end - desc 'Get a single merge request diff version' do - detail 'This feature was introduced in GitLab 8.12.' + desc "Get a single merge request diff version" do + detail "This feature was introduced in GitLab 8.12." success Entities::MergeRequestDiffFull end params do - requires :merge_request_iid, type: Integer, desc: 'The IID of a merge request' - requires :version_id, type: Integer, desc: 'The ID of a merge request diff version' + requires :merge_request_iid, type: Integer, desc: "The IID of a merge request" + requires :version_id, type: Integer, desc: "The ID of a merge request diff version" end get ":id/merge_requests/:merge_request_iid/versions/:version_id" do diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index 44f1e81caf2..71a61f38864 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -38,11 +38,11 @@ module API args[:scope] = args[:scope].underscore if args[:scope] merge_requests = MergeRequestsFinder.new(current_user, args).execute - .reorder(order_options_with_tie_breaker) + .reorder(order_options_with_tie_breaker) merge_requests = paginate(merge_requests) - .preload(:source_project, :target_project) + .preload(:source_project, :target_project) - return merge_requests if args[:view] == 'simple' + return merge_requests if args[:view] == "simple" merge_requests .preload(:notes, :author, :assignee, :milestone, :latest_merge_request_diff, :labels, :timelogs, metrics: [:latest_closed_by, :merged_by]) @@ -63,19 +63,19 @@ module API end def serializer_options_for(merge_requests) - options = { with: Entities::MergeRequestBasic, current_user: current_user } + options = {with: Entities::MergeRequestBasic, current_user: current_user} - if params[:view] == 'simple' + if params[:view] == "simple" options[:with] = Entities::MergeRequestSimple else - options[:issuable_metadata] = issuable_meta_data(merge_requests, 'MergeRequest') + options[:issuable_metadata] = issuable_meta_data(merge_requests, "MergeRequest") end options end def authorize_push_to_merge_request!(merge_request) - forbidden!('Source branch does not exist') unless + forbidden!("Source branch does not exist") unless merge_request.source_branch_exists? user_access = Gitlab::UserAccess.new( @@ -83,50 +83,50 @@ module API project: merge_request.source_project ) - forbidden!('Cannot push to source branch') unless + forbidden!("Cannot push to source branch") unless user_access.can_push_to_branch?(merge_request.source_branch) end params :merge_requests_params do - optional :state, type: String, values: %w[opened closed locked merged all], default: 'all', - desc: 'Return opened, closed, locked, merged, or all merge requests' - optional :order_by, type: String, values: %w[created_at updated_at], default: 'created_at', - desc: 'Return merge requests ordered by `created_at` or `updated_at` fields.' - optional :sort, type: String, values: %w[asc desc], default: 'desc', - desc: 'Return merge requests sorted in `asc` or `desc` order.' - optional :milestone, type: String, desc: 'Return merge requests for a specific milestone' - optional :labels, type: String, desc: 'Comma-separated list of label names' - optional :created_after, type: DateTime, desc: 'Return merge requests created after the specified time' - optional :created_before, type: DateTime, desc: 'Return merge requests created before the specified time' - optional :updated_after, type: DateTime, desc: 'Return merge requests updated after the specified time' - optional :updated_before, type: DateTime, desc: 'Return merge requests updated before the specified time' - optional :view, type: String, values: %w[simple], desc: 'If simple, returns the `iid`, URL, title, description, and basic state of merge request' - optional :author_id, type: Integer, desc: 'Return merge requests which are authored by the user with the given ID' + optional :state, type: String, values: %w[opened closed locked merged all], default: "all", + desc: "Return opened, closed, locked, merged, or all merge requests" + optional :order_by, type: String, values: %w[created_at updated_at], default: "created_at", + desc: "Return merge requests ordered by `created_at` or `updated_at` fields." + optional :sort, type: String, values: %w[asc desc], default: "desc", + desc: "Return merge requests sorted in `asc` or `desc` order." + optional :milestone, type: String, desc: "Return merge requests for a specific milestone" + optional :labels, type: String, desc: "Comma-separated list of label names" + optional :created_after, type: DateTime, desc: "Return merge requests created after the specified time" + optional :created_before, type: DateTime, desc: "Return merge requests created before the specified time" + optional :updated_after, type: DateTime, desc: "Return merge requests updated after the specified time" + optional :updated_before, type: DateTime, desc: "Return merge requests updated before the specified time" + optional :view, type: String, values: %w[simple], desc: "If simple, returns the `iid`, URL, title, description, and basic state of merge request" + optional :author_id, type: Integer, desc: "Return merge requests which are authored by the user with the given ID" optional :assignee_id, types: [Integer, String], integer_none_any: true, - desc: 'Return merge requests which are assigned to the user with the given ID' + desc: "Return merge requests which are assigned to the user with the given ID" optional :scope, type: String, values: %w[created-by-me assigned-to-me created_by_me assigned_to_me all], - desc: 'Return merge requests for the given scope: `created_by_me`, `assigned_to_me` or `all`' - optional :my_reaction_emoji, type: String, desc: 'Return issues reacted by the authenticated user by the given emoji' - optional :source_branch, type: String, desc: 'Return merge requests with the given source branch' - optional :target_branch, type: String, desc: 'Return merge requests with the given target branch' - optional :search, type: String, desc: 'Search merge requests for text present in the title, description, or any combination of these' - optional :in, type: String, desc: '`title`, `description`, or a string joining them with comma' - optional :wip, type: String, values: %w[yes no], desc: 'Search merge requests for WIP in the title' + desc: "Return merge requests for the given scope: `created_by_me`, `assigned_to_me` or `all`" + optional :my_reaction_emoji, type: String, desc: "Return issues reacted by the authenticated user by the given emoji" + optional :source_branch, type: String, desc: "Return merge requests with the given source branch" + optional :target_branch, type: String, desc: "Return merge requests with the given target branch" + optional :search, type: String, desc: "Search merge requests for text present in the title, description, or any combination of these" + optional :in, type: String, desc: "`title`, `description`, or a string joining them with comma" + optional :wip, type: String, values: %w[yes no], desc: "Search merge requests for WIP in the title" use :pagination end end resource :merge_requests do - desc 'List merge requests' do + desc "List merge requests" do success Entities::MergeRequestBasic end params do use :merge_requests_params - optional :scope, type: String, values: %w[created-by-me assigned-to-me created_by_me assigned_to_me all], default: 'created_by_me', - desc: 'Return merge requests for the given scope: `created_by_me`, `assigned_to_me` or `all`' + optional :scope, type: String, values: %w[created-by-me assigned-to-me created_by_me assigned_to_me all], default: "created_by_me", + desc: "Return merge requests for the given scope: `created_by_me`, `assigned_to_me` or `all`" end get do - authenticate! unless params[:scope] == 'all' + authenticate! unless params[:scope] == "all" merge_requests = find_merge_requests present merge_requests, serializer_options_for(merge_requests) @@ -134,10 +134,10 @@ module API end params do - requires :id, type: String, desc: 'The ID of a group' + requires :id, type: String, desc: "The ID of a group" end resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get a list of group merge requests' do + desc "Get a list of group merge requests" do success Entities::MergeRequestBasic end params do @@ -153,7 +153,7 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do include TimeTrackingEndpoints @@ -176,25 +176,25 @@ module API end params :optional_params do - optional :description, type: String, desc: 'The description of the merge request' - optional :assignee_id, type: Integer, desc: 'The ID of a user to assign the merge request' - optional :milestone_id, type: Integer, desc: 'The ID of a milestone to assign the merge request' - optional :labels, type: String, desc: 'Comma-separated list of label names' - optional :remove_source_branch, type: Boolean, desc: 'Delete source branch when merging' - optional :allow_collaboration, type: Boolean, desc: 'Allow commits from members who can merge to the target branch' - optional :allow_maintainer_to_push, type: Boolean, as: :allow_collaboration, desc: '[deprecated] See allow_collaboration' - optional :squash, type: Grape::API::Boolean, desc: 'When true, the commits will be squashed into a single commit on merge' + optional :description, type: String, desc: "The description of the merge request" + optional :assignee_id, type: Integer, desc: "The ID of a user to assign the merge request" + optional :milestone_id, type: Integer, desc: "The ID of a milestone to assign the merge request" + optional :labels, type: String, desc: "Comma-separated list of label names" + optional :remove_source_branch, type: Boolean, desc: "Delete source branch when merging" + optional :allow_collaboration, type: Boolean, desc: "Allow commits from members who can merge to the target branch" + optional :allow_maintainer_to_push, type: Boolean, as: :allow_collaboration, desc: "[deprecated] See allow_collaboration" + optional :squash, type: Grape::API::Boolean, desc: "When true, the commits will be squashed into a single commit on merge" use :optional_params_ee end end - desc 'List merge requests' do + desc "List merge requests" do success Entities::MergeRequestBasic end params do use :merge_requests_params - optional :iids, type: Array[Integer], desc: 'The IID array of merge requests' + optional :iids, type: Array[Integer], desc: "The IID array of merge requests" end get ":id/merge_requests" do authorize! :read_merge_request, user_project @@ -207,19 +207,19 @@ module API present merge_requests, options end - desc 'Create a merge request' do + desc "Create a merge request" do success Entities::MergeRequest end params do - requires :title, type: String, desc: 'The title of the merge request' - requires :source_branch, type: String, desc: 'The source branch' - requires :target_branch, type: String, desc: 'The target branch' + requires :title, type: String, desc: "The title of the merge request" + requires :source_branch, type: String, desc: "The source branch" + requires :target_branch, type: String, desc: "The target branch" optional :target_project_id, type: Integer, - desc: 'The target project of the merge request defaults to the :id of the project' + desc: "The target project of the merge request defaults to the :id of the project" use :optional_params end post ":id/merge_requests" do - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42316') + Gitlab::QueryLimiting.whitelist("https://gitlab.com/gitlab-org/gitlab-ce/issues/42316") authorize! :create_merge_request_from, user_project @@ -235,9 +235,9 @@ module API end end - desc 'Delete a merge request' + desc "Delete a merge request" params do - requires :merge_request_iid, type: Integer, desc: 'The IID of a merge request' + requires :merge_request_iid, type: Integer, desc: "The IID of a merge request" end delete ":id/merge_requests/:merge_request_iid" do merge_request = find_project_merge_request(params[:merge_request_iid]) @@ -250,15 +250,15 @@ module API end params do - requires :merge_request_iid, type: Integer, desc: 'The IID of a merge request' - optional :render_html, type: Boolean, desc: 'Returns the description and title rendered HTML' - optional :include_diverged_commits_count, type: Boolean, desc: 'Returns the commits count behind the target branch' - optional :include_rebase_in_progress, type: Boolean, desc: 'Returns whether a rebase operation is ongoing ' + requires :merge_request_iid, type: Integer, desc: "The IID of a merge request" + optional :render_html, type: Boolean, desc: "Returns the description and title rendered HTML" + optional :include_diverged_commits_count, type: Boolean, desc: "Returns the commits count behind the target branch" + optional :include_rebase_in_progress, type: Boolean, desc: "Returns whether a rebase operation is ongoing " end - desc 'Get a single merge request' do + desc "Get a single merge request" do success Entities::MergeRequest end - get ':id/merge_requests/:merge_request_iid' do + get ":id/merge_requests/:merge_request_iid" do merge_request = find_merge_request_with_access(params[:merge_request_iid]) present merge_request, @@ -270,59 +270,59 @@ module API include_rebase_in_progress: params[:include_rebase_in_progress] end - desc 'Get the participants of a merge request' do + desc "Get the participants of a merge request" do success Entities::UserBasic end - get ':id/merge_requests/:merge_request_iid/participants' do + get ":id/merge_requests/:merge_request_iid/participants" do merge_request = find_merge_request_with_access(params[:merge_request_iid]) participants = ::Kaminari.paginate_array(merge_request.participants) present paginate(participants), with: Entities::UserBasic end - desc 'Get the commits of a merge request' do + desc "Get the commits of a merge request" do success Entities::Commit end - get ':id/merge_requests/:merge_request_iid/commits' do + get ":id/merge_requests/:merge_request_iid/commits" do merge_request = find_merge_request_with_access(params[:merge_request_iid]) commits = ::Kaminari.paginate_array(merge_request.commits) present paginate(commits), with: Entities::Commit end - desc 'Show the merge request changes' do + desc "Show the merge request changes" do success Entities::MergeRequestChanges end - get ':id/merge_requests/:merge_request_iid/changes' do + get ":id/merge_requests/:merge_request_iid/changes" do merge_request = find_merge_request_with_access(params[:merge_request_iid]) present merge_request, with: Entities::MergeRequestChanges, current_user: current_user, project: user_project end - desc 'Get the merge request pipelines' do + desc "Get the merge request pipelines" do success Entities::PipelineBasic end - get ':id/merge_requests/:merge_request_iid/pipelines' do + get ":id/merge_requests/:merge_request_iid/pipelines" do pipelines = merge_request_pipelines_with_access present paginate(pipelines), with: Entities::PipelineBasic end - desc 'Update a merge request' do + desc "Update a merge request" do success Entities::MergeRequest end params do - optional :title, type: String, allow_blank: false, desc: 'The title of the merge request' - optional :target_branch, type: String, allow_blank: false, desc: 'The target branch' + optional :title, type: String, allow_blank: false, desc: "The title of the merge request" + optional :target_branch, type: String, allow_blank: false, desc: "The target branch" optional :state_event, type: String, values: %w[close reopen], - desc: 'Status of the merge request' - optional :discussion_locked, type: Boolean, desc: 'Whether the MR discussion is locked' + desc: "Status of the merge request" + optional :discussion_locked, type: Boolean, desc: "Whether the MR discussion is locked" use :optional_params at_least_one_of(*::API::MergeRequests.update_params_at_least_one_of) end - put ':id/merge_requests/:merge_request_iid' do - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42318') + put ":id/merge_requests/:merge_request_iid" do + Gitlab::QueryLimiting.whitelist("https://gitlab.com/gitlab-org/gitlab-ce/issues/42318") merge_request = find_merge_request_with_access(params.delete(:merge_request_iid), :update_merge_request) @@ -338,21 +338,21 @@ module API end end - desc 'Merge a merge request' do + desc "Merge a merge request" do success Entities::MergeRequest end params do - optional :merge_commit_message, type: String, desc: 'Custom merge commit message' - optional :squash_commit_message, type: String, desc: 'Custom squash commit message' + optional :merge_commit_message, type: String, desc: "Custom merge commit message" + optional :squash_commit_message, type: String, desc: "Custom squash commit message" optional :should_remove_source_branch, type: Boolean, - desc: 'When true, the source branch will be deleted if possible' + desc: "When true, the source branch will be deleted if possible" optional :merge_when_pipeline_succeeds, type: Boolean, - desc: 'When true, this merge request will be merged when the pipeline succeeds' - optional :sha, type: String, desc: 'When present, must have the HEAD SHA of the source branch' - optional :squash, type: Grape::API::Boolean, desc: 'When true, the commits will be squashed into a single commit on merge' + desc: "When true, this merge request will be merged when the pipeline succeeds" + optional :sha, type: String, desc: "When present, must have the HEAD SHA of the source branch" + optional :squash, type: Grape::API::Boolean, desc: "When true, the commits will be squashed into a single commit on merge" end - put ':id/merge_requests/:merge_request_iid/merge' do - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42317') + put ":id/merge_requests/:merge_request_iid/merge" do + Gitlab::QueryLimiting.whitelist("https://gitlab.com/gitlab-org/gitlab-ce/issues/42317") merge_request = find_project_merge_request(params[:merge_request_iid]) merge_when_pipeline_succeeds = to_boolean(params[:merge_when_pipeline_succeeds]) @@ -363,7 +363,7 @@ module API not_allowed! unless merge_request.mergeable_state?(skip_ci_check: merge_when_pipeline_succeeds) - render_api_error!('Branch cannot be merged', 406) unless merge_request.mergeable?(skip_ci_check: merge_when_pipeline_succeeds) + render_api_error!("Branch cannot be merged", 406) unless merge_request.mergeable?(skip_ci_check: merge_when_pipeline_succeeds) check_sha_param!(params, merge_request) @@ -388,17 +388,17 @@ module API present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project end - desc 'Merge a merge request to its default temporary merge ref path' + desc "Merge a merge request to its default temporary merge ref path" params do - optional :merge_commit_message, type: String, desc: 'Custom merge commit message' + optional :merge_commit_message, type: String, desc: "Custom merge commit message" end - put ':id/merge_requests/:merge_request_iid/merge_to_ref' do + put ":id/merge_requests/:merge_request_iid/merge_to_ref" do merge_request = find_project_merge_request(params[:merge_request_iid]) authorize! :admin_merge_request, user_project merge_params = { - commit_message: params[:merge_commit_message] + commit_message: params[:merge_commit_message], } result = ::MergeRequests::MergeToRefService @@ -416,7 +416,7 @@ module API desc 'Cancel merge if "Merge When Pipeline Succeeds" is enabled' do success Entities::MergeRequest end - post ':id/merge_requests/:merge_request_iid/cancel_merge_when_pipeline_succeeds' do + post ":id/merge_requests/:merge_request_iid/cancel_merge_when_pipeline_succeeds" do merge_request = find_project_merge_request(params[:merge_request_iid]) unauthorized! unless merge_request.can_cancel_merge_when_pipeline_succeeds?(current_user) @@ -426,10 +426,10 @@ module API .cancel(merge_request) end - desc 'Rebase the merge request against its target branch' do - detail 'This feature was added in GitLab 11.6' + desc "Rebase the merge request against its target branch" do + detail "This feature was added in GitLab 11.6" end - put ':id/merge_requests/:merge_request_iid/rebase' do + put ":id/merge_requests/:merge_request_iid/rebase" do merge_request = find_project_merge_request(params[:merge_request_iid]) authorize_push_to_merge_request!(merge_request) @@ -439,13 +439,13 @@ module API status :accepted end - desc 'List issues that will be closed on merge' do + desc "List issues that will be closed on merge" do success Entities::MRNote end params do use :pagination end - get ':id/merge_requests/:merge_request_iid/closes_issues' do + get ":id/merge_requests/:merge_request_iid/closes_issues" do merge_request = find_merge_request_with_access(params[:merge_request_iid]) issues = ::Kaminari.paginate_array(merge_request.visible_closing_issues_for(current_user)) issues = paginate(issues) diff --git a/lib/api/milestone_responses.rb b/lib/api/milestone_responses.rb index a0ca39b69d4..d2e31a1b57c 100644 --- a/lib/api/milestone_responses.rb +++ b/lib/api/milestone_responses.rb @@ -7,24 +7,24 @@ module API included do helpers do params :optional_params do - optional :description, type: String, desc: 'The description of the milestone' - optional :due_date, type: String, desc: 'The due date of the milestone. The ISO 8601 date format (%Y-%m-%d)' - optional :start_date, type: String, desc: 'The start date of the milestone. The ISO 8601 date format (%Y-%m-%d)' + optional :description, type: String, desc: "The description of the milestone" + optional :due_date, type: String, desc: "The due date of the milestone. The ISO 8601 date format (%Y-%m-%d)" + optional :start_date, type: String, desc: "The start date of the milestone. The ISO 8601 date format (%Y-%m-%d)" end params :list_params do - optional :state, type: String, values: %w[active closed all], default: 'all', + optional :state, type: String, values: %w[active closed all], default: "all", desc: 'Return "active", "closed", or "all" milestones' - optional :iids, type: Array[Integer], desc: 'The IIDs of the milestones' - optional :search, type: String, desc: 'The search criteria for the title or description of the milestone' + optional :iids, type: Array[Integer], desc: "The IIDs of the milestones" + optional :search, type: String, desc: "The search criteria for the title or description of the milestone" use :pagination end params :update_params do - requires :milestone_id, type: Integer, desc: 'The milestone ID number' - optional :title, type: String, desc: 'The title of the milestone' + requires :milestone_id, type: Integer, desc: "The milestone ID number" + optional :title, type: String, desc: "The title of the milestone" optional :state_event, type: String, values: %w[close activate], - desc: 'The state event of the milestone ' + desc: "The state event of the milestone " use :optional_params at_least_one_of :title, :description, :start_date, :due_date, :state_event end @@ -78,7 +78,7 @@ module API end def build_finder_params(milestone, parent) - finder_params = { milestone_title: milestone.title, sort: 'label_priority' } + finder_params = {milestone_title: milestone.title, sort: "label_priority"} if parent.is_a?(Group) finder_params.merge(group_id: parent.id) diff --git a/lib/api/namespaces.rb b/lib/api/namespaces.rb index 3cc09f6ac3f..4e743b74468 100644 --- a/lib/api/namespaces.rb +++ b/lib/api/namespaces.rb @@ -18,7 +18,7 @@ module API end resource :namespaces do - desc 'Get a namespaces list' do + desc "Get a namespaces list" do success Entities::Namespace end params do @@ -32,18 +32,18 @@ module API namespaces = namespaces.search(params[:search]) if params[:search].present? - options = { with: Entities::Namespace, current_user: current_user } + options = {with: Entities::Namespace, current_user: current_user} present paginate(namespaces), options.reverse_merge(custom_namespace_present_options) end - desc 'Get a namespace by ID' do + desc "Get a namespace by ID" do success Entities::Namespace end params do requires :id, type: String, desc: "Namespace's ID or path" end - get ':id', requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do + get ":id", requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do present user_namespace, with: Entities::Namespace, current_user: current_user end end diff --git a/lib/api/notes.rb b/lib/api/notes.rb index f7bd092ce50..2b4bcbc9aa2 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -23,11 +23,11 @@ module API success Entities::Note end params do - requires :noteable_id, type: Integer, desc: 'The ID of the noteable' - optional :order_by, type: String, values: %w[created_at updated_at], default: 'created_at', - desc: 'Return notes ordered by `created_at` or `updated_at` fields.' - optional :sort, type: String, values: %w[asc desc], default: 'desc', - desc: 'Return notes sorted in `asc` or `desc` order.' + requires :noteable_id, type: Integer, desc: "The ID of the noteable" + optional :order_by, type: String, values: %w[created_at updated_at], default: "created_at", + desc: "Return notes ordered by `created_at` or `updated_at` fields." + optional :sort, type: String, values: %w[asc desc], default: "desc", + desc: "Return notes sorted in `asc` or `desc` order." use :pagination end # rubocop: disable CodeReuse/ActiveRecord @@ -45,7 +45,7 @@ module API # mismatch between the pagination headers info and the actual notes # array returned, but this is really a edge-case. paginate(raw_notes) - .reject { |n| n.cross_reference_not_visible_for?(current_user) } + .reject { |n| n.cross_reference_not_visible_for?(current_user) } present notes, with: Entities::Note end # rubocop: enable CodeReuse/ActiveRecord @@ -54,8 +54,8 @@ module API success Entities::Note end params do - requires :note_id, type: Integer, desc: 'The ID of a note' - requires :noteable_id, type: Integer, desc: 'The ID of the noteable' + requires :note_id, type: Integer, desc: "The ID of a note" + requires :noteable_id, type: Integer, desc: "The ID of the noteable" end get ":id/#{noteables_str}/:noteable_id/notes/:note_id" do noteable = find_noteable(parent_type, noteables_str, params[:noteable_id]) @@ -66,9 +66,9 @@ module API success Entities::Note end params do - requires :noteable_id, type: Integer, desc: 'The ID of the noteable' - requires :body, type: String, desc: 'The content of a note' - optional :created_at, type: String, desc: 'The creation date of the note' + requires :noteable_id, type: Integer, desc: "The ID of the noteable" + requires :body, type: String, desc: "The content of a note" + optional :created_at, type: String, desc: "The creation date of the note" end post ":id/#{noteables_str}/:noteable_id/notes" do noteable = find_noteable(parent_type, noteables_str, params[:noteable_id]) @@ -77,7 +77,7 @@ module API note: params[:body], noteable_type: noteables_str.classify, noteable_id: noteable.id, - created_at: params[:created_at] + created_at: params[:created_at], } note = create_note(noteable, opts) @@ -93,9 +93,9 @@ module API success Entities::Note end params do - requires :noteable_id, type: Integer, desc: 'The ID of the noteable' - requires :note_id, type: Integer, desc: 'The ID of a note' - requires :body, type: String, desc: 'The content of a note' + requires :noteable_id, type: Integer, desc: "The ID of the noteable" + requires :note_id, type: Integer, desc: "The ID of a note" + requires :body, type: String, desc: "The content of a note" end put ":id/#{noteables_str}/:noteable_id/notes/:note_id" do noteable = find_noteable(parent_type, noteables_str, params[:noteable_id]) @@ -107,8 +107,8 @@ module API success Entities::Note end params do - requires :noteable_id, type: Integer, desc: 'The ID of the noteable' - requires :note_id, type: Integer, desc: 'The ID of a note' + requires :noteable_id, type: Integer, desc: "The ID of the noteable" + requires :note_id, type: Integer, desc: "The ID of a note" end delete ":id/#{noteables_str}/:noteable_id/notes/:note_id" do noteable = find_noteable(parent_type, noteables_str, params[:noteable_id]) diff --git a/lib/api/notification_settings.rb b/lib/api/notification_settings.rb index 8cb46bd3ad6..9ebe5e912cb 100644 --- a/lib/api/notification_settings.rb +++ b/lib/api/notification_settings.rb @@ -8,8 +8,8 @@ module API helpers ::API::Helpers::MembersHelpers resource :notification_settings do - desc 'Get global notification level settings and email, defaults to Participate' do - detail 'This feature was introduced in GitLab 8.12' + desc "Get global notification level settings and email, defaults to Participate" do + detail "This feature was introduced in GitLab 8.12" success Entities::GlobalNotificationSetting end get do @@ -18,15 +18,15 @@ module API present notification_setting, with: Entities::GlobalNotificationSetting end - desc 'Update global notification level settings and email, defaults to Participate' do - detail 'This feature was introduced in GitLab 8.12' + desc "Update global notification level settings and email, defaults to Participate" do + detail "This feature was introduced in GitLab 8.12" success Entities::GlobalNotificationSetting end params do - optional :level, type: String, desc: 'The global notification level' - optional :notification_email, type: String, desc: 'The email address to send notifications' + optional :level, type: String, desc: "The global notification level" + optional :notification_email, type: String, desc: "The email address to send notifications" NotificationSetting.email_events.each do |event| - optional event, type: Boolean, desc: 'Enable/disable this notification' + optional event, type: Boolean, desc: "Enable/disable this notification" end end put do @@ -60,7 +60,7 @@ module API end resource source_type.pluralize, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do desc "Get #{source_type} level notification level settings, defaults to Global" do - detail 'This feature was introduced in GitLab 8.12' + detail "This feature was introduced in GitLab 8.12" success Entities::NotificationSetting end get ":id/notification_settings" do @@ -72,13 +72,13 @@ module API end desc "Update #{source_type} level notification level settings, defaults to Global" do - detail 'This feature was introduced in GitLab 8.12' + detail "This feature was introduced in GitLab 8.12" success Entities::NotificationSetting end params do optional :level, type: String, desc: "The #{source_type} notification level" NotificationSetting.email_events(source_class).each do |event| - optional event, type: Boolean, desc: 'Enable/disable this notification' + optional event, type: Boolean, desc: "Enable/disable this notification" end end put ":id/notification_settings" do diff --git a/lib/api/pages_domains.rb b/lib/api/pages_domains.rb index 78442f465bd..05e1363ab16 100644 --- a/lib/api/pages_domains.rb +++ b/lib/api/pages_domains.rb @@ -17,7 +17,7 @@ module API helpers do # rubocop: disable CodeReuse/ActiveRecord def find_pages_domain! - user_project.pages_domains.find_by(domain: params[:domain]) || not_found!('PagesDomain') + user_project.pages_domains.find_by(domain: params[:domain]) || not_found!("PagesDomain") end # rubocop: enable CodeReuse/ActiveRecord @@ -28,7 +28,7 @@ module API def normalize_params_file_to_string params.each do |k, v| if v.is_a?(Hash) && v.key?(:tempfile) - params[k] = v[:tempfile].to_a.join('') + params[k] = v[:tempfile].to_a.join("") end end end @@ -52,14 +52,14 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do before do require_pages_enabled! end - desc 'Get all pages domains' do + desc "Get all pages domains" do success Entities::PagesDomain end params do @@ -73,11 +73,11 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get a single pages domain' do + desc "Get a single pages domain" do success Entities::PagesDomain end params do - requires :domain, type: String, desc: 'The domain' + requires :domain, type: String, desc: "The domain" end get ":id/pages/domains/:domain", requirements: PAGES_DOMAINS_ENDPOINT_REQUIREMENTS do authorize! :read_pages, user_project @@ -85,13 +85,13 @@ module API present pages_domain, with: Entities::PagesDomain end - desc 'Create a new pages domain' do + desc "Create a new pages domain" do success Entities::PagesDomain end params do - requires :domain, type: String, desc: 'The domain' - optional :certificate, allow_blank: false, types: [File, String], desc: 'The certificate' - optional :key, allow_blank: false, types: [File, String], desc: 'The key' + requires :domain, type: String, desc: "The domain" + optional :certificate, allow_blank: false, types: [File, String], desc: "The certificate" + optional :key, allow_blank: false, types: [File, String], desc: "The key" all_or_none_of :certificate, :key end post ":id/pages/domains" do @@ -107,11 +107,11 @@ module API end end - desc 'Updates a pages domain' + desc "Updates a pages domain" params do - requires :domain, type: String, desc: 'The domain' - optional :certificate, allow_blank: false, types: [File, String], desc: 'The certificate' - optional :key, allow_blank: false, types: [File, String], desc: 'The key' + requires :domain, type: String, desc: "The domain" + optional :certificate, allow_blank: false, types: [File, String], desc: "The certificate" + optional :key, allow_blank: false, types: [File, String], desc: "The key" end put ":id/pages/domains/:domain", requirements: PAGES_DOMAINS_ENDPOINT_REQUIREMENTS do authorize! :update_pages, user_project @@ -130,9 +130,9 @@ module API end end - desc 'Delete a pages domain' + desc "Delete a pages domain" params do - requires :domain, type: String, desc: 'The domain' + requires :domain, type: String, desc: "The domain" end delete ":id/pages/domains/:domain", requirements: PAGES_DOMAINS_ENDPOINT_REQUIREMENTS do authorize! :update_pages, user_project diff --git a/lib/api/pagination_params.rb b/lib/api/pagination_params.rb index ae03595eb25..1fe0d7fb3f0 100644 --- a/lib/api/pagination_params.rb +++ b/lib/api/pagination_params.rb @@ -17,8 +17,8 @@ module API included do helpers do params :pagination do - optional :page, type: Integer, default: 1, desc: 'Current page number' - optional :per_page, type: Integer, default: 20, desc: 'Number of items per page' + optional :page, type: Integer, default: 1, desc: "Current page number" + optional :per_page, type: Integer, default: 20, desc: "Number of items per page" end end end diff --git a/lib/api/pipeline_schedules.rb b/lib/api/pipeline_schedules.rb index c86b50d3736..687b1bd5af5 100644 --- a/lib/api/pipeline_schedules.rb +++ b/lib/api/pipeline_schedules.rb @@ -7,19 +7,19 @@ module API before { authenticate! } params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get all pipeline schedules' do + desc "Get all pipeline schedules" do success Entities::PipelineSchedule end params do use :pagination optional :scope, type: String, values: %w[active inactive], - desc: 'The scope of pipeline schedules' + desc: "The scope of pipeline schedules" end # rubocop: disable CodeReuse/ActiveRecord - get ':id/pipeline_schedules' do + get ":id/pipeline_schedules" do authorize! :read_pipeline_schedule, user_project schedules = PipelineSchedulesFinder.new(user_project).execute(scope: params[:scope]) @@ -28,27 +28,27 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get a single pipeline schedule' do + desc "Get a single pipeline schedule" do success Entities::PipelineScheduleDetails end params do - requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' + requires :pipeline_schedule_id, type: Integer, desc: "The pipeline schedule id" end - get ':id/pipeline_schedules/:pipeline_schedule_id' do + get ":id/pipeline_schedules/:pipeline_schedule_id" do present pipeline_schedule, with: Entities::PipelineScheduleDetails end - desc 'Create a new pipeline schedule' do + desc "Create a new pipeline schedule" do success Entities::PipelineScheduleDetails end params do - requires :description, type: String, desc: 'The description of pipeline schedule' - requires :ref, type: String, desc: 'The branch/tag name will be triggered', allow_blank: false - requires :cron, type: String, desc: 'The cron' - optional :cron_timezone, type: String, default: 'UTC', desc: 'The timezone' - optional :active, type: Boolean, default: true, desc: 'The activation of pipeline schedule' + requires :description, type: String, desc: "The description of pipeline schedule" + requires :ref, type: String, desc: "The branch/tag name will be triggered", allow_blank: false + requires :cron, type: String, desc: "The cron" + optional :cron_timezone, type: String, default: "UTC", desc: "The timezone" + optional :active, type: Boolean, default: true, desc: "The activation of pipeline schedule" end - post ':id/pipeline_schedules' do + post ":id/pipeline_schedules" do authorize! :create_pipeline_schedule, user_project pipeline_schedule = Ci::CreatePipelineScheduleService @@ -62,18 +62,18 @@ module API end end - desc 'Edit a pipeline schedule' do + desc "Edit a pipeline schedule" do success Entities::PipelineScheduleDetails end params do - requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' - optional :description, type: String, desc: 'The description of pipeline schedule' - optional :ref, type: String, desc: 'The branch/tag name will be triggered' - optional :cron, type: String, desc: 'The cron' - optional :cron_timezone, type: String, desc: 'The timezone' - optional :active, type: Boolean, desc: 'The activation of pipeline schedule' - end - put ':id/pipeline_schedules/:pipeline_schedule_id' do + requires :pipeline_schedule_id, type: Integer, desc: "The pipeline schedule id" + optional :description, type: String, desc: "The description of pipeline schedule" + optional :ref, type: String, desc: "The branch/tag name will be triggered" + optional :cron, type: String, desc: "The cron" + optional :cron_timezone, type: String, desc: "The timezone" + optional :active, type: Boolean, desc: "The activation of pipeline schedule" + end + put ":id/pipeline_schedules/:pipeline_schedule_id" do authorize! :update_pipeline_schedule, pipeline_schedule if pipeline_schedule.update(declared_params(include_missing: false)) @@ -83,13 +83,13 @@ module API end end - desc 'Take ownership of a pipeline schedule' do + desc "Take ownership of a pipeline schedule" do success Entities::PipelineScheduleDetails end params do - requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' + requires :pipeline_schedule_id, type: Integer, desc: "The pipeline schedule id" end - post ':id/pipeline_schedules/:pipeline_schedule_id/take_ownership' do + post ":id/pipeline_schedules/:pipeline_schedule_id/take_ownership" do authorize! :update_pipeline_schedule, pipeline_schedule if pipeline_schedule.own!(current_user) @@ -99,27 +99,27 @@ module API end end - desc 'Delete a pipeline schedule' do + desc "Delete a pipeline schedule" do success Entities::PipelineScheduleDetails end params do - requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' + requires :pipeline_schedule_id, type: Integer, desc: "The pipeline schedule id" end - delete ':id/pipeline_schedules/:pipeline_schedule_id' do + delete ":id/pipeline_schedules/:pipeline_schedule_id" do authorize! :admin_pipeline_schedule, pipeline_schedule destroy_conditionally!(pipeline_schedule) end - desc 'Create a new pipeline schedule variable' do + desc "Create a new pipeline schedule variable" do success Entities::Variable end params do - requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' - requires :key, type: String, desc: 'The key of the variable' - requires :value, type: String, desc: 'The value of the variable' + requires :pipeline_schedule_id, type: Integer, desc: "The pipeline schedule id" + requires :key, type: String, desc: "The key of the variable" + requires :value, type: String, desc: "The value of the variable" end - post ':id/pipeline_schedules/:pipeline_schedule_id/variables' do + post ":id/pipeline_schedules/:pipeline_schedule_id/variables" do authorize! :update_pipeline_schedule, pipeline_schedule variable_params = declared_params(include_missing: false) @@ -131,15 +131,15 @@ module API end end - desc 'Edit a pipeline schedule variable' do + desc "Edit a pipeline schedule variable" do success Entities::Variable end params do - requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' - requires :key, type: String, desc: 'The key of the variable' - optional :value, type: String, desc: 'The value of the variable' + requires :pipeline_schedule_id, type: Integer, desc: "The pipeline schedule id" + requires :key, type: String, desc: "The key of the variable" + optional :value, type: String, desc: "The value of the variable" end - put ':id/pipeline_schedules/:pipeline_schedule_id/variables/:key' do + put ":id/pipeline_schedules/:pipeline_schedule_id/variables/:key" do authorize! :update_pipeline_schedule, pipeline_schedule if pipeline_schedule_variable.update(declared_params(include_missing: false)) @@ -149,14 +149,14 @@ module API end end - desc 'Delete a pipeline schedule variable' do + desc "Delete a pipeline schedule variable" do success Entities::Variable end params do - requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' - requires :key, type: String, desc: 'The key of the variable' + requires :pipeline_schedule_id, type: Integer, desc: "The pipeline schedule id" + requires :key, type: String, desc: "The key of the variable" end - delete ':id/pipeline_schedules/:pipeline_schedule_id/variables/:key' do + delete ":id/pipeline_schedules/:pipeline_schedule_id/variables/:key" do authorize! :admin_pipeline_schedule, pipeline_schedule status :accepted @@ -173,7 +173,7 @@ module API .preload(:owner, :last_pipeline) .find_by(id: params.delete(:pipeline_schedule_id)).tap do |pipeline_schedule| unless can?(current_user, :read_pipeline_schedule, pipeline_schedule) - not_found!('Pipeline Schedule') + not_found!("Pipeline Schedule") end end end @@ -184,7 +184,7 @@ module API @pipeline_schedule_variable ||= pipeline_schedule.variables.find_by(key: params[:key]).tap do |pipeline_schedule_variable| unless pipeline_schedule_variable - not_found!('Pipeline Schedule Variable') + not_found!("Pipeline Schedule Variable") end end end diff --git a/lib/api/pipelines.rb b/lib/api/pipelines.rb index ac8fe98e55e..4c79cd6feaa 100644 --- a/lib/api/pipelines.rb +++ b/lib/api/pipelines.rb @@ -7,47 +7,47 @@ module API before { authenticate! } params do - requires :id, type: String, desc: 'The project ID' + requires :id, type: String, desc: "The project ID" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get all Pipelines of the project' do - detail 'This feature was introduced in GitLab 8.11.' + desc "Get all Pipelines of the project" do + detail "This feature was introduced in GitLab 8.11." success Entities::PipelineBasic end params do use :pagination optional :scope, type: String, values: %w[running pending finished branches tags], - desc: 'The scope of pipelines' + desc: "The scope of pipelines" optional :status, type: String, values: HasStatus::AVAILABLE_STATUSES, - desc: 'The status of pipelines' - optional :ref, type: String, desc: 'The ref of pipelines' - optional :sha, type: String, desc: 'The sha of pipelines' - optional :yaml_errors, type: Boolean, desc: 'Returns pipelines with invalid configurations' - optional :name, type: String, desc: 'The name of the user who triggered pipelines' - optional :username, type: String, desc: 'The username of the user who triggered pipelines' - optional :order_by, type: String, values: PipelinesFinder::ALLOWED_INDEXED_COLUMNS, default: 'id', - desc: 'Order pipelines' - optional :sort, type: String, values: %w[asc desc], default: 'desc', - desc: 'Sort pipelines' - end - get ':id/pipelines' do + desc: "The status of pipelines" + optional :ref, type: String, desc: "The ref of pipelines" + optional :sha, type: String, desc: "The sha of pipelines" + optional :yaml_errors, type: Boolean, desc: "Returns pipelines with invalid configurations" + optional :name, type: String, desc: "The name of the user who triggered pipelines" + optional :username, type: String, desc: "The username of the user who triggered pipelines" + optional :order_by, type: String, values: PipelinesFinder::ALLOWED_INDEXED_COLUMNS, default: "id", + desc: "Order pipelines" + optional :sort, type: String, values: %w[asc desc], default: "desc", + desc: "Sort pipelines" + end + get ":id/pipelines" do authorize! :read_pipeline, user_project pipelines = PipelinesFinder.new(user_project, current_user, params).execute present paginate(pipelines), with: Entities::PipelineBasic end - desc 'Create a new pipeline' do - detail 'This feature was introduced in GitLab 8.14' + desc "Create a new pipeline" do + detail "This feature was introduced in GitLab 8.14" success Entities::Pipeline end params do - requires :ref, type: String, desc: 'Reference' - optional :variables, Array, desc: 'Array of variables available in the pipeline' + requires :ref, type: String, desc: "Reference" + optional :variables, Array, desc: "Array of variables available in the pipeline" end # rubocop: disable CodeReuse/ActiveRecord - post ':id/pipeline' do - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42124') + post ":id/pipeline" do + Gitlab::QueryLimiting.whitelist("https://gitlab.com/gitlab-org/gitlab-ce/issues/42124") authorize! :create_pipeline, user_project @@ -56,9 +56,9 @@ module API .except(:variables) new_pipeline = Ci::CreatePipelineService.new(user_project, - current_user, - pipeline_params) - .execute(:api, ignore_skip_ci: true, save_on_errors: false) + current_user, + pipeline_params) + .execute(:api, ignore_skip_ci: true, save_on_errors: false) if new_pipeline.persisted? present new_pipeline, with: Entities::Pipeline @@ -68,27 +68,27 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Gets a specific pipeline for the project' do - detail 'This feature was introduced in GitLab 8.11' + desc "Gets a specific pipeline for the project" do + detail "This feature was introduced in GitLab 8.11" success Entities::Pipeline end params do - requires :pipeline_id, type: Integer, desc: 'The pipeline ID' + requires :pipeline_id, type: Integer, desc: "The pipeline ID" end - get ':id/pipelines/:pipeline_id' do + get ":id/pipelines/:pipeline_id" do authorize! :read_pipeline, pipeline present pipeline, with: Entities::Pipeline end - desc 'Deletes a pipeline' do - detail 'This feature was introduced in GitLab 11.6' - http_codes [[204, 'Pipeline was deleted'], [403, 'Forbidden']] + desc "Deletes a pipeline" do + detail "This feature was introduced in GitLab 11.6" + http_codes [[204, "Pipeline was deleted"], [403, "Forbidden"]] end params do - requires :pipeline_id, type: Integer, desc: 'The pipeline ID' + requires :pipeline_id, type: Integer, desc: "The pipeline ID" end - delete ':id/pipelines/:pipeline_id' do + delete ":id/pipelines/:pipeline_id" do authorize! :destroy_pipeline, pipeline destroy_conditionally!(pipeline) do @@ -96,14 +96,14 @@ module API end end - desc 'Retry builds in the pipeline' do - detail 'This feature was introduced in GitLab 8.11.' + desc "Retry builds in the pipeline" do + detail "This feature was introduced in GitLab 8.11." success Entities::Pipeline end params do - requires :pipeline_id, type: Integer, desc: 'The pipeline ID' + requires :pipeline_id, type: Integer, desc: "The pipeline ID" end - post ':id/pipelines/:pipeline_id/retry' do + post ":id/pipelines/:pipeline_id/retry" do authorize! :update_pipeline, pipeline pipeline.retry_failed(current_user) @@ -111,14 +111,14 @@ module API present pipeline, with: Entities::Pipeline end - desc 'Cancel all builds in the pipeline' do - detail 'This feature was introduced in GitLab 8.11.' + desc "Cancel all builds in the pipeline" do + detail "This feature was introduced in GitLab 8.11." success Entities::Pipeline end params do - requires :pipeline_id, type: Integer, desc: 'The pipeline ID' + requires :pipeline_id, type: Integer, desc: "The pipeline ID" end - post ':id/pipelines/:pipeline_id/cancel' do + post ":id/pipelines/:pipeline_id/cancel" do authorize! :update_pipeline, pipeline pipeline.cancel_running diff --git a/lib/api/project_clusters.rb b/lib/api/project_clusters.rb index c96261a7b57..5bcbb095584 100644 --- a/lib/api/project_clusters.rb +++ b/lib/api/project_clusters.rb @@ -17,53 +17,53 @@ module API end params do - requires :id, type: String, desc: 'The ID of the project' + requires :id, type: String, desc: "The ID of the project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get all clusters from the project' do - detail 'This feature was introduced in GitLab 11.7.' + desc "Get all clusters from the project" do + detail "This feature was introduced in GitLab 11.7." success Entities::Cluster end params do use :pagination end - get ':id/clusters' do + get ":id/clusters" do authorize! :read_cluster, user_project present paginate(clusters_for_current_user), with: Entities::Cluster end - desc 'Get specific cluster for the project' do - detail 'This feature was introduced in GitLab 11.7.' + desc "Get specific cluster for the project" do + detail "This feature was introduced in GitLab 11.7." success Entities::ClusterProject end params do - requires :cluster_id, type: Integer, desc: 'The cluster ID' + requires :cluster_id, type: Integer, desc: "The cluster ID" end - get ':id/clusters/:cluster_id' do + get ":id/clusters/:cluster_id" do authorize! :read_cluster, cluster present cluster, with: Entities::ClusterProject end - desc 'Adds an existing cluster' do - detail 'This feature was introduced in GitLab 11.7.' + desc "Adds an existing cluster" do + detail "This feature was introduced in GitLab 11.7." success Entities::ClusterProject end params do - requires :name, type: String, desc: 'Cluster name' - optional :enabled, type: Boolean, default: true, desc: 'Determines if cluster is active or not, defaults to true' - requires :platform_kubernetes_attributes, type: Hash, desc: %q(Platform Kubernetes data) do - requires :api_url, type: String, allow_blank: false, desc: 'URL to access the Kubernetes API' - requires :token, type: String, desc: 'Token to authenticate against Kubernetes' - optional :ca_cert, type: String, desc: 'TLS certificate (needed if API is using a self-signed TLS certificate)' - optional :namespace, type: String, desc: 'Unique namespace related to Project' - optional :authorization_type, type: String, values: Clusters::Platforms::Kubernetes.authorization_types.keys, default: 'rbac', desc: 'Cluster authorization type, defaults to RBAC' + requires :name, type: String, desc: "Cluster name" + optional :enabled, type: Boolean, default: true, desc: "Determines if cluster is active or not, defaults to true" + requires :platform_kubernetes_attributes, type: Hash, desc: "Platform Kubernetes data" do + requires :api_url, type: String, allow_blank: false, desc: "URL to access the Kubernetes API" + requires :token, type: String, desc: "Token to authenticate against Kubernetes" + optional :ca_cert, type: String, desc: "TLS certificate (needed if API is using a self-signed TLS certificate)" + optional :namespace, type: String, desc: "Unique namespace related to Project" + optional :authorization_type, type: String, values: Clusters::Platforms::Kubernetes.authorization_types.keys, default: "rbac", desc: "Cluster authorization type, defaults to RBAC" end use :create_params_ee end - post ':id/clusters/user' do - authorize! :add_cluster, user_project, 'Instance does not support multiple Kubernetes clusters' + post ":id/clusters/user" do + authorize! :add_cluster, user_project, "Instance does not support multiple Kubernetes clusters" user_cluster = ::Clusters::CreateService .new(current_user, create_cluster_user_params) @@ -76,22 +76,22 @@ module API end end - desc 'Update an existing cluster' do - detail 'This feature was introduced in GitLab 11.7.' + desc "Update an existing cluster" do + detail "This feature was introduced in GitLab 11.7." success Entities::ClusterProject end params do - requires :cluster_id, type: Integer, desc: 'The cluster ID' - optional :name, type: String, desc: 'Cluster name' - optional :platform_kubernetes_attributes, type: Hash, desc: %q(Platform Kubernetes data) do - optional :api_url, type: String, desc: 'URL to access the Kubernetes API' - optional :token, type: String, desc: 'Token to authenticate against Kubernetes' - optional :ca_cert, type: String, desc: 'TLS certificate (needed if API is using a self-signed TLS certificate)' - optional :namespace, type: String, desc: 'Unique namespace related to Project' + requires :cluster_id, type: Integer, desc: "The cluster ID" + optional :name, type: String, desc: "Cluster name" + optional :platform_kubernetes_attributes, type: Hash, desc: "Platform Kubernetes data" do + optional :api_url, type: String, desc: "URL to access the Kubernetes API" + optional :token, type: String, desc: "Token to authenticate against Kubernetes" + optional :ca_cert, type: String, desc: "TLS certificate (needed if API is using a self-signed TLS certificate)" + optional :namespace, type: String, desc: "Unique namespace related to Project" end use :update_params_ee end - put ':id/clusters/:cluster_id' do + put ":id/clusters/:cluster_id" do authorize! :update_cluster, cluster update_service = Clusters::UpdateService.new(current_user, update_cluster_params) @@ -103,14 +103,14 @@ module API end end - desc 'Remove a cluster' do - detail 'This feature was introduced in GitLab 11.7.' + desc "Remove a cluster" do + detail "This feature was introduced in GitLab 11.7." success Entities::ClusterProject end params do - requires :cluster_id, type: Integer, desc: 'The Cluster ID' + requires :cluster_id, type: Integer, desc: "The Cluster ID" end - delete ':id/clusters/:cluster_id' do + delete ":id/clusters/:cluster_id" do authorize! :admin_cluster, cluster destroy_conditionally!(cluster) @@ -130,7 +130,7 @@ module API declared_params.merge({ provider_type: :user, platform_type: :kubernetes, - clusterable: user_project + clusterable: user_project, }) end diff --git a/lib/api/project_export.rb b/lib/api/project_export.rb index e34ed0bdb44..8bd5813416e 100644 --- a/lib/api/project_export.rb +++ b/lib/api/project_export.rb @@ -8,47 +8,47 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end - resource :projects, requirements: { id: %r{[^/]+} } do - desc 'Get export status' do - detail 'This feature was introduced in GitLab 10.6.' + resource :projects, requirements: {id: %r{[^/]+}} do + desc "Get export status" do + detail "This feature was introduced in GitLab 10.6." success Entities::ProjectExportStatus end - get ':id/export' do + get ":id/export" do present user_project, with: Entities::ProjectExportStatus end - desc 'Download export' do - detail 'This feature was introduced in GitLab 10.6.' + desc "Download export" do + detail "This feature was introduced in GitLab 10.6." end - get ':id/export/download' do + get ":id/export/download" do if user_project.export_file_exists? present_carrierwave_file!(user_project.export_file) else - render_api_error!('404 Not found or has expired', 404) + render_api_error!("404 Not found or has expired", 404) end end - desc 'Start export' do - detail 'This feature was introduced in GitLab 10.6.' + desc "Start export" do + detail "This feature was introduced in GitLab 10.6." end params do - optional :description, type: String, desc: 'Override the project description' + optional :description, type: String, desc: "Override the project description" optional :upload, type: Hash do - optional :url, type: String, desc: 'The URL to upload the project' - optional :http_method, type: String, default: 'PUT', desc: 'HTTP method to upload the exported project' + optional :url, type: String, desc: "The URL to upload the project" + optional :http_method, type: String, default: "PUT", desc: "HTTP method to upload the exported project" end end - post ':id/export' do + post ":id/export" do project_export_params = declared_params(include_missing: false) after_export_params = project_export_params.delete(:upload) || {} export_strategy = if after_export_params[:url].present? - params = after_export_params.slice(:url, :http_method).symbolize_keys + params = after_export_params.slice(:url, :http_method).symbolize_keys - Gitlab::ImportExport::AfterExportStrategies::WebUploadStrategy.new(params) - end + Gitlab::ImportExport::AfterExportStrategies::WebUploadStrategy.new(params) + end if export_strategy&.invalid? render_validation_error!(export_strategy) diff --git a/lib/api/project_hooks.rb b/lib/api/project_hooks.rb index 0e7576c9243..e4a0a8b90bd 100644 --- a/lib/api/project_hooks.rb +++ b/lib/api/project_hooks.rb @@ -27,10 +27,10 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get project hooks' do + desc "Get project hooks" do success Entities::ProjectHook end params do @@ -40,18 +40,18 @@ module API present paginate(user_project.hooks), with: Entities::ProjectHook end - desc 'Get a project hook' do + desc "Get a project hook" do success Entities::ProjectHook end params do - requires :hook_id, type: Integer, desc: 'The ID of a project hook' + requires :hook_id, type: Integer, desc: "The ID of a project hook" end get ":id/hooks/:hook_id" do hook = user_project.hooks.find(params[:hook_id]) present hook, with: Entities::ProjectHook end - desc 'Add hook to project' do + desc "Add hook to project" do success Entities::ProjectHook end params do @@ -72,7 +72,7 @@ module API end end - desc 'Update an existing project hook' do + desc "Update an existing project hook" do success Entities::ProjectHook end params do @@ -94,11 +94,11 @@ module API end end - desc 'Deletes project hook' do + desc "Deletes project hook" do success Entities::ProjectHook end params do - requires :hook_id, type: Integer, desc: 'The ID of the hook to delete' + requires :hook_id, type: Integer, desc: "The ID of the hook to delete" end delete ":id/hooks/:hook_id" do hook = user_project.hooks.find(params.delete(:hook_id)) diff --git a/lib/api/project_import.rb b/lib/api/project_import.rb index c64ec2fcc95..8aeec7299b6 100644 --- a/lib/api/project_import.rb +++ b/lib/api/project_import.rb @@ -11,50 +11,50 @@ module API end def file_is_valid? - import_params[:file] && import_params[:file]['tempfile'].respond_to?(:read) + import_params[:file] && import_params[:file]["tempfile"].respond_to?(:read) end def validate_file! - render_api_error!('The file is invalid', 400) unless file_is_valid? + render_api_error!("The file is invalid", 400) unless file_is_valid? end end before do - forbidden! unless Gitlab::CurrentSettings.import_sources.include?('gitlab_project') + forbidden! unless Gitlab::CurrentSettings.import_sources.include?("gitlab_project") end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do params do - requires :path, type: String, desc: 'The new project path and name' - requires :file, type: File, desc: 'The project export file to be imported' + requires :path, type: String, desc: "The new project path and name" + requires :file, type: File, desc: "The project export file to be imported" optional :namespace, type: String, desc: "The ID or name of the namespace that the project will be imported into. Defaults to the current user's namespace." - optional :overwrite, type: Boolean, default: false, desc: 'If there is a project in the same namespace and with the same name overwrite it' + optional :overwrite, type: Boolean, default: false, desc: "If there is a project in the same namespace and with the same name overwrite it" optional :override_params, - type: Hash, - desc: 'New project params to override values in the export' do + type: Hash, + desc: "New project params to override values in the export" do use :optional_project_params end end - desc 'Create a new project import' do - detail 'This feature was introduced in GitLab 10.6.' + desc "Create a new project import" do + detail "This feature was introduced in GitLab 10.6." success Entities::ProjectImportStatus end - post 'import' do + post "import" do validate_file! - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42437') + Gitlab::QueryLimiting.whitelist("https://gitlab.com/gitlab-org/gitlab-ce/issues/42437") namespace = if import_params[:namespace] - find_namespace!(import_params[:namespace]) - else - current_user.namespace - end + find_namespace!(import_params[:namespace]) + else + current_user.namespace + end project_params = { - path: import_params[:path], - namespace_id: namespace.id, - file: import_params[:file]['tempfile'], - overwrite: import_params[:overwrite] + path: import_params[:path], + namespace_id: namespace.id, + file: import_params[:file]["tempfile"], + overwrite: import_params[:overwrite], } override_params = import_params.delete(:override_params) @@ -69,13 +69,13 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end - desc 'Get a project export status' do - detail 'This feature was introduced in GitLab 10.6.' + desc "Get a project export status" do + detail "This feature was introduced in GitLab 10.6." success Entities::ProjectImportStatus end - get ':id/import' do + get ":id/import" do present user_project, with: Entities::ProjectImportStatus end end diff --git a/lib/api/project_milestones.rb b/lib/api/project_milestones.rb index ca24742b7a3..8a31cf1d6f5 100644 --- a/lib/api/project_milestones.rb +++ b/lib/api/project_milestones.rb @@ -10,10 +10,10 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get a list of project milestones' do + desc "Get a list of project milestones" do success Entities::Milestone end params do @@ -25,11 +25,11 @@ module API list_milestones_for(user_project) end - desc 'Get a single project milestone' do + desc "Get a single project milestone" do success Entities::Milestone end params do - requires :milestone_id, type: Integer, desc: 'The ID of a project milestone' + requires :milestone_id, type: Integer, desc: "The ID of a project milestone" end get ":id/milestones/:milestone_id" do authorize! :read_milestone, user_project @@ -37,11 +37,11 @@ module API get_milestone_for(user_project) end - desc 'Create a new project milestone' do + desc "Create a new project milestone" do success Entities::Milestone end params do - requires :title, type: String, desc: 'The title of the milestone' + requires :title, type: String, desc: "The title of the milestone" use :optional_params end post ":id/milestones" do @@ -50,7 +50,7 @@ module API create_milestone_for(user_project) end - desc 'Update an existing project milestone' do + desc "Update an existing project milestone" do success Entities::Milestone end params do @@ -62,7 +62,7 @@ module API update_milestone_for(user_project) end - desc 'Remove a project milestone' + desc "Remove a project milestone" delete ":id/milestones/:milestone_id" do authorize! :admin_milestone, user_project @@ -72,11 +72,11 @@ module API status(204) end - desc 'Get all issues for a single project milestone' do + desc "Get all issues for a single project milestone" do success Entities::IssueBasic end params do - requires :milestone_id, type: Integer, desc: 'The ID of a project milestone' + requires :milestone_id, type: Integer, desc: "The ID of a project milestone" use :pagination end get ":id/milestones/:milestone_id/issues" do @@ -85,35 +85,33 @@ module API milestone_issuables_for(user_project, :issue) end - desc 'Get all merge requests for a single project milestone' do - detail 'This feature was introduced in GitLab 9.' + desc "Get all merge requests for a single project milestone" do + detail "This feature was introduced in GitLab 9." success Entities::MergeRequestBasic end params do - requires :milestone_id, type: Integer, desc: 'The ID of a project milestone' + requires :milestone_id, type: Integer, desc: "The ID of a project milestone" use :pagination end - get ':id/milestones/:milestone_id/merge_requests' do + get ":id/milestones/:milestone_id/merge_requests" do authorize! :read_milestone, user_project milestone_issuables_for(user_project, :merge_request) end - desc 'Promote a milestone to group milestone' do - detail 'This feature was introduced in GitLab 11.9' + desc "Promote a milestone to group milestone" do + detail "This feature was introduced in GitLab 11.9" end - post ':id/milestones/:milestone_id/promote' do - begin - authorize! :admin_milestone, user_project - authorize! :admin_milestone, user_project.group + post ":id/milestones/:milestone_id/promote" do + authorize! :admin_milestone, user_project + authorize! :admin_milestone, user_project.group - milestone = user_project.milestones.find(params[:milestone_id]) - Milestones::PromoteService.new(user_project, current_user).execute(milestone) + milestone = user_project.milestones.find(params[:milestone_id]) + Milestones::PromoteService.new(user_project, current_user).execute(milestone) - status(200) - rescue Milestones::PromoteService::PromoteMilestoneError => error - render_api_error!(error.message, 400) - end + status(200) + rescue Milestones::PromoteService::PromoteMilestoneError => error + render_api_error!(error.message, 400) end end end diff --git a/lib/api/project_snapshots.rb b/lib/api/project_snapshots.rb index 175fbb2ce92..92835cb65ae 100644 --- a/lib/api/project_snapshots.rb +++ b/lib/api/project_snapshots.rb @@ -7,13 +7,13 @@ module API before { authorize_read_git_snapshot! } resource :projects do - desc 'Download a (possibly inconsistent) snapshot of a repository' do - detail 'This feature was introduced in GitLab 10.7' + desc "Download a (possibly inconsistent) snapshot of a repository" do + detail "This feature was introduced in GitLab 10.7" end params do - optional :wiki, type: Boolean, desc: 'Set to true to receive the wiki repository' + optional :wiki, type: Boolean, desc: "Set to true to receive the wiki repository" end - get ':id/snapshot' do + get ":id/snapshot" do send_git_snapshot(snapshot_repository) end end diff --git a/lib/api/project_snippets.rb b/lib/api/project_snippets.rb index a607df411a6..416cc7bc084 100644 --- a/lib/api/project_snippets.rb +++ b/lib/api/project_snippets.rb @@ -7,7 +7,7 @@ module API before { authenticate! } params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do helpers do @@ -24,7 +24,7 @@ module API end end - desc 'Get all project snippets' do + desc "Get all project snippets" do success Entities::ProjectSnippet end params do @@ -34,28 +34,28 @@ module API present paginate(snippets_for_current_user), with: Entities::ProjectSnippet end - desc 'Get a single project snippet' do + desc "Get a single project snippet" do success Entities::ProjectSnippet end params do - requires :snippet_id, type: Integer, desc: 'The ID of a project snippet' + requires :snippet_id, type: Integer, desc: "The ID of a project snippet" end get ":id/snippets/:snippet_id" do snippet = snippets_for_current_user.find(params[:snippet_id]) present snippet, with: Entities::ProjectSnippet end - desc 'Create a new project snippet' do + desc "Create a new project snippet" do success Entities::ProjectSnippet end params do - requires :title, type: String, desc: 'The title of the snippet' - requires :file_name, type: String, desc: 'The file name of the snippet' - requires :code, type: String, allow_blank: false, desc: 'The content of the snippet' - optional :description, type: String, desc: 'The description of a snippet' + requires :title, type: String, desc: "The title of the snippet" + requires :file_name, type: String, desc: "The file name of the snippet" + requires :code, type: String, allow_blank: false, desc: "The content of the snippet" + optional :description, type: String, desc: "The description of a snippet" requires :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, - desc: 'The visibility of the snippet' + desc: "The visibility of the snippet" end post ":id/snippets" do authorize! :create_project_snippet, user_project @@ -73,24 +73,24 @@ module API end end - desc 'Update an existing project snippet' do + desc "Update an existing project snippet" do success Entities::ProjectSnippet end params do - requires :snippet_id, type: Integer, desc: 'The ID of a project snippet' - optional :title, type: String, desc: 'The title of the snippet' - optional :file_name, type: String, desc: 'The file name of the snippet' - optional :code, type: String, allow_blank: false, desc: 'The content of the snippet' - optional :description, type: String, desc: 'The description of a snippet' + requires :snippet_id, type: Integer, desc: "The ID of a project snippet" + optional :title, type: String, desc: "The title of the snippet" + optional :file_name, type: String, desc: "The file name of the snippet" + optional :code, type: String, allow_blank: false, desc: "The content of the snippet" + optional :description, type: String, desc: "The description of a snippet" optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, - desc: 'The visibility of the snippet' + desc: "The visibility of the snippet" at_least_one_of :title, :file_name, :code, :visibility_level end # rubocop: disable CodeReuse/ActiveRecord put ":id/snippets/:snippet_id" do snippet = snippets_for_current_user.find_by(id: params.delete(:snippet_id)) - not_found!('Snippet') unless snippet + not_found!("Snippet") unless snippet authorize! :update_project_snippet, snippet @@ -100,7 +100,7 @@ module API snippet_params[:content] = snippet_params.delete(:code) if snippet_params[:code].present? UpdateSnippetService.new(user_project, current_user, snippet, - snippet_params).execute + snippet_params).execute render_spam_error! if snippet.spam? @@ -112,14 +112,14 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Delete a project snippet' + desc "Delete a project snippet" params do - requires :snippet_id, type: Integer, desc: 'The ID of a project snippet' + requires :snippet_id, type: Integer, desc: "The ID of a project snippet" end # rubocop: disable CodeReuse/ActiveRecord delete ":id/snippets/:snippet_id" do snippet = snippets_for_current_user.find_by(id: params[:snippet_id]) - not_found!('Snippet') unless snippet + not_found!("Snippet") unless snippet authorize! :admin_project_snippet, snippet @@ -127,26 +127,26 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get a raw project snippet' + desc "Get a raw project snippet" params do - requires :snippet_id, type: Integer, desc: 'The ID of a project snippet' + requires :snippet_id, type: Integer, desc: "The ID of a project snippet" end # rubocop: disable CodeReuse/ActiveRecord get ":id/snippets/:snippet_id/raw" do snippet = snippets_for_current_user.find_by(id: params[:snippet_id]) - not_found!('Snippet') unless snippet + not_found!("Snippet") unless snippet - env['api.format'] = :txt - content_type 'text/plain' + env["api.format"] = :txt + content_type "text/plain" present snippet.content end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get the user agent details for a project snippet' do + desc "Get the user agent details for a project snippet" do success Entities::UserAgentDetail end params do - requires :snippet_id, type: Integer, desc: 'The ID of a project snippet' + requires :snippet_id, type: Integer, desc: "The ID of a project snippet" end # rubocop: disable CodeReuse/ActiveRecord get ":id/snippets/:snippet_id/user_agent_detail" do @@ -154,7 +154,7 @@ module API snippet = Snippet.find_by!(id: params[:snippet_id], project_id: params[:id]) - break not_found!('UserAgentDetail') unless snippet.user_agent_detail + break not_found!("UserAgentDetail") unless snippet.user_agent_detail present snippet.user_agent_detail, with: Entities::UserAgentDetail end diff --git a/lib/api/project_statistics.rb b/lib/api/project_statistics.rb index 2f73785f72d..6cf765ea7b8 100644 --- a/lib/api/project_statistics.rb +++ b/lib/api/project_statistics.rb @@ -9,10 +9,10 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get the list of project fetch statistics for the last 30 days' + desc "Get the list of project fetch statistics for the last 30 days" get ":id/statistics" do statistic_finder = ::Projects::DailyStatisticsFinder.new(user_project) diff --git a/lib/api/project_templates.rb b/lib/api/project_templates.rb index 119902a189c..ed2cb991eab 100644 --- a/lib/api/project_templates.rb +++ b/lib/api/project_templates.rb @@ -9,17 +9,17 @@ module API before { authenticate_non_get! } params do - requires :id, type: String, desc: 'The ID of a project' - requires :type, type: String, values: TEMPLATE_TYPES, desc: 'The type (dockerfiles|gitignores|gitlab_ci_ymls|licenses) of the template' + requires :id, type: String, desc: "The ID of a project" + requires :type, type: String, values: TEMPLATE_TYPES, desc: "The type (dockerfiles|gitignores|gitlab_ci_ymls|licenses) of the template" end resource :projects do - desc 'Get a list of templates available to this project' do - detail 'This endpoint was introduced in GitLab 11.4' + desc "Get a list of templates available to this project" do + detail "This endpoint was introduced in GitLab 11.4" end params do use :pagination end - get ':id/templates/:type' do + get ":id/templates/:type" do templates = TemplateFinder .build(params[:type], user_project) .execute @@ -27,24 +27,24 @@ module API present paginate(::Kaminari.paginate_array(templates)), with: Entities::TemplatesList end - desc 'Download a template available to this project' do - detail 'This endpoint was introduced in GitLab 11.4' + desc "Download a template available to this project" do + detail "This endpoint was introduced in GitLab 11.4" end params do - requires :name, type: String, desc: 'The name of the template' + requires :name, type: String, desc: "The name of the template" - optional :project, type: String, desc: 'The project name to use when expanding placeholders in the template. Only affects licenses' - optional :fullname, type: String, desc: 'The full name of the copyright holder to use when expanding placeholders in the template. Only affects licenses' + optional :project, type: String, desc: "The project name to use when expanding placeholders in the template. Only affects licenses" + optional :fullname, type: String, desc: "The full name of the copyright holder to use when expanding placeholders in the template. Only affects licenses" end # The regex is needed to ensure a period (e.g. agpl-3.0) # isn't confused with a format type. We also need to allow encoded # values (e.g. C%2B%2B for C++), so allow % and + as well. - get ':id/templates/:type/:name', requirements: { name: /[\w%.+-]+/ } do + get ":id/templates/:type/:name", requirements: {name: /[\w%.+-]+/} do template = TemplateFinder .build(params[:type], user_project, name: params[:name]) .execute - not_found!('Template') unless template.present? + not_found!("Template") unless template.present? template.resolve!( project_name: params[:project].presence, diff --git a/lib/api/projects.rb b/lib/api/projects.rb index b23fe6cd4e7..3be654dcdc7 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_dependency 'declarative_policy' +require_dependency "declarative_policy" module API class Projects < Grape::API @@ -59,13 +59,13 @@ module API :tag_list, :visibility, :wiki_enabled, - :avatar + :avatar, ] end helpers do params :statistics_params do - optional :statistics, type: Boolean, default: false, desc: 'Include project statistics' + optional :statistics, type: Boolean, default: false, desc: "Include project statistics" end params :collection_params do @@ -74,35 +74,35 @@ module API use :pagination optional :simple, type: Boolean, default: false, - desc: 'Return only the ID, URL, name, and path of each project' + desc: "Return only the ID, URL, name, and path of each project" end params :sort_params do optional :order_by, type: String, values: %w[id name path created_at updated_at last_activity_at], - default: 'created_at', desc: 'Return projects ordered by field' - optional :sort, type: String, values: %w[asc desc], default: 'desc', - desc: 'Return projects sorted in ascending and descending order' + default: "created_at", desc: "Return projects ordered by field" + optional :sort, type: String, values: %w[asc desc], default: "desc", + desc: "Return projects sorted in ascending and descending order" end params :filter_params do - optional :archived, type: Boolean, desc: 'Limit by archived status' + optional :archived, type: Boolean, desc: "Limit by archived status" optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, - desc: 'Limit by visibility' - optional :search, type: String, desc: 'Return list of projects matching the search criteria' - optional :owned, type: Boolean, default: false, desc: 'Limit by owned by authenticated user' - optional :starred, type: Boolean, default: false, desc: 'Limit by starred status' - optional :membership, type: Boolean, default: false, desc: 'Limit by projects that the current user is a member of' - optional :with_issues_enabled, type: Boolean, default: false, desc: 'Limit by enabled issues feature' - optional :with_merge_requests_enabled, type: Boolean, default: false, desc: 'Limit by enabled merge requests feature' - optional :with_programming_language, type: String, desc: 'Limit to repositories which use the given programming language' - optional :min_access_level, type: Integer, values: Gitlab::Access.all_values, desc: 'Limit by minimum access level of authenticated user' + desc: "Limit by visibility" + optional :search, type: String, desc: "Return list of projects matching the search criteria" + optional :owned, type: Boolean, default: false, desc: "Limit by owned by authenticated user" + optional :starred, type: Boolean, default: false, desc: "Limit by starred status" + optional :membership, type: Boolean, default: false, desc: "Limit by projects that the current user is a member of" + optional :with_issues_enabled, type: Boolean, default: false, desc: "Limit by enabled issues feature" + optional :with_merge_requests_enabled, type: Boolean, default: false, desc: "Limit by enabled merge requests feature" + optional :with_programming_language, type: String, desc: "Limit to repositories which use the given programming language" + optional :min_access_level, type: Integer, values: Gitlab::Access.all_values, desc: "Limit by minimum access level of authenticated user" use :optional_filter_params_ee end params :create_params do - optional :namespace_id, type: Integer, desc: 'Namespace ID for the new project. Default to the user namespace.' - optional :import_url, type: String, desc: 'URL from which the project is imported' + optional :namespace_id, type: Integer, desc: "Namespace ID for the new project. Default to the user namespace." + optional :import_url, type: String, desc: "URL from which the project is imported" end def load_projects @@ -133,18 +133,18 @@ module API end resource :users, requirements: API::USER_REQUIREMENTS do - desc 'Get a user projects' do + desc "Get a user projects" do success Entities::BasicProjectDetails end params do - requires :user_id, type: String, desc: 'The ID or username of the user' + requires :user_id, type: String, desc: "The ID or username of the user" use :collection_params use :statistics_params use :with_custom_attributes end get ":user_id/projects" do user = find_user(params[:user_id]) - not_found!('User') unless user + not_found!("User") unless user params[:user] = user @@ -155,7 +155,7 @@ module API resource :projects do include CustomAttributesEndpoints - desc 'Get a list of visible projects for authenticated user' do + desc "Get a list of visible projects for authenticated user" do success Entities::BasicProjectDetails end params do @@ -167,12 +167,12 @@ module API present_projects load_projects end - desc 'Create new project' do + desc "Create new project" do success Entities::Project end params do - optional :name, type: String, desc: 'The name of the project' - optional :path, type: String, desc: 'The path of the repository' + optional :name, type: String, desc: "The name of the project" + optional :path, type: String, desc: "The path of the repository" at_least_one_of :name, :path use :optional_project_params use :create_params @@ -194,14 +194,14 @@ module API end end - desc 'Create new project for a specified user. Only available to admin users.' do + desc "Create new project for a specified user. Only available to admin users." do success Entities::Project end params do - requires :name, type: String, desc: 'The name of the project' - requires :user_id, type: Integer, desc: 'The ID of a user' - optional :path, type: String, desc: 'The path of the repository' - optional :default_branch, type: String, desc: 'The default branch of the project' + requires :name, type: String, desc: "The name of the project" + requires :user_id, type: Integer, desc: "The ID of a user" + optional :path, type: String, desc: "The path of the repository" + optional :default_branch, type: String, desc: "The default branch of the project" use :optional_project_params use :create_params end @@ -209,7 +209,7 @@ module API post "user/:user_id" do authenticated_as_admin! user = User.find_by(id: params.delete(:user_id)) - not_found!('User') unless user + not_found!("User") unless user attrs = declared_params(include_missing: false) attrs = translate_params_for_compatibility(attrs) @@ -226,10 +226,10 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get a single project' do + desc "Get a single project" do success Entities::ProjectWithAccess end params do @@ -237,7 +237,7 @@ module API use :with_custom_attributes optional :license, type: Boolean, default: false, - desc: 'Include project license data' + desc: "Include project license data" end get ":id" do options = { @@ -245,7 +245,7 @@ module API current_user: current_user, user_can_admin_project: can?(current_user, :admin_project, user_project), statistics: params[:statistics], - license: params[:license] + license: params[:license], } project, options = with_custom_attributes(user_project, options) @@ -253,16 +253,16 @@ module API present project, options end - desc 'Fork new project for the current user or provided namespace.' do + desc "Fork new project for the current user or provided namespace." do success Entities::Project end params do - optional :namespace, type: String, desc: 'The ID or name of the namespace that the project will be forked into' - optional :path, type: String, desc: 'The path that will be assigned to the fork' - optional :name, type: String, desc: 'The name that will be assigned to the fork' + optional :namespace, type: String, desc: "The ID or name of the namespace that the project will be forked into" + optional :path, type: String, desc: "The path that will be assigned to the fork" + optional :name, type: String, desc: "The name that will be assigned to the fork" end - post ':id/fork' do - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42284') + post ":id/fork" do + Gitlab::QueryLimiting.whitelist("https://gitlab.com/gitlab-org/gitlab-ce/issues/42284") fork_params = declared_params(include_missing: false) namespace_id = fork_params[:namespace] @@ -271,7 +271,7 @@ module API fork_params[:namespace] = find_namespace(namespace_id) unless fork_params[:namespace] && can?(current_user, :create_projects, fork_params[:namespace]) - not_found!('Target Namespace') + not_found!("Target Namespace") end end @@ -285,38 +285,38 @@ module API end end - desc 'List forks of this project' do + desc "List forks of this project" do success Entities::Project end params do use :collection_params use :with_custom_attributes end - get ':id/forks' do + get ":id/forks" do forks = ForkProjectsFinder.new(user_project, params: project_finder_params, current_user: current_user).execute present_projects forks end - desc 'Check pages access of this project' - get ':id/pages_access' do + desc "Check pages access of this project" + get ":id/pages_access" do authorize! :read_pages_content, user_project unless user_project.public_pages? status 200 end - desc 'Update an existing project' do + desc "Update an existing project" do success Entities::Project end params do - optional :name, type: String, desc: 'The name of the project' - optional :default_branch, type: String, desc: 'The default branch of the project' - optional :path, type: String, desc: 'The path of the repository' + optional :name, type: String, desc: "The name of the project" + optional :default_branch, type: String, desc: "The default branch of the project" + optional :path, type: String, desc: "The path of the repository" use :optional_project_params at_least_one_of(*::API::Projects.update_params_at_least_one_of) end - put ':id' do + put ":id" do authorize_admin_project attrs = declared_params(include_missing: false) authorize! :rename_project, user_project if attrs[:name].present? @@ -336,10 +336,10 @@ module API end end - desc 'Archive a project' do + desc "Archive a project" do success Entities::Project end - post ':id/archive' do + post ":id/archive" do authorize!(:archive_project, user_project) ::Projects::UpdateService.new(user_project, current_user, archived: true).execute @@ -347,10 +347,10 @@ module API present user_project, with: Entities::Project end - desc 'Unarchive a project' do + desc "Unarchive a project" do success Entities::Project end - post ':id/unarchive' do + post ":id/unarchive" do authorize!(:archive_project, user_project) ::Projects::UpdateService.new(@project, current_user, archived: false).execute @@ -358,10 +358,10 @@ module API present user_project, with: Entities::Project end - desc 'Star a project' do + desc "Star a project" do success Entities::Project end - post ':id/star' do + post ":id/star" do if current_user.starred?(user_project) not_modified! else @@ -372,10 +372,10 @@ module API end end - desc 'Unstar a project' do + desc "Unstar a project" do success Entities::Project end - post ':id/unstar' do + post ":id/unstar" do if current_user.starred?(user_project) current_user.toggle_star(user_project) user_project.reload @@ -386,8 +386,8 @@ module API end end - desc 'Get languages in project repository' - get ':id/languages' do + desc "Get languages in project repository" + get ":id/languages" do if user_project.repository_languages.present? user_project.repository_languages.map { |l| [l.name, l.share] }.to_h else @@ -395,7 +395,7 @@ module API end end - desc 'Remove a project' + desc "Remove a project" delete ":id" do authorize! :remove_project, user_project @@ -406,9 +406,9 @@ module API accepted! end - desc 'Mark this project as forked from another' + desc "Mark this project as forked from another" params do - requires :forked_from_id, type: String, desc: 'The ID of the project it was forked from' + requires :forked_from_id, type: String, desc: "The ID of the project it was forked from" end post ":id/fork/:forked_from_id" do authorize! :admin_project, user_project @@ -426,31 +426,31 @@ module API end end - desc 'Remove a forked_from relationship' + desc "Remove a forked_from relationship" delete ":id/fork" do authorize! :remove_fork_project, user_project - result = destroy_conditionally!(user_project) do + result = destroy_conditionally!(user_project) { ::Projects::UnlinkForkService.new(user_project, current_user).execute - end + } result ? status(204) : not_modified! end - desc 'Share the project with a group' do + desc "Share the project with a group" do success Entities::ProjectGroupLink end params do - requires :group_id, type: Integer, desc: 'The ID of a group' - requires :group_access, type: Integer, values: Gitlab::Access.values, desc: 'The group access level' - optional :expires_at, type: Date, desc: 'Share expiration date' + requires :group_id, type: Integer, desc: "The ID of a group" + requires :group_access, type: Integer, values: Gitlab::Access.values, desc: "The group access level" + optional :expires_at, type: Date, desc: "Share expiration date" end post ":id/share" do authorize! :admin_project, user_project group = Group.find_by_id(params[:group_id]) unless group && can?(current_user, :read_group, group) - not_found!('Group') + not_found!("Group") end unless user_project.allowed_to_share_with_group? @@ -467,45 +467,45 @@ module API end params do - requires :group_id, type: Integer, desc: 'The ID of the group' + requires :group_id, type: Integer, desc: "The ID of the group" end # rubocop: disable CodeReuse/ActiveRecord delete ":id/share/:group_id" do authorize! :admin_project, user_project link = user_project.project_group_links.find_by(group_id: params[:group_id]) - not_found!('Group Link') unless link + not_found!("Group Link") unless link destroy_conditionally!(link) end # rubocop: enable CodeReuse/ActiveRecord - desc 'Upload a file' + desc "Upload a file" params do - requires :file, type: File, desc: 'The file to be uploaded' + requires :file, type: File, desc: "The file to be uploaded" end post ":id/uploads" do UploadService.new(user_project, params[:file]).execute.to_h end - desc 'Get the users list of a project' do + desc "Get the users list of a project" do success Entities::UserBasic end params do - optional :search, type: String, desc: 'Return list of users matching the search criteria' + optional :search, type: String, desc: "Return list of users matching the search criteria" use :pagination end - get ':id/users' do + get ":id/users" do users = DeclarativePolicy.subject_scope { user_project.team.users } users = users.search(params[:search]) if params[:search].present? present paginate(users), with: Entities::UserBasic end - desc 'Start the housekeeping task for a project' do - detail 'This feature was introduced in GitLab 9.0.' + desc "Start the housekeeping task for a project" do + detail "This feature was introduced in GitLab 9.0." end - post ':id/housekeeping' do + post ":id/housekeeping" do authorize_admin_project begin @@ -515,9 +515,9 @@ module API end end - desc 'Transfer a project to a new namespace' + desc "Transfer a project to a new namespace" params do - requires :namespace, type: String, desc: 'The ID or path of the new namespace' + requires :namespace, type: String, desc: "The ID or path of the new namespace" end put ":id/transfer" do authorize! :change_namespace, user_project diff --git a/lib/api/protected_branches.rb b/lib/api/protected_branches.rb index 5af43448727..b562ea7d529 100644 --- a/lib/api/protected_branches.rb +++ b/lib/api/protected_branches.rb @@ -9,7 +9,7 @@ module API before { authorize_admin_project } params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do desc "Get a project's protected branches" do @@ -19,41 +19,41 @@ module API use :pagination end # rubocop: disable CodeReuse/ActiveRecord - get ':id/protected_branches' do + get ":id/protected_branches" do protected_branches = user_project.protected_branches.preload(:push_access_levels, :merge_access_levels) present paginate(protected_branches), with: Entities::ProtectedBranch, project: user_project end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get a single protected branch' do + desc "Get a single protected branch" do success Entities::ProtectedBranch end params do - requires :name, type: String, desc: 'The name of the branch or wildcard' + requires :name, type: String, desc: "The name of the branch or wildcard" end # rubocop: disable CodeReuse/ActiveRecord - get ':id/protected_branches/:name', requirements: BRANCH_ENDPOINT_REQUIREMENTS do + get ":id/protected_branches/:name", requirements: BRANCH_ENDPOINT_REQUIREMENTS do protected_branch = user_project.protected_branches.find_by!(name: params[:name]) present protected_branch, with: Entities::ProtectedBranch, project: user_project end # rubocop: enable CodeReuse/ActiveRecord - desc 'Protect a single branch or wildcard' do + desc "Protect a single branch or wildcard" do success Entities::ProtectedBranch end params do - requires :name, type: String, desc: 'The name of the protected branch' + requires :name, type: String, desc: "The name of the protected branch" optional :push_access_level, type: Integer, values: ProtectedBranch::PushAccessLevel.allowed_access_levels, - desc: 'Access levels allowed to push (defaults: `40`, maintainer access level)' + desc: "Access levels allowed to push (defaults: `40`, maintainer access level)" optional :merge_access_level, type: Integer, values: ProtectedBranch::MergeAccessLevel.allowed_access_levels, - desc: 'Access levels allowed to merge (defaults: `40`, maintainer access level)' + desc: "Access levels allowed to merge (defaults: `40`, maintainer access level)" end # rubocop: disable CodeReuse/ActiveRecord - post ':id/protected_branches' do + post ":id/protected_branches" do protected_branch = user_project.protected_branches.find_by(name: params[:name]) if protected_branch conflict!("Protected branch '#{params[:name]}' already exists") @@ -71,12 +71,12 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Unprotect a single branch' + desc "Unprotect a single branch" params do - requires :name, type: String, desc: 'The name of the protected branch' + requires :name, type: String, desc: "The name of the protected branch" end # rubocop: disable CodeReuse/ActiveRecord - delete ':id/protected_branches/:name', requirements: BRANCH_ENDPOINT_REQUIREMENTS do + delete ":id/protected_branches/:name", requirements: BRANCH_ENDPOINT_REQUIREMENTS do protected_branch = user_project.protected_branches.find_by!(name: params[:name]) destroy_conditionally!(protected_branch) do diff --git a/lib/api/protected_tags.rb b/lib/api/protected_tags.rb index ee13473c848..8ef1beab610 100644 --- a/lib/api/protected_tags.rb +++ b/lib/api/protected_tags.rb @@ -9,58 +9,58 @@ module API before { authorize_admin_project } params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do desc "Get a project's protected tags" do - detail 'This feature was introduced in GitLab 11.3.' + detail "This feature was introduced in GitLab 11.3." success Entities::ProtectedTag end params do use :pagination end # rubocop: disable CodeReuse/ActiveRecord - get ':id/protected_tags' do + get ":id/protected_tags" do protected_tags = user_project.protected_tags.preload(:create_access_levels) present paginate(protected_tags), with: Entities::ProtectedTag, project: user_project end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get a single protected tag' do - detail 'This feature was introduced in GitLab 11.3.' + desc "Get a single protected tag" do + detail "This feature was introduced in GitLab 11.3." success Entities::ProtectedTag end params do - requires :name, type: String, desc: 'The name of the tag or wildcard' + requires :name, type: String, desc: "The name of the tag or wildcard" end # rubocop: disable CodeReuse/ActiveRecord - get ':id/protected_tags/:name', requirements: TAG_ENDPOINT_REQUIREMENTS do + get ":id/protected_tags/:name", requirements: TAG_ENDPOINT_REQUIREMENTS do protected_tag = user_project.protected_tags.find_by!(name: params[:name]) present protected_tag, with: Entities::ProtectedTag, project: user_project end # rubocop: enable CodeReuse/ActiveRecord - desc 'Protect a single tag or wildcard' do - detail 'This feature was introduced in GitLab 11.3.' + desc "Protect a single tag or wildcard" do + detail "This feature was introduced in GitLab 11.3." success Entities::ProtectedTag end params do - requires :name, type: String, desc: 'The name of the protected tag' + requires :name, type: String, desc: "The name of the protected tag" optional :create_access_level, type: Integer, default: Gitlab::Access::MAINTAINER, values: ProtectedTag::CreateAccessLevel.allowed_access_levels, - desc: 'Access levels allowed to create (defaults: `40`, maintainer access level)' + desc: "Access levels allowed to create (defaults: `40`, maintainer access level)" end - post ':id/protected_tags' do + post ":id/protected_tags" do protected_tags_params = { name: params[:name], - create_access_levels_attributes: [{ access_level: params[:create_access_level] }] + create_access_levels_attributes: [{access_level: params[:create_access_level]}], } protected_tag = ::ProtectedTags::CreateService.new(user_project, - current_user, - protected_tags_params).execute + current_user, + protected_tags_params).execute if protected_tag.persisted? present protected_tag, with: Entities::ProtectedTag, project: user_project @@ -69,14 +69,14 @@ module API end end - desc 'Unprotect a single tag' do - detail 'This feature was introduced in GitLab 11.3.' + desc "Unprotect a single tag" do + detail "This feature was introduced in GitLab 11.3." end params do - requires :name, type: String, desc: 'The name of the protected tag' + requires :name, type: String, desc: "The name of the protected tag" end # rubocop: disable CodeReuse/ActiveRecord - delete ':id/protected_tags/:name', requirements: TAG_ENDPOINT_REQUIREMENTS do + delete ":id/protected_tags/:name", requirements: TAG_ENDPOINT_REQUIREMENTS do protected_tag = user_project.protected_tags.find_by!(name: params[:name]) destroy_conditionally!(protected_tag) diff --git a/lib/api/release/links.rb b/lib/api/release/links.rb index e3072684ef7..f1a70f2a4bc 100644 --- a/lib/api/release/links.rb +++ b/lib/api/release/links.rb @@ -9,36 +9,36 @@ module API .merge(tag_name: API::NO_SLASH_URL_PART_REGEX) params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end - resource 'projects/:id', requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do + resource "projects/:id", requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do params do - requires :tag_name, type: String, desc: 'The name of the tag', as: :tag + requires :tag_name, type: String, desc: "The name of the tag", as: :tag end - resource 'releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do + resource "releases/:tag_name", requirements: RELEASE_ENDPOINT_REQUIREMETS do resource :assets do - desc 'Get a list of links of a release' do - detail 'This feature was introduced in GitLab 11.7.' + desc "Get a list of links of a release" do + detail "This feature was introduced in GitLab 11.7." success Entities::Releases::Link end params do use :pagination end - get 'links' do + get "links" do authorize! :read_release, release present paginate(release.links.sorted), with: Entities::Releases::Link end - desc 'Create a link of a release' do - detail 'This feature was introduced in GitLab 11.7.' + desc "Create a link of a release" do + detail "This feature was introduced in GitLab 11.7." success Entities::Releases::Link end params do - requires :name, type: String, desc: 'The name of the link' - requires :url, type: String, desc: 'The URL of the link' + requires :name, type: String, desc: "The name of the link" + requires :url, type: String, desc: "The URL of the link" end - post 'links' do + post "links" do authorize! :create_release, release new_link = release.links.create(declared_params(include_missing: false)) @@ -51,11 +51,11 @@ module API end params do - requires :link_id, type: String, desc: 'The id of the link' + requires :link_id, type: String, desc: "The id of the link" end - resource 'links/:link_id' do - desc 'Get a link detail of a release' do - detail 'This feature was introduced in GitLab 11.7.' + resource "links/:link_id" do + desc "Get a link detail of a release" do + detail "This feature was introduced in GitLab 11.7." success Entities::Releases::Link end get do @@ -64,13 +64,13 @@ module API present link, with: Entities::Releases::Link end - desc 'Update a link of a release' do - detail 'This feature was introduced in GitLab 11.7.' + desc "Update a link of a release" do + detail "This feature was introduced in GitLab 11.7." success Entities::Releases::Link end params do - optional :name, type: String, desc: 'The name of the link' - optional :url, type: String, desc: 'The URL of the link' + optional :name, type: String, desc: "The name of the link" + optional :url, type: String, desc: "The URL of the link" at_least_one_of :name, :url end put do @@ -83,8 +83,8 @@ module API end end - desc 'Delete a link of a release' do - detail 'This feature was introduced in GitLab 11.7.' + desc "Delete a link of a release" do + detail "This feature was introduced in GitLab 11.7." success Entities::Releases::Link end delete do diff --git a/lib/api/releases.rb b/lib/api/releases.rb index cb85028f22c..b608c237cff 100644 --- a/lib/api/releases.rb +++ b/lib/api/releases.rb @@ -10,44 +10,44 @@ module API before { authorize_read_releases! } params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get a project releases' do - detail 'This feature was introduced in GitLab 11.7.' + desc "Get a project releases" do + detail "This feature was introduced in GitLab 11.7." success Entities::Release end params do use :pagination end - get ':id/releases' do + get ":id/releases" do releases = ::ReleasesFinder.new(user_project, current_user).execute present paginate(releases), with: Entities::Release end - desc 'Get a single project release' do - detail 'This feature was introduced in GitLab 11.7.' + desc "Get a single project release" do + detail "This feature was introduced in GitLab 11.7." success Entities::Release end params do - requires :tag_name, type: String, desc: 'The name of the tag', as: :tag + requires :tag_name, type: String, desc: "The name of the tag", as: :tag end - get ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do + get ":id/releases/:tag_name", requirements: RELEASE_ENDPOINT_REQUIREMETS do authorize_read_release! present release, with: Entities::Release end - desc 'Create a new release' do - detail 'This feature was introduced in GitLab 11.7.' + desc "Create a new release" do + detail "This feature was introduced in GitLab 11.7." success Entities::Release end params do - requires :tag_name, type: String, desc: 'The name of the tag', as: :tag - requires :name, type: String, desc: 'The name of the release' - requires :description, type: String, desc: 'The release notes' - optional :ref, type: String, desc: 'The commit sha or branch name' + requires :tag_name, type: String, desc: "The name of the tag", as: :tag + requires :name, type: String, desc: "The name of the release" + requires :description, type: String, desc: "The release notes" + optional :ref, type: String, desc: "The commit sha or branch name" optional :assets, type: Hash do optional :links, type: Array do requires :name, type: String @@ -55,7 +55,7 @@ module API end end end - post ':id/releases' do + post ":id/releases" do authorize_create_release! result = ::Releases::CreateService @@ -69,16 +69,16 @@ module API end end - desc 'Update a release' do - detail 'This feature was introduced in GitLab 11.7.' + desc "Update a release" do + detail "This feature was introduced in GitLab 11.7." success Entities::Release end params do - requires :tag_name, type: String, desc: 'The name of the tag', as: :tag - optional :name, type: String, desc: 'The name of the release' - optional :description, type: String, desc: 'Release notes with markdown support' + requires :tag_name, type: String, desc: "The name of the tag", as: :tag + optional :name, type: String, desc: "The name of the release" + optional :description, type: String, desc: "Release notes with markdown support" end - put ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do + put ":id/releases/:tag_name", requirements: RELEASE_ENDPOINT_REQUIREMETS do authorize_update_release! result = ::Releases::UpdateService @@ -92,14 +92,14 @@ module API end end - desc 'Delete a release' do - detail 'This feature was introduced in GitLab 11.7.' + desc "Delete a release" do + detail "This feature was introduced in GitLab 11.7." success Entities::Release end params do - requires :tag_name, type: String, desc: 'The name of the tag', as: :tag + requires :tag_name, type: String, desc: "The name of the tag", as: :tag end - delete ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do + delete ":id/releases/:tag_name", requirements: RELEASE_ENDPOINT_REQUIREMETS do authorize_destroy_release! result = ::Releases::DestroyService diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb index 32e05d84491..2545236b3fa 100644 --- a/lib/api/repositories.rb +++ b/lib/api/repositories.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'mime/types' +require "mime/types" module API class Repositories < Grape::API @@ -9,7 +9,7 @@ module API before { authorize! :download_code, user_project } params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do helpers do @@ -30,120 +30,116 @@ module API @blob = Gitlab::Git::Blob.raw(@repo, params[:sha]) @blob.load_all_data!(@repo) rescue - not_found! 'Blob' + not_found! "Blob" end - not_found! 'Blob' unless @blob + not_found! "Blob" unless @blob end end - desc 'Get a project repository tree' do + desc "Get a project repository tree" do success Entities::TreeObject end params do - optional :ref, type: String, desc: 'The name of a repository branch or tag, if not given the default branch is used' - optional :path, type: String, desc: 'The path of the tree' - optional :recursive, type: Boolean, default: false, desc: 'Used to get a recursive tree' + optional :ref, type: String, desc: "The name of a repository branch or tag, if not given the default branch is used" + optional :path, type: String, desc: "The path of the tree" + optional :recursive, type: Boolean, default: false, desc: "Used to get a recursive tree" use :pagination end - get ':id/repository/tree' do - ref = params[:ref] || user_project.try(:default_branch) || 'master' + get ":id/repository/tree" do + ref = params[:ref] || user_project.try(:default_branch) || "master" path = params[:path] || nil commit = user_project.commit(ref) - not_found!('Tree') unless commit + not_found!("Tree") unless commit tree = user_project.repository.tree(commit.id, path, recursive: params[:recursive]) entries = ::Kaminari.paginate_array(tree.sorted_entries) present paginate(entries), with: Entities::TreeObject end - desc 'Get raw blob contents from the repository' + desc "Get raw blob contents from the repository" params do - requires :sha, type: String, desc: 'The commit hash' + requires :sha, type: String, desc: "The commit hash" end - get ':id/repository/blobs/:sha/raw' do + get ":id/repository/blobs/:sha/raw" do assign_blob_vars! send_git_blob @repo, @blob end - desc 'Get a blob from the repository' + desc "Get a blob from the repository" params do - requires :sha, type: String, desc: 'The commit hash' + requires :sha, type: String, desc: "The commit hash" end - get ':id/repository/blobs/:sha' do + get ":id/repository/blobs/:sha" do assign_blob_vars! { size: @blob.size, encoding: "base64", content: Base64.strict_encode64(@blob.data), - sha: @blob.id + sha: @blob.id, } end - desc 'Get an archive of the repository' + desc "Get an archive of the repository" params do - optional :sha, type: String, desc: 'The commit sha of the archive to be downloaded' - optional :format, type: String, desc: 'The archive format' - end - get ':id/repository/archive', requirements: { format: Gitlab::PathRegex.archive_formats_regex } do - begin - send_git_archive user_project.repository, ref: params[:sha], format: params[:format], append_sha: true - rescue - not_found!('File') - end + optional :sha, type: String, desc: "The commit sha of the archive to be downloaded" + optional :format, type: String, desc: "The archive format" + end + get ":id/repository/archive", requirements: {format: Gitlab::PathRegex.archive_formats_regex} do + send_git_archive user_project.repository, ref: params[:sha], format: params[:format], append_sha: true + rescue + not_found!("File") end - desc 'Compare two branches, tags, or commits' do + desc "Compare two branches, tags, or commits" do success Entities::Compare end params do - requires :from, type: String, desc: 'The commit, branch name, or tag name to start comparison' - requires :to, type: String, desc: 'The commit, branch name, or tag name to stop comparison' - optional :straight, type: Boolean, desc: 'Comparison method, `true` for direct comparison between `from` and `to` (`from`..`to`), `false` to compare using merge base (`from`...`to`)', default: false + requires :from, type: String, desc: "The commit, branch name, or tag name to start comparison" + requires :to, type: String, desc: "The commit, branch name, or tag name to stop comparison" + optional :straight, type: Boolean, desc: "Comparison method, `true` for direct comparison between `from` and `to` (`from`..`to`), `false` to compare using merge base (`from`...`to`)", default: false end - get ':id/repository/compare' do + get ":id/repository/compare" do compare = Gitlab::Git::Compare.new(user_project.repository.raw_repository, params[:from], params[:to], straight: params[:straight]) present compare, with: Entities::Compare end - desc 'Get repository contributors' do + desc "Get repository contributors" do success Entities::Contributor end params do use :pagination - optional :order_by, type: String, values: %w[email name commits], default: 'commits', desc: 'Return contributors ordered by `name` or `email` or `commits`' - optional :sort, type: String, values: %w[asc desc], default: 'asc', desc: 'Sort by asc (ascending) or desc (descending)' - end - get ':id/repository/contributors' do - begin - contributors = ::Kaminari.paginate_array(user_project.repository.contributors(order_by: params[:order_by], sort: params[:sort])) - present paginate(contributors), with: Entities::Contributor - rescue - not_found! - end + optional :order_by, type: String, values: %w[email name commits], default: "commits", desc: "Return contributors ordered by `name` or `email` or `commits`" + optional :sort, type: String, values: %w[asc desc], default: "asc", desc: "Sort by asc (ascending) or desc (descending)" + end + get ":id/repository/contributors" do + contributors = ::Kaminari.paginate_array(user_project.repository.contributors(order_by: params[:order_by], sort: params[:sort])) + present paginate(contributors), with: Entities::Contributor + rescue + not_found! end - desc 'Get the common ancestor between commits' do + desc "Get the common ancestor between commits" do success Entities::Commit end params do requires :refs, type: Array[String] end - get ':id/repository/merge_base' do + get ":id/repository/merge_base" do refs = params[:refs] if refs.size < 2 - render_api_error!('Provide at least 2 refs', 400) + render_api_error!("Provide at least 2 refs", 400) end merge_base = Gitlab::Git::MergeBase.new(user_project.repository, refs) if merge_base.unknown_refs.any? - ref_noun = 'ref'.pluralize(merge_base.unknown_refs.size) - message = "Could not find #{ref_noun}: #{merge_base.unknown_refs.join(', ')}" + ref_noun = "ref".pluralize(merge_base.unknown_refs.size) + message = "Could not find #{ref_noun}: #{merge_base.unknown_refs.join(", ")}" render_api_error!(message, 400) end diff --git a/lib/api/resource_label_events.rb b/lib/api/resource_label_events.rb index 0c328f7268e..b2934eb29e1 100644 --- a/lib/api/resource_label_events.rb +++ b/lib/api/resource_label_events.rb @@ -19,10 +19,10 @@ module API resource parent_type.pluralize.to_sym, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do desc "Get a list of #{eventable_type.to_s.downcase} resource label events" do success Entities::ResourceLabelEvent - detail 'This feature was introduced in 11.3' + detail "This feature was introduced in 11.3" end params do - requires :eventable_id, types: [Integer, String], desc: 'The ID of the eventable' + requires :eventable_id, types: [Integer, String], desc: "The ID of the eventable" use :pagination end @@ -37,11 +37,11 @@ module API desc "Get a single #{eventable_type.to_s.downcase} resource label event" do success Entities::ResourceLabelEvent - detail 'This feature was introduced in 11.3' + detail "This feature was introduced in 11.3" end params do - requires :event_id, type: String, desc: 'The ID of a resource label event' - requires :eventable_id, types: [Integer, String], desc: 'The ID of the eventable' + requires :event_id, type: String, desc: "The ID of a resource label event" + requires :eventable_id, types: [Integer, String], desc: "The ID of the eventable" end get ":id/#{eventables_str}/:eventable_id/resource_label_events/:event_id" do eventable = find_noteable(parent_type, eventables_str, params[:eventable_id]) diff --git a/lib/api/runner.rb b/lib/api/runner.rb index c60d25b88cb..b97db592fad 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -5,21 +5,21 @@ module API helpers ::API::Helpers::Runner resource :runners do - desc 'Registers a new Runner' do + desc "Registers a new Runner" do success Entities::RunnerRegistrationDetails - http_codes [[201, 'Runner was created'], [403, 'Forbidden']] + http_codes [[201, "Runner was created"], [403, "Forbidden"]] end params do - requires :token, type: String, desc: 'Registration token' - optional :description, type: String, desc: %q(Runner's description) - optional :info, type: Hash, desc: %q(Runner's metadata) - optional :active, type: Boolean, desc: 'Should Runner be active' - optional :locked, type: Boolean, desc: 'Should Runner be locked for current project' - optional :run_untagged, type: Boolean, desc: 'Should Runner handle untagged jobs' - optional :tag_list, type: Array[String], desc: %q(List of Runner's tags) - optional :maximum_timeout, type: Integer, desc: 'Maximum timeout set when this Runner will handle the job' + requires :token, type: String, desc: "Registration token" + optional :description, type: String, desc: "Runner's description" + optional :info, type: Hash, desc: "Runner's metadata" + optional :active, type: Boolean, desc: "Should Runner be active" + optional :locked, type: Boolean, desc: "Should Runner be locked for current project" + optional :run_untagged, type: Boolean, desc: "Should Runner handle untagged jobs" + optional :tag_list, type: Array[String], desc: "List of Runner's tags" + optional :maximum_timeout, type: Integer, desc: "Maximum timeout set when this Runner will handle the job" end - post '/' do + post "/" do attributes = attributes_for_keys([:description, :active, :locked, :run_untagged, :tag_list, :maximum_timeout]) .merge(get_runner_details_from_request) @@ -46,13 +46,13 @@ module API end end - desc 'Deletes a registered Runner' do - http_codes [[204, 'Runner was deleted'], [403, 'Forbidden']] + desc "Deletes a registered Runner" do + http_codes [[204, "Runner was deleted"], [403, "Forbidden"]] end params do - requires :token, type: String, desc: %q(Runner's authentication token) + requires :token, type: String, desc: "Runner's authentication token" end - delete '/' do + delete "/" do authenticate_runner! runner = Ci::Runner.find_by_token(params[:token]) @@ -60,55 +60,55 @@ module API destroy_conditionally!(runner) end - desc 'Validates authentication credentials' do - http_codes [[200, 'Credentials are valid'], [403, 'Forbidden']] + desc "Validates authentication credentials" do + http_codes [[200, "Credentials are valid"], [403, "Forbidden"]] end params do - requires :token, type: String, desc: %q(Runner's authentication token) + requires :token, type: String, desc: "Runner's authentication token" end - post '/verify' do + post "/verify" do authenticate_runner! status 200 end end resource :jobs do - desc 'Request a job' do + desc "Request a job" do success Entities::JobRequest::Response - http_codes [[201, 'Job was scheduled'], - [204, 'No job for Runner'], - [403, 'Forbidden']] + http_codes [[201, "Job was scheduled"], + [204, "No job for Runner"], + [403, "Forbidden"],] end params do - requires :token, type: String, desc: %q(Runner's authentication token) - optional :last_update, type: String, desc: %q(Runner's queue last_update token) - optional :info, type: Hash, desc: %q(Runner's metadata) do - optional :name, type: String, desc: %q(Runner's name) - optional :version, type: String, desc: %q(Runner's version) - optional :revision, type: String, desc: %q(Runner's revision) - optional :platform, type: String, desc: %q(Runner's platform) - optional :architecture, type: String, desc: %q(Runner's architecture) - optional :executor, type: String, desc: %q(Runner's executor) - optional :features, type: Hash, desc: %q(Runner's features) + requires :token, type: String, desc: "Runner's authentication token" + optional :last_update, type: String, desc: "Runner's queue last_update token" + optional :info, type: Hash, desc: "Runner's metadata" do + optional :name, type: String, desc: "Runner's name" + optional :version, type: String, desc: "Runner's version" + optional :revision, type: String, desc: "Runner's revision" + optional :platform, type: String, desc: "Runner's platform" + optional :architecture, type: String, desc: "Runner's architecture" + optional :executor, type: String, desc: "Runner's executor" + optional :features, type: Hash, desc: "Runner's features" end - optional :session, type: Hash, desc: %q(Runner's session data) do - optional :url, type: String, desc: %q(Session's url) - optional :certificate, type: String, desc: %q(Session's certificate) - optional :authorization, type: String, desc: %q(Session's authorization) + optional :session, type: Hash, desc: "Runner's session data" do + optional :url, type: String, desc: "Session's url" + optional :certificate, type: String, desc: "Session's certificate" + optional :authorization, type: String, desc: "Session's authorization" end end - post '/request' do + post "/request" do authenticate_runner! unless current_runner.active? - header 'X-GitLab-Last-Update', current_runner.ensure_runner_queue_value + header "X-GitLab-Last-Update", current_runner.ensure_runner_queue_value break no_content! end runner_params = declared_params(include_missing: false) if current_runner.runner_queue_value_latest?(runner_params[:last_update]) - header 'X-GitLab-Last-Update', runner_params[:last_update] + header "X-GitLab-Last-Update", runner_params[:last_update] Gitlab::Metrics.add_event(:build_not_found_cached) break no_content! end @@ -122,7 +122,7 @@ module API present Ci::BuildRunnerPresenter.new(result.build), with: Entities::JobRequest::Response else Gitlab::Metrics.add_event(:build_not_found) - header 'X-GitLab-Last-Update', new_update + header "X-GitLab-Last-Update", new_update no_content! end else @@ -132,51 +132,51 @@ module API end end - desc 'Updates a job' do - http_codes [[200, 'Job was updated'], [403, 'Forbidden']] + desc "Updates a job" do + http_codes [[200, "Job was updated"], [403, "Forbidden"]] end params do - requires :token, type: String, desc: %q(Runners's authentication token) - requires :id, type: Integer, desc: %q(Job's ID) - optional :trace, type: String, desc: %q(Job's full trace) - optional :state, type: String, desc: %q(Job's status: success, failed) - optional :failure_reason, type: String, desc: %q(Job's failure_reason) + requires :token, type: String, desc: "Runners's authentication token" + requires :id, type: Integer, desc: "Job's ID" + optional :trace, type: String, desc: "Job's full trace" + optional :state, type: String, desc: "Job's status: success, failed" + optional :failure_reason, type: String, desc: "Job's failure_reason" end - put '/:id' do + put "/:id" do job = authenticate_job! - job_forbidden!(job, 'Job is not running') unless job.running? + job_forbidden!(job, "Job is not running") unless job.running? job.trace.set(params[:trace]) if params[:trace] Gitlab::Metrics.add_event(:update_build) case params[:state].to_s - when 'running' + when "running" job.touch if job.needs_touch? - when 'success' + when "success" job.success! - when 'failed' + when "failed" job.drop!(params[:failure_reason] || :unknown_failure) end end - desc 'Appends a patch to the job trace' do - http_codes [[202, 'Trace was patched'], - [400, 'Missing Content-Range header'], - [403, 'Forbidden'], - [416, 'Range not satisfiable']] + desc "Appends a patch to the job trace" do + http_codes [[202, "Trace was patched"], + [400, "Missing Content-Range header"], + [403, "Forbidden"], + [416, "Range not satisfiable"],] end params do - requires :id, type: Integer, desc: %q(Job's ID) - optional :token, type: String, desc: %q(Job's authentication token) + requires :id, type: Integer, desc: "Job's ID" + optional :token, type: String, desc: "Job's authentication token" end - patch '/:id/trace' do + patch "/:id/trace" do job = authenticate_job! - job_forbidden!(job, 'Job is not running') unless job.running? + job_forbidden!(job, "Job is not running") unless job.running? - error!('400 Missing header Content-Range', 400) unless request.headers.key?('Content-Range') - content_range = request.headers['Content-Range'] - content_range = content_range.split('-') + error!("400 Missing header Content-Range", 400) unless request.headers.key?("Content-Range") + content_range = request.headers["Content-Range"] + content_range = content_range.split("-") # TODO: # it seems that `Content-Range` as formatted by runner is wrong, @@ -191,32 +191,32 @@ module API stream_size = job.trace.append(body_data, body_start) unless stream_size == body_end - break error!('416 Range Not Satisfiable', 416, { 'Range' => "0-#{stream_size}" }) + break error!("416 Range Not Satisfiable", 416, {"Range" => "0-#{stream_size}"}) end status 202 - header 'Job-Status', job.status - header 'Range', "0-#{stream_size}" + header "Job-Status", job.status + header "Range", "0-#{stream_size}" end - desc 'Authorize artifacts uploading for job' do - http_codes [[200, 'Upload allowed'], - [403, 'Forbidden'], - [405, 'Artifacts support not enabled'], - [413, 'File too large']] + desc "Authorize artifacts uploading for job" do + http_codes [[200, "Upload allowed"], + [403, "Forbidden"], + [405, "Artifacts support not enabled"], + [413, "File too large"],] end params do - requires :id, type: Integer, desc: %q(Job's ID) - optional :token, type: String, desc: %q(Job's authentication token) - optional :filesize, type: Integer, desc: %q(Artifacts filesize) + requires :id, type: Integer, desc: "Job's ID" + optional :token, type: String, desc: "Job's authentication token" + optional :filesize, type: Integer, desc: "Artifacts filesize" end - post '/:id/artifacts/authorize' do + post "/:id/artifacts/authorize" do not_allowed! unless Gitlab.config.artifacts.enabled require_gitlab_workhorse! Gitlab::Workhorse.verify_api_request!(headers) job = authenticate_job! - forbidden!('Job is not running') unless job.running? + forbidden!("Job is not running") unless job.running? if params[:filesize] file_size = params[:filesize].to_i @@ -228,55 +228,56 @@ module API JobArtifactUploader.workhorse_authorize(has_length: false, maximum_size: max_artifacts_size) end - desc 'Upload artifacts for job' do + desc "Upload artifacts for job" do success Entities::JobRequest::Response - http_codes [[201, 'Artifact uploaded'], - [400, 'Bad request'], - [403, 'Forbidden'], - [405, 'Artifacts support not enabled'], - [413, 'File too large']] + http_codes [[201, "Artifact uploaded"], + [400, "Bad request"], + [403, "Forbidden"], + [405, "Artifacts support not enabled"], + [413, "File too large"],] end params do - requires :id, type: Integer, desc: %q(Job's ID) - optional :token, type: String, desc: %q(Job's authentication token) - optional :expire_in, type: String, desc: %q(Specify when artifacts should expire) - optional :artifact_type, type: String, desc: %q(The type of artifact), - default: 'archive', values: Ci::JobArtifact.file_types.keys - optional :artifact_format, type: String, desc: %q(The format of artifact), - default: 'zip', values: Ci::JobArtifact.file_formats.keys - optional 'file.path', type: String, desc: %q(path to locally stored body (generated by Workhorse)) - optional 'file.name', type: String, desc: %q(real filename as send in Content-Disposition (generated by Workhorse)) - optional 'file.type', type: String, desc: %q(real content type as send in Content-Type (generated by Workhorse)) - optional 'file.size', type: Integer, desc: %q(real size of file (generated by Workhorse)) - optional 'file.sha256', type: String, desc: %q(sha256 checksum of the file (generated by Workhorse)) - optional 'metadata.path', type: String, desc: %q(path to locally stored body (generated by Workhorse)) - optional 'metadata.name', type: String, desc: %q(filename (generated by Workhorse)) - optional 'metadata.size', type: Integer, desc: %q(real size of metadata (generated by Workhorse)) - optional 'metadata.sha256', type: String, desc: %q(sha256 checksum of metadata (generated by Workhorse)) + requires :id, type: Integer, desc: "Job's ID" + optional :token, type: String, desc: "Job's authentication token" + optional :expire_in, type: String, desc: "Specify when artifacts should expire" + optional :artifact_type, type: String, desc: "The type of artifact", + default: "archive", values: Ci::JobArtifact.file_types.keys + optional :artifact_format, type: String, desc: "The format of artifact", + default: "zip", values: Ci::JobArtifact.file_formats.keys + optional "file.path", type: String, desc: "path to locally stored body (generated by Workhorse)" + optional "file.name", type: String, desc: "real filename as send in Content-Disposition (generated by Workhorse)" + optional "file.type", type: String, desc: "real content type as send in Content-Type (generated by Workhorse)" + optional "file.size", type: Integer, desc: "real size of file (generated by Workhorse)" + optional "file.sha256", type: String, desc: "sha256 checksum of the file (generated by Workhorse)" + optional "metadata.path", type: String, desc: "path to locally stored body (generated by Workhorse)" + optional "metadata.name", type: String, desc: "filename (generated by Workhorse)" + optional "metadata.size", type: Integer, desc: "real size of metadata (generated by Workhorse)" + optional "metadata.sha256", type: String, desc: "sha256 checksum of metadata (generated by Workhorse)" end - post '/:id/artifacts' do + post "/:id/artifacts" do not_allowed! unless Gitlab.config.artifacts.enabled require_gitlab_workhorse! job = authenticate_job! - forbidden!('Job is not running!') unless job.running? + forbidden!("Job is not running!") unless job.running? artifacts = UploadedFile.from_params(params, :file, JobArtifactUploader.workhorse_local_upload_path) metadata = UploadedFile.from_params(params, :metadata, JobArtifactUploader.workhorse_local_upload_path) - bad_request!('Missing artifacts file!') unless artifacts + bad_request!("Missing artifacts file!") unless artifacts file_to_large! unless artifacts.size < max_artifacts_size - expire_in = params['expire_in'] || + expire_in = params["expire_in"] || Gitlab::CurrentSettings.current_application_settings.default_artifacts_expire_in job.job_artifacts.build( project: job.project, file: artifacts, - file_type: params['artifact_type'], - file_format: params['artifact_format'], + file_type: params["artifact_type"], + file_format: params["artifact_format"], file_sha256: artifacts.sha256, - expire_in: expire_in) + expire_in: expire_in + ) if metadata job.job_artifacts.build( @@ -285,7 +286,8 @@ module API file_type: :metadata, file_format: :gzip, file_sha256: metadata.sha256, - expire_in: expire_in) + expire_in: expire_in + ) end if job.update(artifacts_expire_in: expire_in) @@ -295,17 +297,17 @@ module API end end - desc 'Download the artifacts file for job' do - http_codes [[200, 'Upload allowed'], - [403, 'Forbidden'], - [404, 'Artifact not found']] + desc "Download the artifacts file for job" do + http_codes [[200, "Upload allowed"], + [403, "Forbidden"], + [404, "Artifact not found"],] end params do - requires :id, type: Integer, desc: %q(Job's ID) - optional :token, type: String, desc: %q(Job's authentication token) - optional :direct_download, default: false, type: Boolean, desc: %q(Perform direct download from remote storage instead of proxying artifacts) + requires :id, type: Integer, desc: "Job's ID" + optional :token, type: String, desc: "Job's authentication token" + optional :direct_download, default: false, type: Boolean, desc: "Perform direct download from remote storage instead of proxying artifacts" end - get '/:id/artifacts' do + get "/:id/artifacts" do job = authenticate_job! present_carrierwave_file!(job.artifacts_file, supports_direct_download: params[:direct_download]) diff --git a/lib/api/runners.rb b/lib/api/runners.rb index f3fea463e7f..1e99fbabcc8 100644 --- a/lib/api/runners.rb +++ b/lib/api/runners.rb @@ -7,17 +7,17 @@ module API before { authenticate! } resource :runners do - desc 'Get runners available for user' do + desc "Get runners available for user" do success Entities::Runner end params do optional :scope, type: String, values: Ci::Runner::AVAILABLE_STATUSES, - desc: 'The scope of specific runners to show' + desc: "The scope of specific runners to show" optional :type, type: String, values: Ci::Runner::AVAILABLE_TYPES, - desc: 'The type of the runners to show' + desc: "The type of the runners to show" optional :status, type: String, values: Ci::Runner::AVAILABLE_STATUSES, - desc: 'The status of the runners to show' - optional :tag_list, type: Array[String], desc: 'The tags of the runners to show' + desc: "The status of the runners to show" + optional :tag_list, type: Array[String], desc: "The tags of the runners to show" use :pagination end get do @@ -30,20 +30,20 @@ module API present paginate(runners), with: Entities::Runner end - desc 'Get all runners - shared and specific' do + desc "Get all runners - shared and specific" do success Entities::Runner end params do optional :scope, type: String, values: Ci::Runner::AVAILABLE_SCOPES, - desc: 'The scope of specific runners to show' + desc: "The scope of specific runners to show" optional :type, type: String, values: Ci::Runner::AVAILABLE_TYPES, - desc: 'The type of the runners to show' + desc: "The type of the runners to show" optional :status, type: String, values: Ci::Runner::AVAILABLE_STATUSES, - desc: 'The status of the runners to show' - optional :tag_list, type: Array[String], desc: 'The tags of the runners to show' + desc: "The status of the runners to show" + optional :tag_list, type: Array[String], desc: "The tags of the runners to show" use :pagination end - get 'all' do + get "all" do authenticated_as_admin! runners = Ci::Runner.all @@ -59,9 +59,9 @@ module API success Entities::RunnerDetails end params do - requires :id, type: Integer, desc: 'The ID of the runner' + requires :id, type: Integer, desc: "The ID of the runner" end - get ':id' do + get ":id" do runner = get_runner(params[:id]) authenticate_show_runner!(runner) @@ -72,18 +72,18 @@ module API success Entities::RunnerDetails end params do - requires :id, type: Integer, desc: 'The ID of the runner' - optional :description, type: String, desc: 'The description of the runner' - optional :active, type: Boolean, desc: 'The state of a runner' - optional :tag_list, type: Array[String], desc: 'The list of tags for a runner' - optional :run_untagged, type: Boolean, desc: 'Flag indicating the runner can execute untagged jobs' - optional :locked, type: Boolean, desc: 'Flag indicating the runner is locked' + requires :id, type: Integer, desc: "The ID of the runner" + optional :description, type: String, desc: "The description of the runner" + optional :active, type: Boolean, desc: "The state of a runner" + optional :tag_list, type: Array[String], desc: "The list of tags for a runner" + optional :run_untagged, type: Boolean, desc: "Flag indicating the runner can execute untagged jobs" + optional :locked, type: Boolean, desc: "Flag indicating the runner is locked" optional :access_level, type: String, values: Ci::Runner.access_levels.keys, - desc: 'The access_level of the runner' - optional :maximum_timeout, type: Integer, desc: 'Maximum timeout set when this Runner will handle the job' + desc: "The access_level of the runner" + optional :maximum_timeout, type: Integer, desc: "Maximum timeout set when this Runner will handle the job" at_least_one_of :description, :active, :tag_list, :run_untagged, :locked, :access_level, :maximum_timeout end - put ':id' do + put ":id" do runner = get_runner(params.delete(:id)) authenticate_update_runner!(runner) update_service = Ci::UpdateRunnerService.new(runner) @@ -95,13 +95,13 @@ module API end end - desc 'Remove a runner' do + desc "Remove a runner" do success Entities::Runner end params do - requires :id, type: Integer, desc: 'The ID of the runner' + requires :id, type: Integer, desc: "The ID of the runner" end - delete ':id' do + delete ":id" do runner = get_runner(params[:id]) authenticate_delete_runner!(runner) @@ -109,15 +109,15 @@ module API destroy_conditionally!(runner) end - desc 'List jobs running on a runner' do + desc "List jobs running on a runner" do success Entities::JobBasicWithProject end params do - requires :id, type: Integer, desc: 'The ID of the runner' - optional :status, type: String, desc: 'Status of the job', values: Ci::Build::AVAILABLE_STATUSES + requires :id, type: Integer, desc: "The ID of the runner" + optional :status, type: String, desc: "Status of the job", values: Ci::Build::AVAILABLE_STATUSES use :pagination end - get ':id/jobs' do + get ":id/jobs" do runner = get_runner(params[:id]) authenticate_list_runners_jobs!(runner) @@ -128,25 +128,25 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do before { authorize_admin_project } - desc 'Get runners available for project' do + desc "Get runners available for project" do success Entities::Runner end params do optional :scope, type: String, values: Ci::Runner::AVAILABLE_SCOPES, - desc: 'The scope of specific runners to show' + desc: "The scope of specific runners to show" optional :type, type: String, values: Ci::Runner::AVAILABLE_TYPES, - desc: 'The type of the runners to show' + desc: "The type of the runners to show" optional :status, type: String, values: Ci::Runner::AVAILABLE_STATUSES, - desc: 'The status of the runners to show' - optional :tag_list, type: Array[String], desc: 'The tags of the runners to show' + desc: "The status of the runners to show" + optional :tag_list, type: Array[String], desc: "The tags of the runners to show" use :pagination end - get ':id/runners' do + get ":id/runners" do runners = Ci::Runner.owned_or_instance_wide(user_project.id) runners = filter_runners(runners, params[:scope]) runners = filter_runners(runners, params[:type], allowed_scopes: Ci::Runner::AVAILABLE_TYPES) @@ -156,13 +156,13 @@ module API present paginate(runners), with: Entities::Runner end - desc 'Enable a runner for a project' do + desc "Enable a runner for a project" do success Entities::Runner end params do - requires :runner_id, type: Integer, desc: 'The ID of the runner' + requires :runner_id, type: Integer, desc: "The ID of the runner" end - post ':id/runners' do + post ":id/runners" do runner = get_runner(params[:runner_id]) authenticate_enable_runner!(runner) @@ -177,12 +177,12 @@ module API success Entities::Runner end params do - requires :runner_id, type: Integer, desc: 'The ID of the runner' + requires :runner_id, type: Integer, desc: "The ID of the runner" end # rubocop: disable CodeReuse/ActiveRecord - delete ':id/runners/:runner_id' do + delete ":id/runners/:runner_id" do runner_project = user_project.runner_projects.find_by(runner_id: params[:runner_id]) - not_found!('Runner') unless runner_project + not_found!("Runner") unless runner_project runner = runner_project.runner forbidden!("Only one project associated with the runner. Please remove the runner instead") if runner.projects.count == 1 @@ -197,7 +197,7 @@ module API return runners unless scope.present? unless allowed_scopes.include?(scope) - render_api_error!('Scope contains invalid value', 400) + render_api_error!("Scope contains invalid value", 400) end # Support deprecated scopes @@ -210,7 +210,7 @@ module API def get_runner(id) runner = Ci::Runner.find(id) - not_found!('Runner') unless runner + not_found!("Runner") unless runner runner end diff --git a/lib/api/scope.rb b/lib/api/scope.rb index 707775e5d15..1f290185480 100644 --- a/lib/api/scope.rb +++ b/lib/api/scope.rb @@ -13,7 +13,7 @@ module API # Are the `scopes` passed in sufficient to adequately authorize the passed # request for the scope represented by the current instance of this class? def sufficient?(scopes, request) - scopes.include?(self.name) && verify_if_condition(request) + scopes.include?(name) && verify_if_condition(request) end private diff --git a/lib/api/search.rb b/lib/api/search.rb index f5db692afe5..cb03f880d81 100644 --- a/lib/api/search.rb +++ b/lib/api/search.rb @@ -17,7 +17,7 @@ module API blobs: Entities::Blob, wiki_blobs: Entities::Blob, snippet_titles: Entities::Snippet, - snippet_blobs: Entities::Snippet + snippet_blobs: Entities::Snippet, }.freeze def search(additional_params = {}) @@ -26,7 +26,7 @@ module API search: params[:search], snippets: snippets?, page: params[:page], - per_page: params[:per_page] + per_page: params[:per_page], }.merge(additional_params) results = SearchService.new(current_user, search_params).search_objects @@ -39,7 +39,7 @@ module API end def snippets? - %w(snippet_blobs snippet_titles).include?(params[:scope]).to_s + %w[snippet_blobs snippet_titles].include?(params[:scope]).to_s end def entity @@ -48,16 +48,16 @@ module API end resource :search do - desc 'Search on GitLab' do - detail 'This feature was introduced in GitLab 10.5.' + desc "Search on GitLab" do + detail "This feature was introduced in GitLab 10.5." end params do - requires :search, type: String, desc: 'The expression it should be searched for' + requires :search, type: String, desc: "The expression it should be searched for" requires :scope, type: String, desc: 'The scope of search, available scopes: projects, issues, merge_requests, milestones, snippet_titles, snippet_blobs', - values: %w(projects issues merge_requests milestones snippet_titles snippet_blobs) + values: %w[projects issues merge_requests milestones snippet_titles snippet_blobs] use :pagination end get do @@ -66,39 +66,39 @@ module API end resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Search on GitLab' do - detail 'This feature was introduced in GitLab 10.5.' + desc "Search on GitLab" do + detail "This feature was introduced in GitLab 10.5." end params do - requires :id, type: String, desc: 'The ID of a group' - requires :search, type: String, desc: 'The expression it should be searched for' + requires :id, type: String, desc: "The ID of a group" + requires :search, type: String, desc: "The expression it should be searched for" requires :scope, type: String, desc: 'The scope of search, available scopes: projects, issues, merge_requests, milestones', - values: %w(projects issues merge_requests milestones) + values: %w[projects issues merge_requests milestones] use :pagination end - get ':id/(-/)search' do + get ":id/(-/)search" do present search(group_id: user_group.id), with: entity end end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Search on GitLab' do - detail 'This feature was introduced in GitLab 10.5.' + desc "Search on GitLab" do + detail "This feature was introduced in GitLab 10.5." end params do - requires :id, type: String, desc: 'The ID of a project' - requires :search, type: String, desc: 'The expression it should be searched for' + requires :id, type: String, desc: "The ID of a project" + requires :search, type: String, desc: "The expression it should be searched for" requires :scope, type: String, desc: 'The scope of search, available scopes: issues, merge_requests, milestones, notes, wiki_blobs, commits, blobs', - values: %w(issues merge_requests milestones notes wiki_blobs commits blobs) + values: %w[issues merge_requests milestones notes wiki_blobs commits blobs] use :pagination end - get ':id/(-/)search' do + get ":id/(-/)search" do present search(project_id: user_project.id), with: entity end end diff --git a/lib/api/services.rb b/lib/api/services.rb index bda6be51553..60a37802ca5 100644 --- a/lib/api/services.rb +++ b/lib/api/services.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module API class Services < Grape::API CHAT_NOTIFICATION_SETTINGS = [ @@ -6,20 +7,20 @@ module API required: true, name: :webhook, type: String, - desc: 'The chat webhook' + desc: "The chat webhook", }, { required: false, name: :username, type: String, - desc: 'The chat username' + desc: "The chat username", }, { required: false, name: :channel, type: String, - desc: 'The default chat channel' - } + desc: "The default chat channel", + }, ].freeze CHAT_NOTIFICATION_FLAGS = [ @@ -27,14 +28,14 @@ module API required: false, name: :notify_only_broken_pipelines, type: Boolean, - desc: 'Send notifications for broken pipelines' + desc: "Send notifications for broken pipelines", }, { required: false, name: :notify_only_default_branch, type: Boolean, - desc: 'Send notifications only for the default branch' - } + desc: "Send notifications only for the default branch", + }, ].freeze CHAT_NOTIFICATION_CHANNELS = [ @@ -42,50 +43,50 @@ module API required: false, name: :push_channel, type: String, - desc: 'The name of the channel to receive push_events notifications' + desc: "The name of the channel to receive push_events notifications", }, { required: false, name: :issue_channel, type: String, - desc: 'The name of the channel to receive issues_events notifications' + desc: "The name of the channel to receive issues_events notifications", }, { required: false, name: :confidential_issue_channel, type: String, - desc: 'The name of the channel to receive confidential_issues_events notifications' + desc: "The name of the channel to receive confidential_issues_events notifications", }, { required: false, name: :merge_request_channel, type: String, - desc: 'The name of the channel to receive merge_requests_events notifications' + desc: "The name of the channel to receive merge_requests_events notifications", }, { required: false, name: :note_channel, type: String, - desc: 'The name of the channel to receive note_events notifications' + desc: "The name of the channel to receive note_events notifications", }, { required: false, name: :tag_push_channel, type: String, - desc: 'The name of the channel to receive tag_push_events notifications' + desc: "The name of the channel to receive tag_push_events notifications", }, { required: false, name: :pipeline_channel, type: String, - desc: 'The name of the channel to receive pipeline_events notifications' + desc: "The name of the channel to receive pipeline_events notifications", }, { required: false, name: :wiki_page_channel, type: String, - desc: 'The name of the channel to receive wiki_page_events notifications' - } + desc: "The name of the channel to receive wiki_page_events notifications", + }, ].freeze CHAT_NOTIFICATION_EVENTS = [ @@ -93,571 +94,571 @@ module API required: false, name: :push_events, type: Boolean, - desc: 'Enable notifications for push_events' + desc: "Enable notifications for push_events", }, { required: false, name: :issues_events, type: Boolean, - desc: 'Enable notifications for issues_events' + desc: "Enable notifications for issues_events", }, { required: false, name: :confidential_issues_events, type: Boolean, - desc: 'Enable notifications for confidential_issues_events' + desc: "Enable notifications for confidential_issues_events", }, { required: false, name: :merge_requests_events, type: Boolean, - desc: 'Enable notifications for merge_requests_events' + desc: "Enable notifications for merge_requests_events", }, { required: false, name: :note_events, type: Boolean, - desc: 'Enable notifications for note_events' + desc: "Enable notifications for note_events", }, { required: false, name: :tag_push_events, type: Boolean, - desc: 'Enable notifications for tag_push_events' + desc: "Enable notifications for tag_push_events", }, { required: false, name: :pipeline_events, type: Boolean, - desc: 'Enable notifications for pipeline_events' + desc: "Enable notifications for pipeline_events", }, { required: false, name: :wiki_page_events, type: Boolean, - desc: 'Enable notifications for wiki_page_events' - } + desc: "Enable notifications for wiki_page_events", + }, ].freeze services = { - 'asana' => [ + "asana" => [ { required: true, name: :api_key, type: String, - desc: 'User API token' + desc: "User API token", }, { required: false, name: :restrict_to_branch, type: String, - desc: 'Comma-separated list of branches which will be automatically inspected. Leave blank to include all branches' - } + desc: "Comma-separated list of branches which will be automatically inspected. Leave blank to include all branches", + }, ], - 'assembla' => [ + "assembla" => [ { required: true, name: :token, type: String, - desc: 'The authentication token' + desc: "The authentication token", }, { required: false, name: :subdomain, type: String, - desc: 'Subdomain setting' - } + desc: "Subdomain setting", + }, ], - 'bamboo' => [ + "bamboo" => [ { required: true, name: :bamboo_url, type: String, - desc: 'Bamboo root URL like https://bamboo.example.com' + desc: "Bamboo root URL like https://bamboo.example.com", }, { required: true, name: :build_key, type: String, - desc: 'Bamboo build plan key like' + desc: "Bamboo build plan key like", }, { required: true, name: :username, type: String, - desc: 'A user with API access, if applicable' + desc: "A user with API access, if applicable", }, { required: true, name: :password, type: String, - desc: 'Passord of the user' - } + desc: "Passord of the user", + }, ], - 'bugzilla' => [ + "bugzilla" => [ { required: true, name: :new_issue_url, type: String, - desc: 'New issue URL' + desc: "New issue URL", }, { required: true, name: :issues_url, type: String, - desc: 'Issues URL' + desc: "Issues URL", }, { required: true, name: :project_url, type: String, - desc: 'Project URL' + desc: "Project URL", }, { required: false, name: :description, type: String, - desc: 'Description' + desc: "Description", }, { required: false, name: :title, type: String, - desc: 'Title' - } + desc: "Title", + }, ], - 'buildkite' => [ + "buildkite" => [ { required: true, name: :token, type: String, - desc: 'Buildkite project GitLab token' + desc: "Buildkite project GitLab token", }, { required: true, name: :project_url, type: String, - desc: 'The buildkite project URL' + desc: "The buildkite project URL", }, { required: false, name: :enable_ssl_verification, type: Boolean, - desc: 'Enable SSL verification for communication' - } + desc: "Enable SSL verification for communication", + }, ], - 'campfire' => [ + "campfire" => [ { required: true, name: :token, type: String, - desc: 'Campfire token' + desc: "Campfire token", }, { required: false, name: :subdomain, type: String, - desc: 'Campfire subdomain' + desc: "Campfire subdomain", }, { required: false, name: :room, type: String, - desc: 'Campfire room' - } + desc: "Campfire room", + }, ], - 'custom-issue-tracker' => [ + "custom-issue-tracker" => [ { required: true, name: :new_issue_url, type: String, - desc: 'New issue URL' + desc: "New issue URL", }, { required: true, name: :issues_url, type: String, - desc: 'Issues URL' + desc: "Issues URL", }, { required: true, name: :project_url, type: String, - desc: 'Project URL' + desc: "Project URL", }, { required: false, name: :description, type: String, - desc: 'Description' + desc: "Description", }, { required: false, name: :title, type: String, - desc: 'Title' - } + desc: "Title", + }, ], - 'discord' => [ + "discord" => [ { required: true, name: :webhook, type: String, - desc: 'Discord webhook. e.g. https://discordapp.com/api/webhooks/…' - } + desc: "Discord webhook. e.g. https://discordapp.com/api/webhooks/…", + }, ], - 'drone-ci' => [ + "drone-ci" => [ { required: true, name: :token, type: String, - desc: 'Drone CI token' + desc: "Drone CI token", }, { required: true, name: :drone_url, type: String, - desc: 'Drone CI URL' + desc: "Drone CI URL", }, { required: false, name: :enable_ssl_verification, type: Boolean, - desc: 'Enable SSL verification for communication' - } + desc: "Enable SSL verification for communication", + }, ], - 'emails-on-push' => [ + "emails-on-push" => [ { required: true, name: :recipients, type: String, - desc: 'Comma-separated list of recipient email addresses' + desc: "Comma-separated list of recipient email addresses", }, { required: false, name: :disable_diffs, type: Boolean, - desc: 'Disable code diffs' + desc: "Disable code diffs", }, { required: false, name: :send_from_committer_email, type: Boolean, - desc: 'Send from committer' - } + desc: "Send from committer", + }, ], - 'external-wiki' => [ + "external-wiki" => [ { required: true, name: :external_wiki_url, type: String, - desc: 'The URL of the external Wiki' - } + desc: "The URL of the external Wiki", + }, ], - 'flowdock' => [ + "flowdock" => [ { required: true, name: :token, type: String, - desc: 'Flowdock token' - } + desc: "Flowdock token", + }, ], - 'hangouts-chat' => [ + "hangouts-chat" => [ { required: true, name: :webhook, type: String, - desc: 'The Hangouts Chat webhook. e.g. https://chat.googleapis.com/v1/spaces…' + desc: "The Hangouts Chat webhook. e.g. https://chat.googleapis.com/v1/spaces…", }, - CHAT_NOTIFICATION_EVENTS + CHAT_NOTIFICATION_EVENTS, ].flatten, - 'irker' => [ + "irker" => [ { required: true, name: :recipients, type: String, - desc: 'Recipients/channels separated by whitespaces' + desc: "Recipients/channels separated by whitespaces", }, { required: false, name: :default_irc_uri, type: String, - desc: 'Default: irc://irc.network.net:6697' + desc: "Default: irc://irc.network.net:6697", }, { required: false, name: :server_host, type: String, - desc: 'Server host. Default localhost' + desc: "Server host. Default localhost", }, { required: false, name: :server_port, type: Integer, - desc: 'Server port. Default 6659' + desc: "Server port. Default 6659", }, { required: false, name: :colorize_messages, type: Boolean, - desc: 'Colorize messages' - } + desc: "Colorize messages", + }, ], - 'jira' => [ + "jira" => [ { required: true, name: :url, type: String, - desc: 'The base URL to the JIRA instance web interface which is being linked to this GitLab project. E.g., https://jira.example.com' + desc: "The base URL to the JIRA instance web interface which is being linked to this GitLab project. E.g., https://jira.example.com", }, { required: false, name: :api_url, type: String, - desc: 'The base URL to the JIRA instance API. Web URL value will be used if not set. E.g., https://jira-api.example.com' + desc: "The base URL to the JIRA instance API. Web URL value will be used if not set. E.g., https://jira-api.example.com", }, { required: true, name: :username, type: String, - desc: 'The username of the user created to be used with GitLab/JIRA' + desc: "The username of the user created to be used with GitLab/JIRA", }, { required: true, name: :password, type: String, - desc: 'The password of the user created to be used with GitLab/JIRA' + desc: "The password of the user created to be used with GitLab/JIRA", }, { required: false, name: :jira_issue_transition_id, type: String, - desc: 'The ID of a transition that moves issues to a closed state. You can find this number under the JIRA workflow administration (**Administration > Issues > Workflows**) by selecting **View** under **Operations** of the desired workflow of your project. The ID of each state can be found inside the parenthesis of each transition name under the **Transitions (id)** column ([see screenshot][trans]). By default, this ID is set to `2`' - } + desc: "The ID of a transition that moves issues to a closed state. You can find this number under the JIRA workflow administration (**Administration > Issues > Workflows**) by selecting **View** under **Operations** of the desired workflow of your project. The ID of each state can be found inside the parenthesis of each transition name under the **Transitions (id)** column ([see screenshot][trans]). By default, this ID is set to `2`", + }, ], - 'kubernetes' => [ + "kubernetes" => [ { required: true, name: :namespace, type: String, - desc: 'The Kubernetes namespace to use' + desc: "The Kubernetes namespace to use", }, { required: true, name: :api_url, type: String, - desc: 'The URL to the Kubernetes cluster API, e.g., https://kubernetes.example.com' + desc: "The URL to the Kubernetes cluster API, e.g., https://kubernetes.example.com", }, { required: true, name: :token, type: String, - desc: 'The service token to authenticate against the Kubernetes cluster with' + desc: "The service token to authenticate against the Kubernetes cluster with", }, { required: false, name: :ca_pem, type: String, - desc: 'A custom certificate authority bundle to verify the Kubernetes cluster with (PEM format)' - } + desc: "A custom certificate authority bundle to verify the Kubernetes cluster with (PEM format)", + }, ], - 'mattermost-slash-commands' => [ + "mattermost-slash-commands" => [ { required: true, name: :token, type: String, - desc: 'The Mattermost token' - } + desc: "The Mattermost token", + }, ], - 'slack-slash-commands' => [ + "slack-slash-commands" => [ { required: true, name: :token, type: String, - desc: 'The Slack token' - } + desc: "The Slack token", + }, ], - 'packagist' => [ + "packagist" => [ { required: true, name: :username, type: String, - desc: 'The username' + desc: "The username", }, { required: true, name: :token, type: String, - desc: 'The Packagist API token' + desc: "The Packagist API token", }, { required: false, name: :server, type: String, - desc: 'The server' - } + desc: "The server", + }, ], - 'pipelines-email' => [ + "pipelines-email" => [ { required: true, name: :recipients, type: String, - desc: 'Comma-separated list of recipient email addresses' + desc: "Comma-separated list of recipient email addresses", }, { required: false, name: :notify_only_broken_pipelines, type: Boolean, - desc: 'Notify only broken pipelines' - } + desc: "Notify only broken pipelines", + }, ], - 'pivotaltracker' => [ + "pivotaltracker" => [ { required: true, name: :token, type: String, - desc: 'The Pivotaltracker token' + desc: "The Pivotaltracker token", }, { required: false, name: :restrict_to_branch, type: String, - desc: 'Comma-separated list of branches which will be automatically inspected. Leave blank to include all branches.' - } + desc: "Comma-separated list of branches which will be automatically inspected. Leave blank to include all branches.", + }, ], - 'prometheus' => [ + "prometheus" => [ { required: true, name: :api_url, type: String, - desc: 'Prometheus API Base URL, like http://prometheus.example.com/' - } + desc: "Prometheus API Base URL, like http://prometheus.example.com/", + }, ], - 'pushover' => [ + "pushover" => [ { required: true, name: :api_key, type: String, - desc: 'The application key' + desc: "The application key", }, { required: true, name: :user_key, type: String, - desc: 'The user key' + desc: "The user key", }, { required: true, name: :priority, type: String, - desc: 'The priority' + desc: "The priority", }, { required: true, name: :device, type: String, - desc: 'Leave blank for all active devices' + desc: "Leave blank for all active devices", }, { required: true, name: :sound, type: String, - desc: 'The sound of the notification' - } + desc: "The sound of the notification", + }, ], - 'redmine' => [ + "redmine" => [ { required: true, name: :new_issue_url, type: String, - desc: 'The new issue URL' + desc: "The new issue URL", }, { required: true, name: :project_url, type: String, - desc: 'The project URL' + desc: "The project URL", }, { required: true, name: :issues_url, type: String, - desc: 'The issues URL' + desc: "The issues URL", }, { required: false, name: :description, type: String, - desc: 'The description of the tracker' - } + desc: "The description of the tracker", + }, ], - 'youtrack' => [ + "youtrack" => [ { required: true, name: :project_url, type: String, - desc: 'The project URL' + desc: "The project URL", }, { required: true, name: :issues_url, type: String, - desc: 'The issues URL' + desc: "The issues URL", }, { required: false, name: :description, type: String, - desc: 'The description of the tracker' - } + desc: "The description of the tracker", + }, ], - 'slack' => [ + "slack" => [ CHAT_NOTIFICATION_SETTINGS, CHAT_NOTIFICATION_FLAGS, CHAT_NOTIFICATION_CHANNELS, - CHAT_NOTIFICATION_EVENTS + CHAT_NOTIFICATION_EVENTS, ].flatten, - 'microsoft-teams' => [ + "microsoft-teams" => [ { required: true, name: :webhook, type: String, - desc: 'The Microsoft Teams webhook. e.g. https://outlook.office.com/webhook/…' - } + desc: "The Microsoft Teams webhook. e.g. https://outlook.office.com/webhook/…", + }, ], - 'mattermost' => [ + "mattermost" => [ CHAT_NOTIFICATION_SETTINGS, CHAT_NOTIFICATION_FLAGS, CHAT_NOTIFICATION_CHANNELS, - CHAT_NOTIFICATION_EVENTS + CHAT_NOTIFICATION_EVENTS, ].flatten, - 'teamcity' => [ + "teamcity" => [ { required: true, name: :teamcity_url, type: String, - desc: 'TeamCity root URL like https://teamcity.example.com' + desc: "TeamCity root URL like https://teamcity.example.com", }, { required: true, name: :build_type, type: String, - desc: 'Build configuration ID' + desc: "Build configuration ID", }, { required: true, name: :username, type: String, - desc: 'A user with permissions to trigger a manual build' + desc: "A user with permissions to trigger a manual build", }, { required: true, name: :password, type: String, - desc: 'The password of the user' - } - ] + desc: "The password of the user", + }, + ], } service_classes = [ @@ -689,25 +690,25 @@ module API SlackService, MattermostService, MicrosoftTeamsService, - TeamcityService + TeamcityService, ] if Rails.env.development? - services['mock-ci'] = [ + services["mock-ci"] = [ { required: true, name: :mock_service_url, type: String, - desc: 'URL to the mock service' - } + desc: "URL to the mock service", + }, ] - services['mock-deployment'] = [] - services['mock-monitoring'] = [] + services["mock-deployment"] = [] + services["mock-monitoring"] = [] service_classes += [ MockCiService, MockDeploymentService, - MockMonitoringService + MockMonitoringService, ] end @@ -721,30 +722,30 @@ module API required: false, name: event_name.to_sym, type: String, - desc: service.event_description(event_name) + desc: service.event_description(event_name), } end end TRIGGER_SERVICES = { - 'mattermost-slash-commands' => [ + "mattermost-slash-commands" => [ { name: :token, type: String, - desc: 'The Mattermost token' - } + desc: "The Mattermost token", + }, ], - 'slack-slash-commands' => [ + "slack-slash-commands" => [ { name: :token, type: String, - desc: 'The Slack token' - } - ] + desc: "The Slack token", + }, + ], }.freeze params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do before { authenticate! } @@ -776,34 +777,34 @@ module API if service.update(service_params) present service, with: Entities::ProjectService else - render_api_error!('400 Bad Request', 400) + render_api_error!("400 Bad Request", 400) end end end desc "Delete a service for project" params do - requires :service_slug, type: String, values: SERVICES.keys, desc: 'The name of the service' + requires :service_slug, type: String, values: SERVICES.keys, desc: "The name of the service" end delete ":id/services/:service_slug" do service = user_project.find_or_initialize_service(params[:service_slug].underscore) destroy_conditionally!(service) do - attrs = service_attributes(service).inject({}) do |hash, key| + attrs = service_attributes(service).inject({}) { |hash, key| hash.merge!(key => nil) - end + } unless service.update(attrs.merge(active: false)) - render_api_error!('400 Bad Request', 400) + render_api_error!("400 Bad Request", 400) end end end - desc 'Get the service settings for project' do + desc "Get the service settings for project" do success Entities::ProjectService end params do - requires :service_slug, type: String, values: SERVICES.keys, desc: 'The name of the service' + requires :service_slug, type: String, values: SERVICES.keys, desc: "The name of the service" end get ":id/services/:service_slug" do service = user_project.find_or_initialize_service(params[:service_slug].underscore) @@ -823,11 +824,11 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do desc "Trigger a slash command for #{service_slug}" do - detail 'Added in GitLab 8.13' + detail "Added in GitLab 8.13" end params do settings.each do |setting| @@ -838,7 +839,7 @@ module API project = find_project(params[:id]) # This is not accurate, but done to prevent leakage of the project names - not_found!('Service') unless project + not_found!("Service") unless project service = slash_command_service(project, service_slug, params) result = service.try(:trigger, params) @@ -847,7 +848,7 @@ module API status result[:status] || 200 present result else - not_found!('Service') + not_found!("Service") end end end diff --git a/lib/api/settings.rb b/lib/api/settings.rb index b16faffe335..08dee0a1047 100644 --- a/lib/api/settings.rb +++ b/lib/api/settings.rb @@ -11,123 +11,123 @@ module API end end - desc 'Get the current application settings' do + desc "Get the current application settings" do success Entities::ApplicationSetting end get "application/settings" do present current_settings, with: Entities::ApplicationSetting end - desc 'Modify application settings' do + desc "Modify application settings" do success Entities::ApplicationSetting end params do - optional :admin_notification_email, type: String, desc: 'Abuse reports will be sent to this address if it is set. Abuse reports are always available in the admin area.' - optional :after_sign_up_text, type: String, desc: 'Text shown after sign up' - optional :after_sign_out_path, type: String, desc: 'We will redirect users to this page after they sign out' - optional :akismet_enabled, type: Boolean, desc: 'Helps prevent bots from creating issues' + optional :admin_notification_email, type: String, desc: "Abuse reports will be sent to this address if it is set. Abuse reports are always available in the admin area." + optional :after_sign_up_text, type: String, desc: "Text shown after sign up" + optional :after_sign_out_path, type: String, desc: "We will redirect users to this page after they sign out" + optional :akismet_enabled, type: Boolean, desc: "Helps prevent bots from creating issues" given akismet_enabled: ->(val) { val } do - requires :akismet_api_key, type: String, desc: 'Generate API key at http://www.akismet.com' + requires :akismet_api_key, type: String, desc: "Generate API key at http://www.akismet.com" end - optional :clientside_sentry_enabled, type: Boolean, desc: 'Sentry can also be used for reporting and logging clientside exceptions. https://sentry.io/for/javascript/' + optional :clientside_sentry_enabled, type: Boolean, desc: "Sentry can also be used for reporting and logging clientside exceptions. https://sentry.io/for/javascript/" given clientside_sentry_enabled: ->(val) { val } do - requires :clientside_sentry_dsn, type: String, desc: 'Clientside Sentry Data Source Name' + requires :clientside_sentry_dsn, type: String, desc: "Clientside Sentry Data Source Name" end - optional :container_registry_token_expire_delay, type: Integer, desc: 'Authorization token duration (minutes)' + optional :container_registry_token_expire_delay, type: Integer, desc: "Authorization token duration (minutes)" optional :default_artifacts_expire_in, type: String, desc: "Set the default expiration time for each job's artifacts" - optional :default_branch_protection, type: Integer, values: Gitlab::Access.protection_values, desc: 'Determine if developers can push to master' - optional :default_group_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The default group visibility' - optional :default_project_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The default project visibility' - optional :default_projects_limit, type: Integer, desc: 'The maximum number of personal projects' - optional :default_snippet_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The default snippet visibility' - optional :disabled_oauth_sign_in_sources, type: Array[String], desc: 'Disable certain OAuth sign-in sources' - optional :domain_blacklist_enabled, type: Boolean, desc: 'Enable domain blacklist for sign ups' + optional :default_branch_protection, type: Integer, values: Gitlab::Access.protection_values, desc: "Determine if developers can push to master" + optional :default_group_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: "The default group visibility" + optional :default_project_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: "The default project visibility" + optional :default_projects_limit, type: Integer, desc: "The maximum number of personal projects" + optional :default_snippet_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: "The default snippet visibility" + optional :disabled_oauth_sign_in_sources, type: Array[String], desc: "Disable certain OAuth sign-in sources" + optional :domain_blacklist_enabled, type: Boolean, desc: "Enable domain blacklist for sign ups" given domain_blacklist_enabled: ->(val) { val } do - requires :domain_blacklist, type: String, desc: 'Users with e-mail addresses that match these domain(s) will NOT be able to sign-up. Wildcards allowed. Use separate lines for multiple entries. Ex: domain.com, *.domain.com' - end - optional :domain_whitelist, type: String, desc: 'ONLY users with e-mail addresses that match these domain(s) will be able to sign-up. Wildcards allowed. Use separate lines for multiple entries. Ex: domain.com, *.domain.com' - optional :email_author_in_body, type: Boolean, desc: 'Some email servers do not support overriding the email sender name. Enable this option to include the name of the author of the issue, merge request or comment in the email body instead.' - optional :enabled_git_access_protocol, type: String, values: %w[ssh http nil], desc: 'Allow only the selected protocols to be used for Git access.' - optional :gitaly_timeout_default, type: Integer, desc: 'Default Gitaly timeout, in seconds. Set to 0 to disable timeouts.' - optional :gitaly_timeout_fast, type: Integer, desc: 'Gitaly fast operation timeout, in seconds. Set to 0 to disable timeouts.' - optional :gitaly_timeout_medium, type: Integer, desc: 'Medium Gitaly timeout, in seconds. Set to 0 to disable timeouts.' - optional :gravatar_enabled, type: Boolean, desc: 'Flag indicating if the Gravatar service is enabled' - optional :help_page_hide_commercial_content, type: Boolean, desc: 'Hide marketing-related entries from help' - optional :help_page_support_url, type: String, desc: 'Alternate support URL for help page' - optional :help_page_text, type: String, desc: 'Custom text displayed on the help page' - optional :home_page_url, type: String, desc: 'We will redirect non-logged in users to this page' - optional :housekeeping_enabled, type: Boolean, desc: 'Enable automatic repository housekeeping (git repack, git gc)' + requires :domain_blacklist, type: String, desc: "Users with e-mail addresses that match these domain(s) will NOT be able to sign-up. Wildcards allowed. Use separate lines for multiple entries. Ex: domain.com, *.domain.com" + end + optional :domain_whitelist, type: String, desc: "ONLY users with e-mail addresses that match these domain(s) will be able to sign-up. Wildcards allowed. Use separate lines for multiple entries. Ex: domain.com, *.domain.com" + optional :email_author_in_body, type: Boolean, desc: "Some email servers do not support overriding the email sender name. Enable this option to include the name of the author of the issue, merge request or comment in the email body instead." + optional :enabled_git_access_protocol, type: String, values: %w[ssh http nil], desc: "Allow only the selected protocols to be used for Git access." + optional :gitaly_timeout_default, type: Integer, desc: "Default Gitaly timeout, in seconds. Set to 0 to disable timeouts." + optional :gitaly_timeout_fast, type: Integer, desc: "Gitaly fast operation timeout, in seconds. Set to 0 to disable timeouts." + optional :gitaly_timeout_medium, type: Integer, desc: "Medium Gitaly timeout, in seconds. Set to 0 to disable timeouts." + optional :gravatar_enabled, type: Boolean, desc: "Flag indicating if the Gravatar service is enabled" + optional :help_page_hide_commercial_content, type: Boolean, desc: "Hide marketing-related entries from help" + optional :help_page_support_url, type: String, desc: "Alternate support URL for help page" + optional :help_page_text, type: String, desc: "Custom text displayed on the help page" + optional :home_page_url, type: String, desc: "We will redirect non-logged in users to this page" + optional :housekeeping_enabled, type: Boolean, desc: "Enable automatic repository housekeeping (git repack, git gc)" given housekeeping_enabled: ->(val) { val } do requires :housekeeping_bitmaps_enabled, type: Boolean, desc: "Creating pack file bitmaps makes housekeeping take a little longer but bitmaps should accelerate 'git clone' performance." requires :housekeeping_full_repack_period, type: Integer, desc: "Number of Git pushes after which a full 'git repack' is run." requires :housekeeping_gc_period, type: Integer, desc: "Number of Git pushes after which 'git gc' is run." requires :housekeeping_incremental_repack_period, type: Integer, desc: "Number of Git pushes after which an incremental 'git repack' is run." end - optional :html_emails_enabled, type: Boolean, desc: 'By default GitLab sends emails in HTML and plain text formats so mail clients can choose what format to use. Disable this option if you only want to send emails in plain text format.' + optional :html_emails_enabled, type: Boolean, desc: "By default GitLab sends emails in HTML and plain text formats so mail clients can choose what format to use. Disable this option if you only want to send emails in plain text format." optional :import_sources, type: Array[String], values: %w[github bitbucket gitlab google_code fogbugz git gitlab_project manifest], - desc: 'Enabled sources for code import during project creation. OmniAuth must be configured for GitHub, Bitbucket, and GitLab.com' + desc: "Enabled sources for code import during project creation. OmniAuth must be configured for GitHub, Bitbucket, and GitLab.com" optional :max_artifacts_size, type: Integer, desc: "Set the maximum file size for each job's artifacts" - optional :max_attachment_size, type: Integer, desc: 'Maximum attachment size in MB' - optional :max_pages_size, type: Integer, desc: 'Maximum size of pages in MB' - optional :metrics_enabled, type: Boolean, desc: 'Enable the InfluxDB metrics' + optional :max_attachment_size, type: Integer, desc: "Maximum attachment size in MB" + optional :max_pages_size, type: Integer, desc: "Maximum size of pages in MB" + optional :metrics_enabled, type: Boolean, desc: "Enable the InfluxDB metrics" given metrics_enabled: ->(val) { val } do - requires :metrics_host, type: String, desc: 'The InfluxDB host' - requires :metrics_method_call_threshold, type: Integer, desc: 'A method call is only tracked when it takes longer to complete than the given amount of milliseconds.' - requires :metrics_packet_size, type: Integer, desc: 'The amount of points to store in a single UDP packet' - requires :metrics_pool_size, type: Integer, desc: 'The amount of InfluxDB connections to open' - requires :metrics_port, type: Integer, desc: 'The UDP port to use for connecting to InfluxDB' - requires :metrics_sample_interval, type: Integer, desc: 'The sampling interval in seconds' - requires :metrics_timeout, type: Integer, desc: 'The amount of seconds after which an InfluxDB connection will time out' - end - optional :password_authentication_enabled, type: Boolean, desc: 'Flag indicating if password authentication is enabled for the web interface' # support legacy names, can be removed in v5 - optional :password_authentication_enabled_for_web, type: Boolean, desc: 'Flag indicating if password authentication is enabled for the web interface' + requires :metrics_host, type: String, desc: "The InfluxDB host" + requires :metrics_method_call_threshold, type: Integer, desc: "A method call is only tracked when it takes longer to complete than the given amount of milliseconds." + requires :metrics_packet_size, type: Integer, desc: "The amount of points to store in a single UDP packet" + requires :metrics_pool_size, type: Integer, desc: "The amount of InfluxDB connections to open" + requires :metrics_port, type: Integer, desc: "The UDP port to use for connecting to InfluxDB" + requires :metrics_sample_interval, type: Integer, desc: "The sampling interval in seconds" + requires :metrics_timeout, type: Integer, desc: "The amount of seconds after which an InfluxDB connection will time out" + end + optional :password_authentication_enabled, type: Boolean, desc: "Flag indicating if password authentication is enabled for the web interface" # support legacy names, can be removed in v5 + optional :password_authentication_enabled_for_web, type: Boolean, desc: "Flag indicating if password authentication is enabled for the web interface" mutually_exclusive :password_authentication_enabled_for_web, :password_authentication_enabled, :signin_enabled - optional :password_authentication_enabled_for_git, type: Boolean, desc: 'Flag indicating if password authentication is enabled for Git over HTTP(S)' - optional :performance_bar_allowed_group_id, type: String, desc: 'Deprecated: Use :performance_bar_allowed_group_path instead. Path of the group that is allowed to toggle the performance bar.' # support legacy names, can be removed in v6 - optional :performance_bar_allowed_group_path, type: String, desc: 'Path of the group that is allowed to toggle the performance bar.' - optional :performance_bar_enabled, type: String, desc: 'Deprecated: Pass `performance_bar_allowed_group_path: nil` instead. Allow enabling the performance.' # support legacy names, can be removed in v6 - optional :plantuml_enabled, type: Boolean, desc: 'Enable PlantUML' + optional :password_authentication_enabled_for_git, type: Boolean, desc: "Flag indicating if password authentication is enabled for Git over HTTP(S)" + optional :performance_bar_allowed_group_id, type: String, desc: "Deprecated: Use :performance_bar_allowed_group_path instead. Path of the group that is allowed to toggle the performance bar." # support legacy names, can be removed in v6 + optional :performance_bar_allowed_group_path, type: String, desc: "Path of the group that is allowed to toggle the performance bar." + optional :performance_bar_enabled, type: String, desc: "Deprecated: Pass `performance_bar_allowed_group_path: nil` instead. Allow enabling the performance." # support legacy names, can be removed in v6 + optional :plantuml_enabled, type: Boolean, desc: "Enable PlantUML" given plantuml_enabled: ->(val) { val } do - requires :plantuml_url, type: String, desc: 'The PlantUML server URL' + requires :plantuml_url, type: String, desc: "The PlantUML server URL" end - optional :polling_interval_multiplier, type: BigDecimal, desc: 'Interval multiplier used by endpoints that perform polling. Set to 0 to disable polling.' - optional :project_export_enabled, type: Boolean, desc: 'Enable project export' - optional :prometheus_metrics_enabled, type: Boolean, desc: 'Enable Prometheus metrics' - optional :recaptcha_enabled, type: Boolean, desc: 'Helps prevent bots from creating accounts' + optional :polling_interval_multiplier, type: BigDecimal, desc: "Interval multiplier used by endpoints that perform polling. Set to 0 to disable polling." + optional :project_export_enabled, type: Boolean, desc: "Enable project export" + optional :prometheus_metrics_enabled, type: Boolean, desc: "Enable Prometheus metrics" + optional :recaptcha_enabled, type: Boolean, desc: "Helps prevent bots from creating accounts" given recaptcha_enabled: ->(val) { val } do - requires :recaptcha_site_key, type: String, desc: 'Generate site key at http://www.google.com/recaptcha' - requires :recaptcha_private_key, type: String, desc: 'Generate private key at http://www.google.com/recaptcha' + requires :recaptcha_site_key, type: String, desc: "Generate site key at http://www.google.com/recaptcha" + requires :recaptcha_private_key, type: String, desc: "Generate private key at http://www.google.com/recaptcha" end optional :repository_checks_enabled, type: Boolean, desc: "GitLab will periodically run 'git fsck' in all project and wiki repositories to look for silent disk corruption issues." - optional :repository_storages, type: Array[String], desc: 'Storage paths for new projects' - optional :require_two_factor_authentication, type: Boolean, desc: 'Require all users to set up Two-factor authentication' + optional :repository_storages, type: Array[String], desc: "Storage paths for new projects" + optional :require_two_factor_authentication, type: Boolean, desc: "Require all users to set up Two-factor authentication" given require_two_factor_authentication: ->(val) { val } do - requires :two_factor_grace_period, type: Integer, desc: 'Amount of time (in hours) that users are allowed to skip forced configuration of two-factor authentication' + requires :two_factor_grace_period, type: Integer, desc: "Amount of time (in hours) that users are allowed to skip forced configuration of two-factor authentication" end - optional :restricted_visibility_levels, type: Array[String], desc: 'Selected levels cannot be used by non-admin users for groups, projects or snippets. If the public level is restricted, user profiles are only visible to logged in users.' - optional :send_user_confirmation_email, type: Boolean, desc: 'Send confirmation email on sign-up' - optional :sentry_enabled, type: Boolean, desc: 'Sentry is an error reporting and logging tool which is currently not shipped with GitLab, get it here: https://getsentry.com' + optional :restricted_visibility_levels, type: Array[String], desc: "Selected levels cannot be used by non-admin users for groups, projects or snippets. If the public level is restricted, user profiles are only visible to logged in users." + optional :send_user_confirmation_email, type: Boolean, desc: "Send confirmation email on sign-up" + optional :sentry_enabled, type: Boolean, desc: "Sentry is an error reporting and logging tool which is currently not shipped with GitLab, get it here: https://getsentry.com" given sentry_enabled: ->(val) { val } do - requires :sentry_dsn, type: String, desc: 'Sentry Data Source Name' + requires :sentry_dsn, type: String, desc: "Sentry Data Source Name" end - optional :session_expire_delay, type: Integer, desc: 'Session duration in minutes. GitLab restart is required to apply changes.' - optional :shared_runners_enabled, type: Boolean, desc: 'Enable shared runners for new projects' + optional :session_expire_delay, type: Integer, desc: "Session duration in minutes. GitLab restart is required to apply changes." + optional :shared_runners_enabled, type: Boolean, desc: "Enable shared runners for new projects" given shared_runners_enabled: ->(val) { val } do - requires :shared_runners_text, type: String, desc: 'Shared runners text ' - end - optional :sign_in_text, type: String, desc: 'The sign in text of the GitLab application' - optional :signin_enabled, type: Boolean, desc: 'Flag indicating if password authentication is enabled for the web interface' # support legacy names, can be removed in v5 - optional :signup_enabled, type: Boolean, desc: 'Flag indicating if sign up is enabled' - optional :terminal_max_session_time, type: Integer, desc: 'Maximum time for web terminal websocket connection (in seconds). Set to 0 for unlimited time.' - optional :usage_ping_enabled, type: Boolean, desc: 'Every week GitLab will report license usage back to GitLab, Inc.' - optional :instance_statistics_visibility_private, type: Boolean, desc: 'When set to `true` Instance statistics will only be available to admins' + requires :shared_runners_text, type: String, desc: "Shared runners text " + end + optional :sign_in_text, type: String, desc: "The sign in text of the GitLab application" + optional :signin_enabled, type: Boolean, desc: "Flag indicating if password authentication is enabled for the web interface" # support legacy names, can be removed in v5 + optional :signup_enabled, type: Boolean, desc: "Flag indicating if sign up is enabled" + optional :terminal_max_session_time, type: Integer, desc: "Maximum time for web terminal websocket connection (in seconds). Set to 0 for unlimited time." + optional :usage_ping_enabled, type: Boolean, desc: "Every week GitLab will report license usage back to GitLab, Inc." + optional :instance_statistics_visibility_private, type: Boolean, desc: "When set to `true` Instance statistics will only be available to admins" optional :local_markdown_version, type: Integer, desc: "Local markdown version, increase this value when any cached markdown should be invalidated" ApplicationSetting::SUPPORTED_KEY_TYPES.each do |type| optional :"#{type}_key_restriction", - type: Integer, - values: KeyRestrictionValidator.supported_key_restrictions(type), - desc: "Restrictions on the complexity of uploaded #{type.upcase} keys. A value of #{ApplicationSetting::FORBIDDEN_KEY_VALUE} disables all #{type.upcase} keys." + type: Integer, + values: KeyRestrictionValidator.supported_key_restrictions(type), + desc: "Restrictions on the complexity of uploaded #{type.upcase} keys. A value of #{ApplicationSetting::FORBIDDEN_KEY_VALUE} disables all #{type.upcase} keys." end optional_attributes = ::ApplicationSettingsHelper.visible_attributes << :performance_bar_allowed_group_id @@ -139,20 +139,20 @@ module API attrs = declared_params(include_missing: false) # support legacy names, can be removed in v6 - if attrs.has_key?(:performance_bar_allowed_group_id) + if attrs.key?(:performance_bar_allowed_group_id) attrs[:performance_bar_allowed_group_path] = attrs.delete(:performance_bar_allowed_group_id) end # support legacy names, can be removed in v6 - if attrs.has_key?(:performance_bar_enabled) + if attrs.key?(:performance_bar_enabled) performance_bar_enabled = attrs.delete(:performance_bar_allowed_group_id) attrs[:performance_bar_allowed_group_path] = nil unless performance_bar_enabled end # support legacy names, can be removed in v5 - if attrs.has_key?(:signin_enabled) + if attrs.key?(:signin_enabled) attrs[:password_authentication_enabled_for_web] = attrs.delete(:signin_enabled) - elsif attrs.has_key?(:password_authentication_enabled) + elsif attrs.key?(:password_authentication_enabled) attrs[:password_authentication_enabled_for_web] = attrs.delete(:password_authentication_enabled) end diff --git a/lib/api/sidekiq_metrics.rb b/lib/api/sidekiq_metrics.rb index daa9598a204..a8fd2a01b13 100644 --- a/lib/api/sidekiq_metrics.rb +++ b/lib/api/sidekiq_metrics.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'sidekiq/api' +require "sidekiq/api" module API class SidekiqMetrics < Grape::API @@ -11,7 +11,7 @@ module API Sidekiq::Queue.all.each_with_object({}) do |queue, hash| hash[queue.name] = { backlog: queue.size, - latency: queue.latency.to_i + latency: queue.latency.to_i, } end end @@ -19,14 +19,14 @@ module API def process_metrics Sidekiq::ProcessSet.new.map do |process| { - hostname: process['hostname'], - pid: process['pid'], - tag: process['tag'], - started_at: Time.at(process['started_at']), - queues: process['queues'], - labels: process['labels'], - concurrency: process['concurrency'], - busy: process['busy'] + hostname: process["hostname"], + pid: process["pid"], + tag: process["tag"], + started_at: Time.at(process["started_at"]), + queues: process["queues"], + labels: process["labels"], + concurrency: process["concurrency"], + busy: process["busy"], } end end @@ -36,29 +36,29 @@ module API { processed: stats.processed, failed: stats.failed, - enqueued: stats.enqueued + enqueued: stats.enqueued, } end end - desc 'Get the Sidekiq queue metrics' - get 'sidekiq/queue_metrics' do - { queues: queue_metrics } + desc "Get the Sidekiq queue metrics" + get "sidekiq/queue_metrics" do + {queues: queue_metrics} end - desc 'Get the Sidekiq process metrics' - get 'sidekiq/process_metrics' do - { processes: process_metrics } + desc "Get the Sidekiq process metrics" + get "sidekiq/process_metrics" do + {processes: process_metrics} end - desc 'Get the Sidekiq job statistics' - get 'sidekiq/job_stats' do - { jobs: job_stats } + desc "Get the Sidekiq job statistics" + get "sidekiq/job_stats" do + {jobs: job_stats} end - desc 'Get the Sidekiq Compound metrics. Includes queue, process, and job statistics' - get 'sidekiq/compound_metrics' do - { queues: queue_metrics, processes: process_metrics, jobs: job_stats } + desc "Get the Sidekiq Compound metrics. Includes queue, process, and job statistics" + get "sidekiq/compound_metrics" do + {queues: queue_metrics, processes: process_metrics, jobs: job_stats} end end end diff --git a/lib/api/snippets.rb b/lib/api/snippets.rb index 326d55afd0e..62e1e9aef2d 100644 --- a/lib/api/snippets.rb +++ b/lib/api/snippets.rb @@ -18,8 +18,8 @@ module API end end - desc 'Get a snippets list for authenticated user' do - detail 'This feature was introduced in GitLab 8.15.' + desc "Get a snippets list for authenticated user" do + detail "This feature was introduced in GitLab 8.15." success Entities::PersonalSnippet end params do @@ -29,42 +29,42 @@ module API present paginate(snippets_for_current_user), with: Entities::PersonalSnippet end - desc 'List all public snippets current_user has access to' do - detail 'This feature was introduced in GitLab 8.15.' + desc "List all public snippets current_user has access to" do + detail "This feature was introduced in GitLab 8.15." success Entities::PersonalSnippet end params do use :pagination end - get 'public' do + get "public" do present paginate(public_snippets), with: Entities::PersonalSnippet end - desc 'Get a single snippet' do - detail 'This feature was introduced in GitLab 8.15.' + desc "Get a single snippet" do + detail "This feature was introduced in GitLab 8.15." success Entities::PersonalSnippet end params do - requires :id, type: Integer, desc: 'The ID of a snippet' + requires :id, type: Integer, desc: "The ID of a snippet" end - get ':id' do + get ":id" do snippet = snippets_for_current_user.find(params[:id]) present snippet, with: Entities::PersonalSnippet end - desc 'Create new snippet' do - detail 'This feature was introduced in GitLab 8.15.' + desc "Create new snippet" do + detail "This feature was introduced in GitLab 8.15." success Entities::PersonalSnippet end params do - requires :title, type: String, desc: 'The title of a snippet' - requires :file_name, type: String, desc: 'The name of a snippet file' - requires :content, type: String, desc: 'The content of a snippet' - optional :description, type: String, desc: 'The description of a snippet' + requires :title, type: String, desc: "The title of a snippet" + requires :file_name, type: String, desc: "The name of a snippet file" + requires :content, type: String, desc: "The content of a snippet" + optional :description, type: String, desc: "The description of a snippet" optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, - default: 'internal', - desc: 'The visibility of the snippet' + default: "internal", + desc: "The visibility of the snippet" end post do attrs = declared_params(include_missing: false).merge(request: request, api: true) @@ -79,25 +79,25 @@ module API end end - desc 'Update an existing snippet' do - detail 'This feature was introduced in GitLab 8.15.' + desc "Update an existing snippet" do + detail "This feature was introduced in GitLab 8.15." success Entities::PersonalSnippet end params do - requires :id, type: Integer, desc: 'The ID of a snippet' - optional :title, type: String, desc: 'The title of a snippet' - optional :file_name, type: String, desc: 'The name of a snippet file' - optional :content, type: String, desc: 'The content of a snippet' - optional :description, type: String, desc: 'The description of a snippet' + requires :id, type: Integer, desc: "The ID of a snippet" + optional :title, type: String, desc: "The title of a snippet" + optional :file_name, type: String, desc: "The name of a snippet file" + optional :content, type: String, desc: "The content of a snippet" + optional :description, type: String, desc: "The description of a snippet" optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, - desc: 'The visibility of the snippet' + desc: "The visibility of the snippet" at_least_one_of :title, :file_name, :content, :visibility end # rubocop: disable CodeReuse/ActiveRecord - put ':id' do + put ":id" do snippet = snippets_for_current_user.find_by(id: params.delete(:id)) - break not_found!('Snippet') unless snippet + break not_found!("Snippet") unless snippet authorize! :update_personal_snippet, snippet @@ -115,17 +115,17 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Remove snippet' do - detail 'This feature was introduced in GitLab 8.15.' + desc "Remove snippet" do + detail "This feature was introduced in GitLab 8.15." success Entities::PersonalSnippet end params do - requires :id, type: Integer, desc: 'The ID of a snippet' + requires :id, type: Integer, desc: "The ID of a snippet" end # rubocop: disable CodeReuse/ActiveRecord - delete ':id' do + delete ":id" do snippet = snippets_for_current_user.find_by(id: params.delete(:id)) - break not_found!('Snippet') unless snippet + break not_found!("Snippet") unless snippet authorize! :destroy_personal_snippet, snippet @@ -133,29 +133,29 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get a raw snippet' do - detail 'This feature was introduced in GitLab 8.15.' + desc "Get a raw snippet" do + detail "This feature was introduced in GitLab 8.15." end params do - requires :id, type: Integer, desc: 'The ID of a snippet' + requires :id, type: Integer, desc: "The ID of a snippet" end # rubocop: disable CodeReuse/ActiveRecord get ":id/raw" do snippet = snippets_for_current_user.find_by(id: params.delete(:id)) - break not_found!('Snippet') unless snippet + break not_found!("Snippet") unless snippet - env['api.format'] = :txt - content_type 'text/plain' - header['Content-Disposition'] = 'attachment' + env["api.format"] = :txt + content_type "text/plain" + header["Content-Disposition"] = "attachment" present snippet.content end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get the user agent details for a snippet' do + desc "Get the user agent details for a snippet" do success Entities::UserAgentDetail end params do - requires :id, type: Integer, desc: 'The ID of a snippet' + requires :id, type: Integer, desc: "The ID of a snippet" end # rubocop: disable CodeReuse/ActiveRecord get ":id/user_agent_detail" do @@ -163,7 +163,7 @@ module API snippet = Snippet.find_by!(id: params[:id]) - break not_found!('UserAgentDetail') unless snippet.user_agent_detail + break not_found!("UserAgentDetail") unless snippet.user_agent_detail present snippet.user_agent_detail, with: Entities::UserAgentDetail end diff --git a/lib/api/submodules.rb b/lib/api/submodules.rb index 72d7d994102..a76c6a832db 100644 --- a/lib/api/submodules.rb +++ b/lib/api/submodules.rb @@ -10,23 +10,23 @@ module API submodule: attrs[:submodule], commit_sha: attrs[:commit_sha], branch_name: attrs[:branch], - commit_message: attrs[:commit_message] + commit_message: attrs[:commit_message], } end end params do - requires :id, type: String, desc: 'The project ID' + requires :id, type: String, desc: "The project ID" end resource :projects, requirements: Files::FILE_ENDPOINT_REQUIREMENTS do - desc 'Update existing submodule reference in repository' do + desc "Update existing submodule reference in repository" do success Entities::Commit end params do - requires :submodule, type: String, desc: 'Url encoded full path to submodule.' - requires :commit_sha, type: String, desc: 'Commit sha to update the submodule to.' - requires :branch, type: String, desc: 'Name of the branch to commit into.' - optional :commit_message, type: String, desc: 'Commit message. If no message is provided a default one will be set.' + requires :submodule, type: String, desc: "Url encoded full path to submodule." + requires :commit_sha, type: String, desc: "Commit sha to update the submodule to." + requires :branch, type: String, desc: "Name of the branch to commit into." + optional :commit_message, type: String, desc: "Commit message. If no message is provided a default one will be set." end put ":id/repository/submodules/:submodule", requirements: Files::FILE_ENDPOINT_REQUIREMENTS do authorize! :push_code, user_project diff --git a/lib/api/subscriptions.rb b/lib/api/subscriptions.rb index dfb54446ddf..c36e52cfd79 100644 --- a/lib/api/subscriptions.rb +++ b/lib/api/subscriptions.rb @@ -8,29 +8,29 @@ module API subscribables = [ { - type: 'merge_requests', + type: "merge_requests", entity: Entities::MergeRequest, source: Project, - finder: ->(id) { find_merge_request_with_access(id, :update_merge_request) } + finder: ->(id) { find_merge_request_with_access(id, :update_merge_request) }, }, { - type: 'issues', + type: "issues", entity: Entities::Issue, source: Project, - finder: ->(id) { find_project_issue(id) } + finder: ->(id) { find_project_issue(id) }, }, { - type: 'labels', + type: "labels", entity: Entities::ProjectLabel, source: Project, - finder: ->(id) { find_label(user_project, id) } + finder: ->(id) { find_label(user_project, id) }, }, { - type: 'labels', + type: "labels", entity: Entities::GroupLabel, source: Group, - finder: ->(id) { find_label(user_group, id) } - } + finder: ->(id) { find_label(user_group, id) }, + }, ] subscribables.each do |subscribable| @@ -38,10 +38,10 @@ module API params do requires :id, type: String, desc: "The #{source_type} ID" - requires :subscribable_id, type: String, desc: 'The ID of a resource' + requires :subscribable_id, type: String, desc: "The ID of a resource" end resource source_type.pluralize, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Subscribe to a resource' do + desc "Subscribe to a resource" do success subscribable[:entity] end post ":id/#{subscribable[:type]}/:subscribable_id/subscribe" do @@ -56,7 +56,7 @@ module API end end - desc 'Unsubscribe from a resource' do + desc "Unsubscribe from a resource" do success subscribable[:entity] end post ":id/#{subscribable[:type]}/:subscribable_id/unsubscribe" do @@ -78,10 +78,8 @@ module API helpers do def parent_resource(source_type) case source_type - when 'project' + when "project" user_project - else - nil end end end diff --git a/lib/api/suggestions.rb b/lib/api/suggestions.rb index d008d1b9e97..92713b54230 100644 --- a/lib/api/suggestions.rb +++ b/lib/api/suggestions.rb @@ -5,13 +5,13 @@ module API before { authenticate! } resource :suggestions do - desc 'Apply suggestion patch in the Merge Request it was created' do + desc "Apply suggestion patch in the Merge Request it was created" do success Entities::Suggestion end params do - requires :id, type: String, desc: 'The suggestion ID' + requires :id, type: String, desc: "The suggestion ID" end - put ':id/apply' do + put ":id/apply" do suggestion = Suggestion.find_by_id(params[:id]) not_found! unless suggestion diff --git a/lib/api/system_hooks.rb b/lib/api/system_hooks.rb index 51fae0e54aa..ff4e903ed3c 100644 --- a/lib/api/system_hooks.rb +++ b/lib/api/system_hooks.rb @@ -10,7 +10,7 @@ module API end resource :hooks do - desc 'Get the list of system hooks' do + desc "Get the list of system hooks" do success Entities::Hook end params do @@ -20,12 +20,12 @@ module API present paginate(SystemHook.all), with: Entities::Hook end - desc 'Create a new system hook' do + desc "Create a new system hook" do success Entities::Hook end params do requires :url, type: String, desc: "The URL to send the request to" - optional :token, type: String, desc: 'The token used to validate payloads' + optional :token, type: String, desc: "The token used to validate payloads" optional :push_events, type: Boolean, desc: "Trigger hook on push events" optional :tag_push_events, type: Boolean, desc: "Trigger hook on tag push events" optional :merge_requests_events, type: Boolean, desc: "Trigger hook on tag push events" @@ -41,9 +41,9 @@ module API end end - desc 'Test a hook' + desc "Test a hook" params do - requires :id, type: Integer, desc: 'The ID of the system hook' + requires :id, type: Integer, desc: "The ID of the system hook" end get ":id" do hook = SystemHook.find(params[:id]) @@ -53,22 +53,22 @@ module API path: "ruby", project_id: 1, owner_name: "Someone", - owner_email: "example@gitlabhq.com" + owner_email: "example@gitlabhq.com", } - hook.execute(data, 'system_hooks') + hook.execute(data, "system_hooks") data end - desc 'Delete a hook' do + desc "Delete a hook" do success Entities::Hook end params do - requires :id, type: Integer, desc: 'The ID of the system hook' + requires :id, type: Integer, desc: "The ID of the system hook" end # rubocop: disable CodeReuse/ActiveRecord delete ":id" do hook = SystemHook.find_by(id: params[:id]) - not_found!('System hook') unless hook + not_found!("System hook") unless hook destroy_conditionally!(hook) end diff --git a/lib/api/tags.rb b/lib/api/tags.rb index f5359fd316c..6644f70056d 100644 --- a/lib/api/tags.rb +++ b/lib/api/tags.rb @@ -9,52 +9,52 @@ module API before { authorize! :download_code, user_project } params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get a project repository tags' do + desc "Get a project repository tags" do success Entities::Tag end params do - optional :sort, type: String, values: %w[asc desc], default: 'desc', - desc: 'Return tags sorted in updated by `asc` or `desc` order.' - optional :order_by, type: String, values: %w[name updated], default: 'updated', - desc: 'Return tags ordered by `name` or `updated` fields.' - optional :search, type: String, desc: 'Return list of tags matching the search criteria' + optional :sort, type: String, values: %w[asc desc], default: "desc", + desc: "Return tags sorted in updated by `asc` or `desc` order." + optional :order_by, type: String, values: %w[name updated], default: "updated", + desc: "Return tags ordered by `name` or `updated` fields." + optional :search, type: String, desc: "Return list of tags matching the search criteria" use :pagination end - get ':id/repository/tags' do + get ":id/repository/tags" do tags = ::TagsFinder.new(user_project.repository, - sort: "#{params[:order_by]}_#{params[:sort]}", - search: params[:search]).execute + sort: "#{params[:order_by]}_#{params[:sort]}", + search: params[:search]).execute present paginate(::Kaminari.paginate_array(tags)), with: Entities::Tag, project: user_project end - desc 'Get a single repository tag' do + desc "Get a single repository tag" do success Entities::Tag end params do - requires :tag_name, type: String, desc: 'The name of the tag' + requires :tag_name, type: String, desc: "The name of the tag" end - get ':id/repository/tags/:tag_name', requirements: TAG_ENDPOINT_REQUIREMENTS do + get ":id/repository/tags/:tag_name", requirements: TAG_ENDPOINT_REQUIREMENTS do tag = user_project.repository.find_tag(params[:tag_name]) - not_found!('Tag') unless tag + not_found!("Tag") unless tag present tag, with: Entities::Tag, project: user_project end - desc 'Create a new repository tag' do - detail 'This optional release_description parameter was deprecated in GitLab 11.7.' + desc "Create a new repository tag" do + detail "This optional release_description parameter was deprecated in GitLab 11.7." success Entities::Tag end params do - requires :tag_name, type: String, desc: 'The name of the tag' - requires :ref, type: String, desc: 'The commit sha or branch name' - optional :message, type: String, desc: 'Specifying a message creates an annotated tag' - optional :release_description, type: String, desc: 'Specifying release notes stored in the GitLab database (deprecated in GitLab 11.7)' + requires :tag_name, type: String, desc: "The name of the tag" + requires :ref, type: String, desc: "The commit sha or branch name" + optional :message, type: String, desc: "Specifying a message creates an annotated tag" + optional :release_description, type: String, desc: "Specifying release notes stored in the GitLab database (deprecated in GitLab 11.7)" end - post ':id/repository/tags' do + post ":id/repository/tags" do authorize_push_project result = ::Tags::CreateService.new(user_project, current_user) @@ -66,7 +66,7 @@ module API release_create_params = { tag: params[:tag_name], name: params[:tag_name], # Name can be specified in new API - description: params[:release_description] + description: params[:release_description], } ::Releases::CreateService @@ -75,28 +75,28 @@ module API end present result[:tag], - with: Entities::Tag, - project: user_project + with: Entities::Tag, + project: user_project else render_api_error!(result[:message], 400) end end - desc 'Delete a repository tag' + desc "Delete a repository tag" params do - requires :tag_name, type: String, desc: 'The name of the tag' + requires :tag_name, type: String, desc: "The name of the tag" end - delete ':id/repository/tags/:tag_name', requirements: TAG_ENDPOINT_REQUIREMENTS do + delete ":id/repository/tags/:tag_name", requirements: TAG_ENDPOINT_REQUIREMENTS do authorize_push_project tag = user_project.repository.find_tag(params[:tag_name]) - not_found!('Tag') unless tag + not_found!("Tag") unless tag commit = user_project.repository.commit(tag.dereferenced_target) destroy_conditionally!(commit, last_updated: commit.authored_date) do result = ::Tags::DestroyService.new(user_project, current_user) - .execute(params[:tag_name]) + .execute(params[:tag_name]) if result[:status] != :success render_api_error!(result[:message], result[:return_code]) @@ -104,25 +104,25 @@ module API end end - desc 'Add a release note to a tag' do - detail 'This feature was deprecated in GitLab 11.7.' + desc "Add a release note to a tag" do + detail "This feature was deprecated in GitLab 11.7." success Entities::TagRelease end params do - requires :tag_name, type: String, desc: 'The name of the tag', as: :tag - requires :description, type: String, desc: 'Release notes with markdown support' + requires :tag_name, type: String, desc: "The name of the tag", as: :tag + requires :description, type: String, desc: "Release notes with markdown support" end - post ':id/repository/tags/:tag_name/release', requirements: TAG_ENDPOINT_REQUIREMENTS do + post ":id/repository/tags/:tag_name/release", requirements: TAG_ENDPOINT_REQUIREMENTS do authorize_create_release! ## # Legacy API does not support tag auto creation. - not_found!('Tag') unless user_project.repository.find_tag(params[:tag]) + not_found!("Tag") unless user_project.repository.find_tag(params[:tag]) release_create_params = { tag: params[:tag], name: params[:tag], # Name can be specified in new API - description: params[:description] + description: params[:description], } result = ::Releases::CreateService @@ -137,14 +137,14 @@ module API end desc "Update a tag's release note" do - detail 'This feature was deprecated in GitLab 11.7.' + detail "This feature was deprecated in GitLab 11.7." success Entities::TagRelease end params do - requires :tag_name, type: String, desc: 'The name of the tag', as: :tag - requires :description, type: String, desc: 'Release notes with markdown support' + requires :tag_name, type: String, desc: "The name of the tag", as: :tag + requires :description, type: String, desc: "Release notes with markdown support" end - put ':id/repository/tags/:tag_name/release', requirements: TAG_ENDPOINT_REQUIREMENTS do + put ":id/repository/tags/:tag_name/release", requirements: TAG_ENDPOINT_REQUIREMENTS do authorize_update_release! result = ::Releases::UpdateService diff --git a/lib/api/templates.rb b/lib/api/templates.rb index 51f357d9477..c4b1c4f2d52 100644 --- a/lib/api/templates.rb +++ b/lib/api/templates.rb @@ -6,14 +6,14 @@ module API GLOBAL_TEMPLATE_TYPES = { gitignores: { - gitlab_version: 8.8 + gitlab_version: 8.8, }, gitlab_ci_ymls: { - gitlab_version: 8.9 + gitlab_version: 8.9, }, dockerfiles: { - gitlab_version: 8.15 - } + gitlab_version: 8.15, + }, }.freeze helpers do @@ -23,12 +23,12 @@ module API end end - desc 'Get the list of the available license template' do - detail 'This feature was introduced in GitLab 8.7.' + desc "Get the list of the available license template" do + detail "This feature was introduced in GitLab 8.7." success ::API::Entities::License end params do - optional :popular, type: Boolean, desc: 'If passed, returns only popular licenses' + optional :popular, type: Boolean, desc: "If passed, returns only popular licenses" use :pagination end get "templates/licenses" do @@ -40,17 +40,17 @@ module API present paginate(::Kaminari.paginate_array(templates)), with: ::API::Entities::License end - desc 'Get the text for a specific license' do - detail 'This feature was introduced in GitLab 8.7.' + desc "Get the text for a specific license" do + detail "This feature was introduced in GitLab 8.7." success ::API::Entities::License end params do - requires :name, type: String, desc: 'The name of the template' + requires :name, type: String, desc: "The name of the template" end - get "templates/licenses/:name", requirements: { name: /[\w\.-]+/ } do + get "templates/licenses/:name", requirements: {name: /[\w\.-]+/} do template = TemplateFinder.build(:licenses, nil, name: params[:name]).execute - not_found!('License') unless template.present? + not_found!("License") unless template.present? template.resolve!( project_name: params[:project].presence, @@ -63,7 +63,7 @@ module API GLOBAL_TEMPLATE_TYPES.each do |template_type, properties| gitlab_version = properties[:gitlab_version] - desc 'Get the list of the available template' do + desc "Get the list of the available template" do detail "This feature was introduced in GitLab #{gitlab_version}." success Entities::TemplatesList end @@ -75,14 +75,14 @@ module API present paginate(templates), with: Entities::TemplatesList end - desc 'Get the text for a specific template present in local filesystem' do + desc "Get the text for a specific template present in local filesystem" do detail "This feature was introduced in GitLab #{gitlab_version}." success Entities::Template end params do - requires :name, type: String, desc: 'The name of the template' + requires :name, type: String, desc: "The name of the template" end - get "templates/#{template_type}/:name", requirements: { name: /[\w\.-]+/ } do + get "templates/#{template_type}/:name", requirements: {name: /[\w\.-]+/} do finder = TemplateFinder.build(template_type, nil, name: declared(params)[:name]) new_template = finder.execute diff --git a/lib/api/time_tracking_endpoints.rb b/lib/api/time_tracking_endpoints.rb index 93fe06bec27..9a65801855d 100644 --- a/lib/api/time_tracking_endpoints.rb +++ b/lib/api/time_tracking_endpoints.rb @@ -7,7 +7,7 @@ module API included do helpers do def issuable_name - declared_params.key?(:issue_iid) ? 'issue' : 'merge_request' + declared_params.key?(:issue_iid) ? "issue" : "merge_request" end def issuable_key @@ -25,9 +25,9 @@ module API def load_issuable @issuable ||= begin case issuable_name - when 'issue' + when "issue" find_project_issue(params.delete(issuable_key)) - when 'merge_request' + when "merge_request" find_project_merge_request(params.delete(issuable_key)) end end @@ -46,18 +46,18 @@ module API end def update_service - issuable_name == 'issue' ? ::Issues::UpdateService : ::MergeRequests::UpdateService + issuable_name == "issue" ? ::Issues::UpdateService : ::MergeRequests::UpdateService end end - issuable_name = name.end_with?('Issues') ? 'issue' : 'merge_request' + issuable_name = name.end_with?("Issues") ? "issue" : "merge_request" issuable_collection_name = issuable_name.pluralize issuable_key = "#{issuable_name}_iid".to_sym desc "Set a time estimate for a project #{issuable_name}" params do requires issuable_key, type: Integer, desc: "The ID of a project #{issuable_name}" - requires :duration, type: String, desc: 'The duration to be parsed' + requires :duration, type: String, desc: "The duration to be parsed" end post ":id/#{issuable_collection_name}/:#{issuable_key}/time_estimate" do authorize! update_issuable_key, load_issuable @@ -80,14 +80,14 @@ module API desc "Add spent time for a project #{issuable_name}" params do requires issuable_key, type: Integer, desc: "The ID of a project #{issuable_name}" - requires :duration, type: String, desc: 'The duration to be parsed' + requires :duration, type: String, desc: "The duration to be parsed" end post ":id/#{issuable_collection_name}/:#{issuable_key}/add_spent_time" do authorize! update_issuable_key, load_issuable update_issuable(spend_time: { duration: Gitlab::TimeTrackingFormatter.parse(params.delete(:duration)), - user_id: current_user.id + user_id: current_user.id, }) end @@ -99,7 +99,7 @@ module API authorize! update_issuable_key, load_issuable status :ok - update_issuable(spend_time: { duration: :reset, user_id: current_user.id }) + update_issuable(spend_time: {duration: :reset, user_id: current_user.id}) end desc "Show time stats for a project #{issuable_name}" diff --git a/lib/api/todos.rb b/lib/api/todos.rb index 64ac8ece56c..99aad6eb964 100644 --- a/lib/api/todos.rb +++ b/lib/api/todos.rb @@ -7,22 +7,22 @@ module API before { authenticate! } ISSUABLE_TYPES = { - 'merge_requests' => ->(iid) { find_merge_request_with_access(iid) }, - 'issues' => ->(iid) { find_project_issue(iid) } + "merge_requests" => ->(iid) { find_merge_request_with_access(iid) }, + "issues" => ->(iid) { find_project_issue(iid) }, }.freeze params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do ISSUABLE_TYPES.each do |type, finder| type_id_str = "#{type.singularize}_iid".to_sym - desc 'Create a todo on an issuable' do + desc "Create a todo on an issuable" do success Entities::Todo end params do - requires type_id_str, type: Integer, desc: 'The IID of an issuable' + requires type_id_str, type: Integer, desc: "The IID of an issuable" end post ":id/#{type}/:#{type_id_str}/todo" do issuable = instance_exec(params[type_id_str], &finder) @@ -44,7 +44,7 @@ module API end end - desc 'Get a todo list' do + desc "Get a todo list" do success Entities::Todo end params do @@ -54,21 +54,21 @@ module API present paginate(find_todos), with: Entities::Todo, current_user: current_user end - desc 'Mark a todo as done' do + desc "Mark a todo as done" do success Entities::Todo end params do - requires :id, type: Integer, desc: 'The ID of the todo being marked as done' + requires :id, type: Integer, desc: "The ID of the todo being marked as done" end - post ':id/mark_as_done' do + post ":id/mark_as_done" do TodoService.new.mark_todos_as_done_by_ids(params[:id], current_user) todo = current_user.todos.find(params[:id]) present todo, with: Entities::Todo, current_user: current_user end - desc 'Mark all todos as done' - post '/mark_as_done' do + desc "Mark all todos as done" + post "/mark_as_done" do todos = find_todos TodoService.new.mark_todos_as_done(todos, current_user) diff --git a/lib/api/triggers.rb b/lib/api/triggers.rb index 8fc7c7361e1..6754fc13ec1 100644 --- a/lib/api/triggers.rb +++ b/lib/api/triggers.rb @@ -5,24 +5,24 @@ module API include PaginationParams params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Trigger a GitLab project pipeline' do + desc "Trigger a GitLab project pipeline" do success Entities::Pipeline end params do - requires :ref, type: String, desc: 'The commit sha or name of a branch or tag', allow_blank: false - requires :token, type: String, desc: 'The unique token of trigger' - optional :variables, type: Hash, desc: 'The list of variables to be injected into build' + requires :ref, type: String, desc: "The commit sha or name of a branch or tag", allow_blank: false + requires :token, type: String, desc: "The unique token of trigger" + optional :variables, type: Hash, desc: "The list of variables to be injected into build" end - post ":id/(ref/:ref/)trigger/pipeline", requirements: { ref: /.+/ } do - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42283') + post ":id/(ref/:ref/)trigger/pipeline", requirements: {ref: /.+/} do + Gitlab::QueryLimiting.whitelist("https://gitlab.com/gitlab-org/gitlab-ce/issues/42283") # validate variables params[:variables] = params[:variables].to_h unless params[:variables].all? { |key, value| key.is_a?(String) && value.is_a?(String) } - render_api_error!('variables needs to be a map of key-valued strings', 400) + render_api_error!("variables needs to be a map of key-valued strings", 400) end project = find_project(params[:id]) @@ -38,14 +38,14 @@ module API end end - desc 'Get triggers list' do + desc "Get triggers list" do success Entities::Trigger end params do use :pagination end # rubocop: disable CodeReuse/ActiveRecord - get ':id/triggers' do + get ":id/triggers" do authenticate! authorize! :admin_build, user_project @@ -55,34 +55,35 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get specific trigger of a project' do + desc "Get specific trigger of a project" do success Entities::Trigger end params do - requires :trigger_id, type: Integer, desc: 'The trigger ID' + requires :trigger_id, type: Integer, desc: "The trigger ID" end - get ':id/triggers/:trigger_id' do + get ":id/triggers/:trigger_id" do authenticate! authorize! :admin_build, user_project trigger = user_project.triggers.find(params.delete(:trigger_id)) - break not_found!('Trigger') unless trigger + break not_found!("Trigger") unless trigger present trigger, with: Entities::Trigger, current_user: current_user end - desc 'Create a trigger' do + desc "Create a trigger" do success Entities::Trigger end params do - requires :description, type: String, desc: 'The trigger description' + requires :description, type: String, desc: "The trigger description" end - post ':id/triggers' do + post ":id/triggers" do authenticate! authorize! :admin_build, user_project trigger = user_project.triggers.create( - declared_params(include_missing: false).merge(owner: current_user)) + declared_params(include_missing: false).merge(owner: current_user) + ) if trigger.valid? present trigger, with: Entities::Trigger, current_user: current_user @@ -91,19 +92,19 @@ module API end end - desc 'Update a trigger' do + desc "Update a trigger" do success Entities::Trigger end params do - requires :trigger_id, type: Integer, desc: 'The trigger ID' - optional :description, type: String, desc: 'The trigger description' + requires :trigger_id, type: Integer, desc: "The trigger ID" + optional :description, type: String, desc: "The trigger description" end - put ':id/triggers/:trigger_id' do + put ":id/triggers/:trigger_id" do authenticate! authorize! :admin_build, user_project trigger = user_project.triggers.find(params.delete(:trigger_id)) - break not_found!('Trigger') unless trigger + break not_found!("Trigger") unless trigger if trigger.update(declared_params(include_missing: false)) present trigger, with: Entities::Trigger, current_user: current_user @@ -112,18 +113,18 @@ module API end end - desc 'Take ownership of trigger' do + desc "Take ownership of trigger" do success Entities::Trigger end params do - requires :trigger_id, type: Integer, desc: 'The trigger ID' + requires :trigger_id, type: Integer, desc: "The trigger ID" end - post ':id/triggers/:trigger_id/take_ownership' do + post ":id/triggers/:trigger_id/take_ownership" do authenticate! authorize! :admin_build, user_project trigger = user_project.triggers.find(params.delete(:trigger_id)) - break not_found!('Trigger') unless trigger + break not_found!("Trigger") unless trigger if trigger.update(owner: current_user) status :ok @@ -133,18 +134,18 @@ module API end end - desc 'Delete a trigger' do + desc "Delete a trigger" do success Entities::Trigger end params do - requires :trigger_id, type: Integer, desc: 'The trigger ID' + requires :trigger_id, type: Integer, desc: "The trigger ID" end - delete ':id/triggers/:trigger_id' do + delete ":id/triggers/:trigger_id" do authenticate! authorize! :admin_build, user_project trigger = user_project.triggers.find(params.delete(:trigger_id)) - break not_found!('Trigger') unless trigger + break not_found!("Trigger") unless trigger destroy_conditionally!(trigger) end diff --git a/lib/api/users.rb b/lib/api/users.rb index 7d88880d412..4c0da1ca72f 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -6,9 +6,9 @@ module API include APIGuard include Helpers::CustomAttributes - allow_access_with_scope :read_user, if: -> (request) { request.get? } + allow_access_with_scope :read_user, if: ->(request) { request.get? } - resource :users, requirements: { uid: /[0-9]*/, id: /[0-9]*/ } do + resource :users, requirements: {uid: /[0-9]*/, id: /[0-9]*/} do include CustomAttributesEndpoints before do @@ -19,7 +19,7 @@ module API # rubocop: disable CodeReuse/ActiveRecord def find_user_by_id(params) id = params[:user_id] || params[:id] - User.find_by(id: id) || not_found!('User') + User.find_by(id: id) || not_found!("User") end # rubocop: enable CodeReuse/ActiveRecord @@ -34,47 +34,47 @@ module API # rubocop: enable CodeReuse/ActiveRecord params :optional_attributes do - optional :skype, type: String, desc: 'The Skype username' - optional :linkedin, type: String, desc: 'The LinkedIn username' - optional :twitter, type: String, desc: 'The Twitter username' - optional :website_url, type: String, desc: 'The website of the user' - optional :organization, type: String, desc: 'The organization of the user' - optional :projects_limit, type: Integer, desc: 'The number of projects a user can create' - optional :extern_uid, type: String, desc: 'The external authentication provider UID' - optional :provider, type: String, desc: 'The external provider' - optional :bio, type: String, desc: 'The biography of the user' - optional :location, type: String, desc: 'The location of the user' - optional :public_email, type: String, desc: 'The public email of the user' - optional :admin, type: Boolean, desc: 'Flag indicating the user is an administrator' - optional :can_create_group, type: Boolean, desc: 'Flag indicating the user can create groups' - optional :external, type: Boolean, desc: 'Flag indicating the user is an external user' - optional :avatar, type: File, desc: 'Avatar image for user' - optional :private_profile, type: Boolean, desc: 'Flag indicating the user has a private profile' + optional :skype, type: String, desc: "The Skype username" + optional :linkedin, type: String, desc: "The LinkedIn username" + optional :twitter, type: String, desc: "The Twitter username" + optional :website_url, type: String, desc: "The website of the user" + optional :organization, type: String, desc: "The organization of the user" + optional :projects_limit, type: Integer, desc: "The number of projects a user can create" + optional :extern_uid, type: String, desc: "The external authentication provider UID" + optional :provider, type: String, desc: "The external provider" + optional :bio, type: String, desc: "The biography of the user" + optional :location, type: String, desc: "The location of the user" + optional :public_email, type: String, desc: "The public email of the user" + optional :admin, type: Boolean, desc: "Flag indicating the user is an administrator" + optional :can_create_group, type: Boolean, desc: "Flag indicating the user can create groups" + optional :external, type: Boolean, desc: "Flag indicating the user is an external user" + optional :avatar, type: File, desc: "Avatar image for user" + optional :private_profile, type: Boolean, desc: "Flag indicating the user has a private profile" all_or_none_of :extern_uid, :provider end params :sort_params do optional :order_by, type: String, values: %w[id name username created_at updated_at], - default: 'id', desc: 'Return users ordered by a field' - optional :sort, type: String, values: %w[asc desc], default: 'desc', - desc: 'Return users sorted in ascending and descending order' + default: "id", desc: "Return users ordered by a field" + optional :sort, type: String, values: %w[asc desc], default: "desc", + desc: "Return users sorted in ascending and descending order" end end - desc 'Get the list of users' do + desc "Get the list of users" do success Entities::UserBasic end params do # CE - optional :username, type: String, desc: 'Get a single user with a specific username' - optional :extern_uid, type: String, desc: 'Get a single user with a specific external authentication provider UID' - optional :provider, type: String, desc: 'The external provider' - optional :search, type: String, desc: 'Search for a username' - optional :active, type: Boolean, default: false, desc: 'Filters only active users' - optional :external, type: Boolean, default: false, desc: 'Filters only external users' - optional :blocked, type: Boolean, default: false, desc: 'Filters only blocked users' - optional :created_after, type: DateTime, desc: 'Return users created after the specified time' - optional :created_before, type: DateTime, desc: 'Return users created before the specified time' + optional :username, type: String, desc: "Get a single user with a specific username" + optional :extern_uid, type: String, desc: "Get a single user with a specific external authentication provider UID" + optional :provider, type: String, desc: "The external provider" + optional :search, type: String, desc: "Search for a username" + optional :active, type: Boolean, default: false, desc: "Filters only active users" + optional :external, type: Boolean, default: false, desc: "Filters only external users" + optional :blocked, type: Boolean, default: false, desc: "Filters only blocked users" + optional :created_after, type: DateTime, desc: "Return users created after the specified time" + optional :created_before, type: DateTime, desc: "Return users created before the specified time" all_or_none_of :extern_uid, :provider use :sort_params @@ -105,26 +105,26 @@ module API entity = current_user&.admin? ? Entities::UserWithAdmin : Entities::UserBasic users = users.preload(:identities, :u2f_registrations) if entity == Entities::UserWithAdmin - users, options = with_custom_attributes(users, { with: entity, current_user: current_user }) + users, options = with_custom_attributes(users, {with: entity, current_user: current_user}) present paginate(users), options end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get a single user' do + desc "Get a single user" do success Entities::User end params do - requires :id, type: Integer, desc: 'The ID of the user' + requires :id, type: Integer, desc: "The ID of the user" use :with_custom_attributes end # rubocop: disable CodeReuse/ActiveRecord get ":id" do user = User.find_by(id: params[:id]) - not_found!('User') unless user && can?(current_user, :read_user, user) + not_found!("User") unless user && can?(current_user, :read_user, user) - opts = { with: current_user&.admin? ? Entities::UserWithAdmin : Entities::User, current_user: current_user } + opts = {with: current_user&.admin? ? Entities::UserWithAdmin : Entities::User, current_user: current_user} user, opts = with_custom_attributes(user, opts) present user, opts @@ -133,26 +133,26 @@ module API desc "Get the status of a user" params do - requires :user_id, type: String, desc: 'The ID or username of the user' + requires :user_id, type: String, desc: "The ID or username of the user" end get ":user_id/status", requirements: API::USER_REQUIREMENTS do user = find_user(params[:user_id]) - not_found!('User') unless user && can?(current_user, :read_user, user) + not_found!("User") unless user && can?(current_user, :read_user, user) present user.status || {}, with: Entities::UserStatus end - desc 'Create a user. Available only for admins.' do + desc "Create a user. Available only for admins." do success Entities::UserPublic end params do - requires :email, type: String, desc: 'The email of the user' - optional :password, type: String, desc: 'The password of the new user' - optional :reset_password, type: Boolean, desc: 'Flag indicating the user will be sent a password reset token' - optional :skip_confirmation, type: Boolean, desc: 'Flag indicating the account is confirmed' + requires :email, type: String, desc: "The email of the user" + optional :password, type: String, desc: "The password of the new user" + optional :reset_password, type: Boolean, desc: "Flag indicating the user will be sent a password reset token" + optional :skip_confirmation, type: Boolean, desc: "Flag indicating the account is confirmed" at_least_one_of :password, :reset_password - requires :name, type: String, desc: 'The name of the user' - requires :username, type: String, desc: 'The username of the user' + requires :name, type: String, desc: "The name of the user" + requires :username, type: String, desc: "The username of the user" use :optional_attributes end post do @@ -164,11 +164,11 @@ module API if user.persisted? present user, with: Entities::UserPublic, current_user: current_user else - conflict!('Email has already been taken') if User + conflict!("Email has already been taken") if User .by_any_email(user.email.downcase) .any? - conflict!('Username has already been taken') if User + conflict!("Username has already been taken") if User .by_username(user.username) .any? @@ -176,16 +176,16 @@ module API end end - desc 'Update a user. Available only for admins.' do + desc "Update a user. Available only for admins." do success Entities::UserPublic end params do - requires :id, type: Integer, desc: 'The ID of the user' - optional :email, type: String, desc: 'The email of the user' - optional :password, type: String, desc: 'The password of the new user' - optional :skip_reconfirmation, type: Boolean, desc: 'Flag indicating the account skips the confirmation by email' - optional :name, type: String, desc: 'The name of the user' - optional :username, type: String, desc: 'The username of the user' + requires :id, type: Integer, desc: "The ID of the user" + optional :email, type: String, desc: "The email of the user" + optional :password, type: String, desc: "The password of the new user" + optional :skip_reconfirmation, type: Boolean, desc: "Flag indicating the account skips the confirmation by email" + optional :name, type: String, desc: "The name of the user" + optional :username, type: String, desc: "The username of the user" use :optional_attributes end # rubocop: disable CodeReuse/ActiveRecord @@ -193,15 +193,15 @@ module API authenticated_as_admin! user = User.find_by(id: params.delete(:id)) - not_found!('User') unless user + not_found!("User") unless user - conflict!('Email has already been taken') if params[:email] && - User.by_any_email(params[:email].downcase) - .where.not(id: user.id).count > 0 + conflict!("Email has already been taken") if params[:email] && + User.by_any_email(params[:email].downcase) + .where.not(id: user.id).count > 0 - conflict!('Username has already been taken') if params[:username] && - User.by_username(params[:username]) - .where.not(id: user.id).count > 0 + conflict!("Username has already been taken") if params[:username] && + User.by_username(params[:username]) + .where.not(id: user.id).count > 0 user_params = declared_params(include_missing: false) identity_attrs = user_params.slice(:provider, :extern_uid) @@ -229,20 +229,20 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Add an SSH key to a specified user. Available only for admins.' do + desc "Add an SSH key to a specified user. Available only for admins." do success Entities::SSHKey end params do - requires :id, type: Integer, desc: 'The ID of the user' - requires :key, type: String, desc: 'The new SSH key' - requires :title, type: String, desc: 'The title of the new SSH key' + requires :id, type: Integer, desc: "The ID of the user" + requires :key, type: String, desc: "The new SSH key" + requires :title, type: String, desc: "The title of the new SSH key" end # rubocop: disable CodeReuse/ActiveRecord post ":id/keys" do authenticated_as_admin! user = User.find_by(id: params.delete(:id)) - not_found!('User') unless user + not_found!("User") unless user key = user.keys.new(declared_params(include_missing: false)) @@ -254,57 +254,57 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get the SSH keys of a specified user.' do + desc "Get the SSH keys of a specified user." do success Entities::SSHKey end params do - requires :id, type: Integer, desc: 'The ID of the user' + requires :id, type: Integer, desc: "The ID of the user" use :pagination end # rubocop: disable CodeReuse/ActiveRecord - get ':id/keys' do + get ":id/keys" do user = User.find_by(id: params[:id]) - not_found!('User') unless user && can?(current_user, :read_user, user) + not_found!("User") unless user && can?(current_user, :read_user, user) present paginate(user.keys), with: Entities::SSHKey end # rubocop: enable CodeReuse/ActiveRecord - desc 'Delete an existing SSH key from a specified user. Available only for admins.' do + desc "Delete an existing SSH key from a specified user. Available only for admins." do success Entities::SSHKey end params do - requires :id, type: Integer, desc: 'The ID of the user' - requires :key_id, type: Integer, desc: 'The ID of the SSH key' + requires :id, type: Integer, desc: "The ID of the user" + requires :key_id, type: Integer, desc: "The ID of the SSH key" end # rubocop: disable CodeReuse/ActiveRecord - delete ':id/keys/:key_id' do + delete ":id/keys/:key_id" do authenticated_as_admin! user = User.find_by(id: params[:id]) - not_found!('User') unless user + not_found!("User") unless user key = user.keys.find_by(id: params[:key_id]) - not_found!('Key') unless key + not_found!("Key") unless key destroy_conditionally!(key) end # rubocop: enable CodeReuse/ActiveRecord - desc 'Add a GPG key to a specified user. Available only for admins.' do - detail 'This feature was added in GitLab 10.0' + desc "Add a GPG key to a specified user. Available only for admins." do + detail "This feature was added in GitLab 10.0" success Entities::GPGKey end params do - requires :id, type: Integer, desc: 'The ID of the user' - requires :key, type: String, desc: 'The new GPG key' + requires :id, type: Integer, desc: "The ID of the user" + requires :key, type: String, desc: "The new GPG key" end # rubocop: disable CodeReuse/ActiveRecord - post ':id/gpg_keys' do + post ":id/gpg_keys" do authenticated_as_admin! user = User.find_by(id: params.delete(:id)) - not_found!('User') unless user + not_found!("User") unless user key = user.gpg_keys.new(declared_params(include_missing: false)) @@ -316,83 +316,83 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get the GPG keys of a specified user. Available only for admins.' do - detail 'This feature was added in GitLab 10.0' + desc "Get the GPG keys of a specified user. Available only for admins." do + detail "This feature was added in GitLab 10.0" success Entities::GPGKey end params do - requires :id, type: Integer, desc: 'The ID of the user' + requires :id, type: Integer, desc: "The ID of the user" use :pagination end # rubocop: disable CodeReuse/ActiveRecord - get ':id/gpg_keys' do + get ":id/gpg_keys" do authenticated_as_admin! user = User.find_by(id: params[:id]) - not_found!('User') unless user + not_found!("User") unless user present paginate(user.gpg_keys), with: Entities::GPGKey end # rubocop: enable CodeReuse/ActiveRecord - desc 'Delete an existing GPG key from a specified user. Available only for admins.' do - detail 'This feature was added in GitLab 10.0' + desc "Delete an existing GPG key from a specified user. Available only for admins." do + detail "This feature was added in GitLab 10.0" end params do - requires :id, type: Integer, desc: 'The ID of the user' - requires :key_id, type: Integer, desc: 'The ID of the GPG key' + requires :id, type: Integer, desc: "The ID of the user" + requires :key_id, type: Integer, desc: "The ID of the GPG key" end # rubocop: disable CodeReuse/ActiveRecord - delete ':id/gpg_keys/:key_id' do + delete ":id/gpg_keys/:key_id" do authenticated_as_admin! user = User.find_by(id: params[:id]) - not_found!('User') unless user + not_found!("User") unless user key = user.gpg_keys.find_by(id: params[:key_id]) - not_found!('GPG Key') unless key + not_found!("GPG Key") unless key status 204 key.destroy end # rubocop: enable CodeReuse/ActiveRecord - desc 'Revokes an existing GPG key from a specified user. Available only for admins.' do - detail 'This feature was added in GitLab 10.0' + desc "Revokes an existing GPG key from a specified user. Available only for admins." do + detail "This feature was added in GitLab 10.0" end params do - requires :id, type: Integer, desc: 'The ID of the user' - requires :key_id, type: Integer, desc: 'The ID of the GPG key' + requires :id, type: Integer, desc: "The ID of the user" + requires :key_id, type: Integer, desc: "The ID of the GPG key" end # rubocop: disable CodeReuse/ActiveRecord - post ':id/gpg_keys/:key_id/revoke' do + post ":id/gpg_keys/:key_id/revoke" do authenticated_as_admin! user = User.find_by(id: params[:id]) - not_found!('User') unless user + not_found!("User") unless user key = user.gpg_keys.find_by(id: params[:key_id]) - not_found!('GPG Key') unless key + not_found!("GPG Key") unless key key.revoke status :accepted end # rubocop: enable CodeReuse/ActiveRecord - desc 'Add an email address to a specified user. Available only for admins.' do + desc "Add an email address to a specified user. Available only for admins." do success Entities::Email end params do - requires :id, type: Integer, desc: 'The ID of the user' - requires :email, type: String, desc: 'The email of the user' - optional :skip_confirmation, type: Boolean, desc: 'Skip confirmation of email and assume it is verified' + requires :id, type: Integer, desc: "The ID of the user" + requires :email, type: String, desc: "The email of the user" + optional :skip_confirmation, type: Boolean, desc: "Skip confirmation of email and assume it is verified" end # rubocop: disable CodeReuse/ActiveRecord post ":id/emails" do authenticated_as_admin! user = User.find_by(id: params.delete(:id)) - not_found!('User') unless user + not_found!("User") unless user email = Emails::CreateService.new(current_user, declared_params(include_missing: false).merge(user: user)).execute @@ -404,38 +404,38 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get the emails addresses of a specified user. Available only for admins.' do + desc "Get the emails addresses of a specified user. Available only for admins." do success Entities::Email end params do - requires :id, type: Integer, desc: 'The ID of the user' + requires :id, type: Integer, desc: "The ID of the user" use :pagination end # rubocop: disable CodeReuse/ActiveRecord - get ':id/emails' do + get ":id/emails" do authenticated_as_admin! user = User.find_by(id: params[:id]) - not_found!('User') unless user + not_found!("User") unless user present paginate(user.emails), with: Entities::Email end # rubocop: enable CodeReuse/ActiveRecord - desc 'Delete an email address of a specified user. Available only for admins.' do + desc "Delete an email address of a specified user. Available only for admins." do success Entities::Email end params do - requires :id, type: Integer, desc: 'The ID of the user' - requires :email_id, type: Integer, desc: 'The ID of the email' + requires :id, type: Integer, desc: "The ID of the user" + requires :email_id, type: Integer, desc: "The ID of the email" end # rubocop: disable CodeReuse/ActiveRecord - delete ':id/emails/:email_id' do + delete ":id/emails/:email_id" do authenticated_as_admin! user = User.find_by(id: params[:id]) - not_found!('User') unless user + not_found!("User") unless user email = user.emails.find_by(id: params[:email_id]) - not_found!('Email') unless email + not_found!("Email") unless email destroy_conditionally!(email) do |email| Emails::DestroyService.new(current_user, user: user).execute(email) @@ -443,21 +443,21 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Delete a user. Available only for admins.' do + desc "Delete a user. Available only for admins." do success Entities::Email end params do - requires :id, type: Integer, desc: 'The ID of the user' + requires :id, type: Integer, desc: "The ID of the user" optional :hard_delete, type: Boolean, desc: "Whether to remove a user's contributions" end # rubocop: disable CodeReuse/ActiveRecord delete ":id" do - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42279') + Gitlab::QueryLimiting.whitelist("https://gitlab.com/gitlab-org/gitlab-ce/issues/42279") authenticated_as_admin! user = User.find_by(id: params[:id]) - not_found!('User') unless user + not_found!("User") unless user destroy_conditionally!(user) do user.delete_async(deleted_by: current_user, params: params) @@ -465,36 +465,36 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Block a user. Available only for admins.' + desc "Block a user. Available only for admins." params do - requires :id, type: Integer, desc: 'The ID of the user' + requires :id, type: Integer, desc: "The ID of the user" end # rubocop: disable CodeReuse/ActiveRecord - post ':id/block' do + post ":id/block" do authenticated_as_admin! user = User.find_by(id: params[:id]) - not_found!('User') unless user + not_found!("User") unless user if !user.ldap_blocked? user.block else - forbidden!('LDAP blocked users cannot be modified by the API') + forbidden!("LDAP blocked users cannot be modified by the API") end end # rubocop: enable CodeReuse/ActiveRecord - desc 'Unblock a user. Available only for admins.' + desc "Unblock a user. Available only for admins." params do - requires :id, type: Integer, desc: 'The ID of the user' + requires :id, type: Integer, desc: "The ID of the user" end # rubocop: disable CodeReuse/ActiveRecord - post ':id/unblock' do + post ":id/unblock" do authenticated_as_admin! user = User.find_by(id: params[:id]) - not_found!('User') unless user + not_found!("User") unless user if user.ldap_blocked? - forbidden!('LDAP blocked users cannot be unblocked by the API') + forbidden!("LDAP blocked users cannot be unblocked by the API") else user.activate end @@ -502,41 +502,41 @@ module API # rubocop: enable CodeReuse/ActiveRecord params do - requires :user_id, type: Integer, desc: 'The ID of the user' + requires :user_id, type: Integer, desc: "The ID of the user" end - segment ':user_id' do + segment ":user_id" do resource :impersonation_tokens do helpers do def finder(options = {}) user = find_user_by_id(params) - PersonalAccessTokensFinder.new({ user: user, impersonation: true }.merge(options)) + PersonalAccessTokensFinder.new({user: user, impersonation: true}.merge(options)) end def find_impersonation_token - finder.find_by_id(declared_params[:impersonation_token_id]) || not_found!('Impersonation Token') + finder.find_by_id(declared_params[:impersonation_token_id]) || not_found!("Impersonation Token") end end before { authenticated_as_admin! } - desc 'Retrieve impersonation tokens. Available only for admins.' do - detail 'This feature was introduced in GitLab 9.0' + desc "Retrieve impersonation tokens. Available only for admins." do + detail "This feature was introduced in GitLab 9.0" success Entities::ImpersonationToken end params do use :pagination - optional :state, type: String, default: 'all', values: %w[all active inactive], desc: 'Filters (all|active|inactive) impersonation_tokens' + optional :state, type: String, default: "all", values: %w[all active inactive], desc: "Filters (all|active|inactive) impersonation_tokens" end get { present paginate(finder(declared_params(include_missing: false)).execute), with: Entities::ImpersonationToken } - desc 'Create a impersonation token. Available only for admins.' do - detail 'This feature was introduced in GitLab 9.0' + desc "Create a impersonation token. Available only for admins." do + detail "This feature was introduced in GitLab 9.0" success Entities::ImpersonationTokenWithToken end params do - requires :name, type: String, desc: 'The name of the impersonation token' - optional :expires_at, type: Date, desc: 'The expiration date in the format YEAR-MONTH-DAY of the impersonation token' - optional :scopes, type: Array, desc: 'The array of scopes of the impersonation token' + requires :name, type: String, desc: "The name of the impersonation token" + optional :expires_at, type: Date, desc: "The expiration date in the format YEAR-MONTH-DAY of the impersonation token" + optional :scopes, type: Array, desc: "The array of scopes of the impersonation token" end post do impersonation_token = finder.build(declared_params(include_missing: false)) @@ -548,24 +548,24 @@ module API end end - desc 'Retrieve impersonation token. Available only for admins.' do - detail 'This feature was introduced in GitLab 9.0' + desc "Retrieve impersonation token. Available only for admins." do + detail "This feature was introduced in GitLab 9.0" success Entities::ImpersonationToken end params do - requires :impersonation_token_id, type: Integer, desc: 'The ID of the impersonation token' + requires :impersonation_token_id, type: Integer, desc: "The ID of the impersonation token" end - get ':impersonation_token_id' do + get ":impersonation_token_id" do present find_impersonation_token, with: Entities::ImpersonationToken end - desc 'Revoke a impersonation token. Available only for admins.' do - detail 'This feature was introduced in GitLab 9.0' + desc "Revoke a impersonation token. Available only for admins." do + detail "This feature was introduced in GitLab 9.0" end params do - requires :impersonation_token_id, type: Integer, desc: 'The ID of the impersonation token' + requires :impersonation_token_id, type: Integer, desc: "The ID of the impersonation token" end - delete ':impersonation_token_id' do + delete ":impersonation_token_id" do token = find_impersonation_token destroy_conditionally!(token) do @@ -583,8 +583,8 @@ module API # Enabling /user endpoint for the v3 version to allow oauth # authentication through this endpoint. - version %w(v3 v4), using: :path do - desc 'Get the currently authenticated user' do + version %w[v3 v4], using: :path do + desc "Get the currently authenticated user" do success Entities::UserPublic end get do @@ -609,27 +609,27 @@ module API present paginate(current_user.keys), with: Entities::SSHKey end - desc 'Get a single key owned by currently authenticated user' do + desc "Get a single key owned by currently authenticated user" do success Entities::SSHKey end params do - requires :key_id, type: Integer, desc: 'The ID of the SSH key' + requires :key_id, type: Integer, desc: "The ID of the SSH key" end # rubocop: disable CodeReuse/ActiveRecord get "keys/:key_id" do key = current_user.keys.find_by(id: params[:key_id]) - not_found!('Key') unless key + not_found!("Key") unless key present key, with: Entities::SSHKey end # rubocop: enable CodeReuse/ActiveRecord - desc 'Add a new SSH key to the currently authenticated user' do + desc "Add a new SSH key to the currently authenticated user" do success Entities::SSHKey end params do - requires :key, type: String, desc: 'The new SSH key' - requires :title, type: String, desc: 'The title of the new SSH key' + requires :key, type: String, desc: "The new SSH key" + requires :title, type: String, desc: "The title of the new SSH key" end post "keys" do key = current_user.keys.new(declared_params) @@ -641,56 +641,56 @@ module API end end - desc 'Delete an SSH key from the currently authenticated user' do + desc "Delete an SSH key from the currently authenticated user" do success Entities::SSHKey end params do - requires :key_id, type: Integer, desc: 'The ID of the SSH key' + requires :key_id, type: Integer, desc: "The ID of the SSH key" end # rubocop: disable CodeReuse/ActiveRecord delete "keys/:key_id" do key = current_user.keys.find_by(id: params[:key_id]) - not_found!('Key') unless key + not_found!("Key") unless key destroy_conditionally!(key) end # rubocop: enable CodeReuse/ActiveRecord desc "Get the currently authenticated user's GPG keys" do - detail 'This feature was added in GitLab 10.0' + detail "This feature was added in GitLab 10.0" success Entities::GPGKey end params do use :pagination end - get 'gpg_keys' do + get "gpg_keys" do present paginate(current_user.gpg_keys), with: Entities::GPGKey end - desc 'Get a single GPG key owned by currently authenticated user' do - detail 'This feature was added in GitLab 10.0' + desc "Get a single GPG key owned by currently authenticated user" do + detail "This feature was added in GitLab 10.0" success Entities::GPGKey end params do - requires :key_id, type: Integer, desc: 'The ID of the GPG key' + requires :key_id, type: Integer, desc: "The ID of the GPG key" end # rubocop: disable CodeReuse/ActiveRecord - get 'gpg_keys/:key_id' do + get "gpg_keys/:key_id" do key = current_user.gpg_keys.find_by(id: params[:key_id]) - not_found!('GPG Key') unless key + not_found!("GPG Key") unless key present key, with: Entities::GPGKey end # rubocop: enable CodeReuse/ActiveRecord - desc 'Add a new GPG key to the currently authenticated user' do - detail 'This feature was added in GitLab 10.0' + desc "Add a new GPG key to the currently authenticated user" do + detail "This feature was added in GitLab 10.0" success Entities::GPGKey end params do - requires :key, type: String, desc: 'The new GPG key' + requires :key, type: String, desc: "The new GPG key" end - post 'gpg_keys' do + post "gpg_keys" do key = current_user.gpg_keys.new(declared_params) if key.save @@ -700,32 +700,32 @@ module API end end - desc 'Revoke a GPG key owned by currently authenticated user' do - detail 'This feature was added in GitLab 10.0' + desc "Revoke a GPG key owned by currently authenticated user" do + detail "This feature was added in GitLab 10.0" end params do - requires :key_id, type: Integer, desc: 'The ID of the GPG key' + requires :key_id, type: Integer, desc: "The ID of the GPG key" end # rubocop: disable CodeReuse/ActiveRecord - post 'gpg_keys/:key_id/revoke' do + post "gpg_keys/:key_id/revoke" do key = current_user.gpg_keys.find_by(id: params[:key_id]) - not_found!('GPG Key') unless key + not_found!("GPG Key") unless key key.revoke status :accepted end # rubocop: enable CodeReuse/ActiveRecord - desc 'Delete a GPG key from the currently authenticated user' do - detail 'This feature was added in GitLab 10.0' + desc "Delete a GPG key from the currently authenticated user" do + detail "This feature was added in GitLab 10.0" end params do - requires :key_id, type: Integer, desc: 'The ID of the SSH key' + requires :key_id, type: Integer, desc: "The ID of the SSH key" end # rubocop: disable CodeReuse/ActiveRecord - delete 'gpg_keys/:key_id' do + delete "gpg_keys/:key_id" do key = current_user.gpg_keys.find_by(id: params[:key_id]) - not_found!('GPG Key') unless key + not_found!("GPG Key") unless key status 204 key.destroy @@ -742,26 +742,26 @@ module API present paginate(current_user.emails), with: Entities::Email end - desc 'Get a single email address owned by the currently authenticated user' do + desc "Get a single email address owned by the currently authenticated user" do success Entities::Email end params do - requires :email_id, type: Integer, desc: 'The ID of the email' + requires :email_id, type: Integer, desc: "The ID of the email" end # rubocop: disable CodeReuse/ActiveRecord get "emails/:email_id" do email = current_user.emails.find_by(id: params[:email_id]) - not_found!('Email') unless email + not_found!("Email") unless email present email, with: Entities::Email end # rubocop: enable CodeReuse/ActiveRecord - desc 'Add new email address to the currently authenticated user' do + desc "Add new email address to the currently authenticated user" do success Entities::Email end params do - requires :email, type: String, desc: 'The new email' + requires :email, type: String, desc: "The new email" end post "emails" do email = Emails::CreateService.new(current_user, declared_params.merge(user: current_user)).execute @@ -773,14 +773,14 @@ module API end end - desc 'Delete an email address from the currently authenticated user' + desc "Delete an email address from the currently authenticated user" params do - requires :email_id, type: Integer, desc: 'The ID of the email' + requires :email_id, type: Integer, desc: "The ID of the email" end # rubocop: disable CodeReuse/ActiveRecord delete "emails/:email_id" do email = current_user.emails.find_by(id: params[:email_id]) - not_found!('Email') unless email + not_found!("Email") unless email destroy_conditionally!(email) do |email| Emails::DestroyService.new(current_user, user: current_user).execute(email) @@ -788,9 +788,9 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Get a list of user activities' + desc "Get a list of user activities" params do - optional :from, type: DateTime, default: 6.months.ago, desc: 'Date string in the format YEAR-MONTH-DAY' + optional :from, type: DateTime, default: 6.months.ago, desc: "Date string in the format YEAR-MONTH-DAY" use :pagination end # rubocop: disable CodeReuse/ActiveRecord @@ -805,7 +805,7 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Set the status of the current user' do + desc "Set the status of the current user" do success Entities::UserStatus end params do @@ -822,10 +822,10 @@ module API end end - desc 'get the status of the current user' do + desc "get the status of the current user" do success Entities::UserStatus end - get 'status' do + get "status" do present current_user.status || {}, with: Entities::UserStatus end end diff --git a/lib/api/variables.rb b/lib/api/variables.rb index 148deb86c4c..2972125085a 100644 --- a/lib/api/variables.rb +++ b/lib/api/variables.rb @@ -8,47 +8,47 @@ module API before { authorize! :admin_build, user_project } params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get project variables' do + desc "Get project variables" do success Entities::Variable end params do use :pagination end - get ':id/variables' do + get ":id/variables" do variables = user_project.variables present paginate(variables), with: Entities::Variable end - desc 'Get a specific variable from a project' do + desc "Get a specific variable from a project" do success Entities::Variable end params do - requires :key, type: String, desc: 'The key of the variable' + requires :key, type: String, desc: "The key of the variable" end # rubocop: disable CodeReuse/ActiveRecord - get ':id/variables/:key' do + get ":id/variables/:key" do key = params[:key] variable = user_project.variables.find_by(key: key) - break not_found!('Variable') unless variable + break not_found!("Variable") unless variable present variable, with: Entities::Variable end # rubocop: enable CodeReuse/ActiveRecord - desc 'Create a new variable in a project' do + desc "Create a new variable in a project" do success Entities::Variable end params do - requires :key, type: String, desc: 'The key of the variable' - requires :value, type: String, desc: 'The value of the variable' - optional :protected, type: String, desc: 'Whether the variable is protected' + requires :key, type: String, desc: "The key of the variable" + requires :value, type: String, desc: "The value of the variable" + optional :protected, type: String, desc: "Whether the variable is protected" end - post ':id/variables' do + post ":id/variables" do variable_params = declared_params(include_missing: false) variable = user_project.variables.create(variable_params) @@ -60,19 +60,19 @@ module API end end - desc 'Update an existing variable from a project' do + desc "Update an existing variable from a project" do success Entities::Variable end params do - optional :key, type: String, desc: 'The key of the variable' - optional :value, type: String, desc: 'The value of the variable' - optional :protected, type: String, desc: 'Whether the variable is protected' + optional :key, type: String, desc: "The key of the variable" + optional :value, type: String, desc: "The value of the variable" + optional :protected, type: String, desc: "Whether the variable is protected" end # rubocop: disable CodeReuse/ActiveRecord - put ':id/variables/:key' do + put ":id/variables/:key" do variable = user_project.variables.find_by(key: params[:key]) - break not_found!('Variable') unless variable + break not_found!("Variable") unless variable variable_params = declared_params(include_missing: false).except(:key) @@ -84,16 +84,16 @@ module API end # rubocop: enable CodeReuse/ActiveRecord - desc 'Delete an existing variable from a project' do + desc "Delete an existing variable from a project" do success Entities::Variable end params do - requires :key, type: String, desc: 'The key of the variable' + requires :key, type: String, desc: "The key of the variable" end # rubocop: disable CodeReuse/ActiveRecord - delete ':id/variables/:key' do + delete ":id/variables/:key" do variable = user_project.variables.find_by(key: params[:key]) - not_found!('Variable') unless variable + not_found!("Variable") unless variable # Variables don't have any timestamp. Therfore, destroy unconditionally. status 204 diff --git a/lib/api/version.rb b/lib/api/version.rb index 74cd857f447..e770153caf7 100644 --- a/lib/api/version.rb +++ b/lib/api/version.rb @@ -4,11 +4,11 @@ module API class Version < Grape::API before { authenticate! } - desc 'Get the version information of the GitLab instance.' do - detail 'This feature was introduced in GitLab 8.13.' + desc "Get the version information of the GitLab instance." do + detail "This feature was introduced in GitLab 8.13." end - get '/version' do - { version: Gitlab::VERSION, revision: Gitlab.revision } + get "/version" do + {version: Gitlab::VERSION, revision: Gitlab.revision} end end end diff --git a/lib/api/wikis.rb b/lib/api/wikis.rb index 994074ddc67..9dd7916c480 100644 --- a/lib/api/wikis.rb +++ b/lib/api/wikis.rb @@ -7,7 +7,7 @@ module API { file_name: attrs[:file][:filename], file_content: attrs[:file][:tempfile].read, - branch_name: attrs[:branch] + branch_name: attrs[:branch], } end @@ -15,48 +15,48 @@ module API optional :format, type: String, values: ProjectWiki::MARKUPS.values.map(&:to_s), - default: 'markdown', - desc: 'Format of a wiki page. Available formats are markdown, rdoc, and asciidoc' + default: "markdown", + desc: "Format of a wiki page. Available formats are markdown, rdoc, and asciidoc" end end WIKI_ENDPOINT_REQUIREMENTS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS.merge(slug: API::NO_SLASH_URL_PART_REGEX) resource :projects, requirements: WIKI_ENDPOINT_REQUIREMENTS do - desc 'Get a list of wiki pages' do + desc "Get a list of wiki pages" do success Entities::WikiPageBasic end params do optional :with_content, type: Boolean, default: false, desc: "Include pages' content" end - get ':id/wikis' do + get ":id/wikis" do authorize! :read_wiki, user_project entity = params[:with_content] ? Entities::WikiPage : Entities::WikiPageBasic present user_project.wiki.pages, with: entity end - desc 'Get a wiki page' do + desc "Get a wiki page" do success Entities::WikiPage end params do - requires :slug, type: String, desc: 'The slug of a wiki page' + requires :slug, type: String, desc: "The slug of a wiki page" end - get ':id/wikis/:slug' do + get ":id/wikis/:slug" do authorize! :read_wiki, user_project present wiki_page, with: Entities::WikiPage end - desc 'Create a wiki page' do + desc "Create a wiki page" do success Entities::WikiPage end params do - requires :title, type: String, desc: 'Title of a wiki page' - requires :content, type: String, desc: 'Content of a wiki page' + requires :title, type: String, desc: "Title of a wiki page" + requires :content, type: String, desc: "Content of a wiki page" use :common_wiki_page_params end - post ':id/wikis' do + post ":id/wikis" do authorize! :create_wiki, user_project page = WikiPages::CreateService.new(user_project, current_user, params).execute @@ -68,16 +68,16 @@ module API end end - desc 'Update a wiki page' do + desc "Update a wiki page" do success Entities::WikiPage end params do - optional :title, type: String, desc: 'Title of a wiki page' - optional :content, type: String, desc: 'Content of a wiki page' + optional :title, type: String, desc: "Title of a wiki page" + optional :content, type: String, desc: "Content of a wiki page" use :common_wiki_page_params at_least_one_of :content, :title, :format end - put ':id/wikis/:slug' do + put ":id/wikis/:slug" do authorize! :create_wiki, user_project page = WikiPages::UpdateService.new(user_project, current_user, params).execute(wiki_page) @@ -89,31 +89,31 @@ module API end end - desc 'Delete a wiki page' + desc "Delete a wiki page" params do - requires :slug, type: String, desc: 'The slug of a wiki page' + requires :slug, type: String, desc: "The slug of a wiki page" end - delete ':id/wikis/:slug' do + delete ":id/wikis/:slug" do authorize! :admin_wiki, user_project status 204 WikiPages::DestroyService.new(user_project, current_user).execute(wiki_page) end - desc 'Upload an attachment to the wiki repository' do - detail 'This feature was introduced in GitLab 11.3.' + desc "Upload an attachment to the wiki repository" do + detail "This feature was introduced in GitLab 11.3." success Entities::WikiAttachment end params do - requires :file, type: ::API::Validations::Types::SafeFile, desc: 'The attachment file to be uploaded' - optional :branch, type: String, desc: 'The name of the branch' + requires :file, type: ::API::Validations::Types::SafeFile, desc: "The attachment file to be uploaded" + optional :branch, type: String, desc: "The name of the branch" end post ":id/wikis/attachments" do authorize! :create_wiki, user_project result = ::Wikis::CreateAttachmentService.new(user_project, - current_user, - commit_params(declared_params(include_missing: false))).execute + current_user, + commit_params(declared_params(include_missing: false))).execute if result[:status] == :success status(201) |