Commit 3836d691 authored by gfyoung's avatar gfyoung

Enable frozen string in lib/api and lib/backup

Partially addresses #47424.

Had to make changes to spec files because
stubbing methods on frozen objects is a mess
in RSpec and leads to failures:

https://github.com/rspec/rspec-mocks/issues/1190
parent 227cc997
---
title: Enable frozen string in lib/api and lib/backup
merge_request:
author: gfyoung
type: performance
# frozen_string_literal: true
module API module API
class AccessRequests < Grape::API class AccessRequests < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class API < Grape::API class API < Grape::API
include APIGuard include APIGuard
......
# frozen_string_literal: true
# Guard API with OAuth 2.0 Access Token # Guard API with OAuth 2.0 Access Token
require 'rack/oauth2' require 'rack/oauth2'
......
# frozen_string_literal: true
module API module API
# External applications API # External applications API
class Applications < Grape::API class Applications < Grape::API
......
# frozen_string_literal: true
module API module API
class Avatar < Grape::API class Avatar < Grape::API
resource :avatar do resource :avatar do
......
# frozen_string_literal: true
module API module API
class AwardEmoji < Grape::API class AwardEmoji < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class Badges < Grape::API class Badges < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class Boards < Grape::API class Boards < Grape::API
include BoardsResponses include BoardsResponses
......
# frozen_string_literal: true
module API module API
module BoardsResponses module BoardsResponses
extend ActiveSupport::Concern extend ActiveSupport::Concern
......
# frozen_string_literal: true
require 'mime/types' require 'mime/types'
module API module API
......
# frozen_string_literal: true
module API module API
class BroadcastMessages < Grape::API class BroadcastMessages < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class CircuitBreakers < Grape::API class CircuitBreakers < Grape::API
before { authenticated_as_admin! } before { authenticated_as_admin! }
......
# frozen_string_literal: true
require 'mime/types' require 'mime/types'
module API module API
......
# frozen_string_literal: true
require 'mime/types' require 'mime/types'
module API module API
......
# frozen_string_literal: true
module API module API
module CustomAttributesEndpoints module CustomAttributesEndpoints
extend ActiveSupport::Concern extend ActiveSupport::Concern
......
# frozen_string_literal: true
module API module API
class DeployKeys < Grape::API class DeployKeys < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
# Deployments RESTful API endpoints # Deployments RESTful API endpoints
class Deployments < Grape::API class Deployments < Grape::API
......
# frozen_string_literal: true
module API module API
class Discussions < Grape::API class Discussions < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
module Entities module Entities
class WikiPageBasic < Grape::Entity class WikiPageBasic < Grape::Entity
......
# frozen_string_literal: true
module API module API
# Environments RESTfull API endpoints # Environments RESTfull API endpoints
class Environments < Grape::API class Environments < Grape::API
......
# frozen_string_literal: true
module API module API
class Events < Grape::API class Events < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class Features < Grape::API class Features < Grape::API
before { authenticated_as_admin! } before { authenticated_as_admin! }
......
# frozen_string_literal: true
module API module API
class Files < Grape::API class Files < Grape::API
FILE_ENDPOINT_REQUIREMENTS = API::PROJECT_ENDPOINT_REQUIREMENTS.merge(file_path: API::NO_SLASH_URL_PART_REGEX) FILE_ENDPOINT_REQUIREMENTS = API::PROJECT_ENDPOINT_REQUIREMENTS.merge(file_path: API::NO_SLASH_URL_PART_REGEX)
......
# frozen_string_literal: true
module API module API
class GroupBoards < Grape::API class GroupBoards < Grape::API
include BoardsResponses include BoardsResponses
......
# frozen_string_literal: true
module API module API
class GroupMilestones < Grape::API class GroupMilestones < Grape::API
include MilestoneResponses include MilestoneResponses
......
# frozen_string_literal: true
module API module API
class GroupVariables < Grape::API class GroupVariables < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class Groups < Grape::API class Groups < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
module Helpers module Helpers
include Gitlab::Utils include Gitlab::Utils
...@@ -381,9 +383,10 @@ module API ...@@ -381,9 +383,10 @@ module API
# lifted from https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L60 # lifted from https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L60
trace = exception.backtrace trace = exception.backtrace
message = "\n#{exception.class} (#{exception.message}):\n" message = ["\n#{exception.class} (#{exception.message}):\n"]
message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code) message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
message << " " << trace.join("\n ") message << " " << trace.join("\n ")
message = message.join
API.logger.add Logger::FATAL, message API.logger.add Logger::FATAL, message
......
# frozen_string_literal: true
module API module API
module Helpers module Helpers
module BadgesHelpers module BadgesHelpers
......
# frozen_string_literal: true
module API module API
module Helpers module Helpers
module CommonHelpers module CommonHelpers
......
# frozen_string_literal: true
module API module API
module Helpers module Helpers
module CustomAttributes module CustomAttributes
......
# frozen_string_literal: true
module API module API
module Helpers module Helpers
module CustomValidators module CustomValidators
......
# frozen_string_literal: true
module API module API
module Helpers module Helpers
module HeadersHelpers module HeadersHelpers
......
# frozen_string_literal: true
module API module API
module Helpers module Helpers
module InternalHelpers module InternalHelpers
......
# frozen_string_literal: true
# rubocop:disable GitlabSecurity/PublicSend # rubocop:disable GitlabSecurity/PublicSend
module API module API
......
# frozen_string_literal: true
module API module API
module Helpers module Helpers
module NotesHelpers module NotesHelpers
......
# frozen_string_literal: true
module API module API
module Helpers module Helpers
module Pagination module Pagination
......
# frozen_string_literal: true
module API module API
module Helpers module Helpers
module ProjectSnapshotsHelpers module ProjectSnapshotsHelpers
......
# frozen_string_literal: true
module API module API
module Helpers module Helpers
module ProjectsHelpers module ProjectsHelpers
......
# frozen_string_literal: true
module API module API
module Helpers module Helpers
module RelatedResourcesHelpers module RelatedResourcesHelpers
......
# frozen_string_literal: true
module API module API
module Helpers module Helpers
module Runner module Runner
......
# frozen_string_literal: true
module API module API
# Internal access API # Internal access API
class Internal < Grape::API class Internal < Grape::API
......
# frozen_string_literal: true
module API module API
class Issues < Grape::API class Issues < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class JobArtifacts < Grape::API class JobArtifacts < Grape::API
before { authenticate_non_get! } before { authenticate_non_get! }
......
# frozen_string_literal: true
module API module API
class Jobs < Grape::API class Jobs < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
# Keys API # Keys API
class Keys < Grape::API class Keys < Grape::API
......
# frozen_string_literal: true
module API module API
class Labels < Grape::API class Labels < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class Lint < Grape::API class Lint < Grape::API
namespace :ci do namespace :ci do
......
# frozen_string_literal: true
module API module API
class Markdown < Grape::API class Markdown < Grape::API
params do params do
......
# frozen_string_literal: true
module API module API
class Members < Grape::API class Members < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
# MergeRequestDiff API # MergeRequestDiff API
class MergeRequestDiffs < Grape::API class MergeRequestDiffs < Grape::API
......
# frozen_string_literal: true
module API module API
class MergeRequests < Grape::API class MergeRequests < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
module MilestoneResponses module MilestoneResponses
extend ActiveSupport::Concern extend ActiveSupport::Concern
......
# frozen_string_literal: true
module API module API
class Namespaces < Grape::API class Namespaces < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class Notes < Grape::API class Notes < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
# notification_settings API # notification_settings API
class NotificationSettings < Grape::API class NotificationSettings < Grape::API
......
# frozen_string_literal: true
module API module API
class PagesDomains < Grape::API class PagesDomains < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
# Concern for declare pagination params. # Concern for declare pagination params.
# #
......
# frozen_string_literal: true
module API module API
class PipelineSchedules < Grape::API class PipelineSchedules < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class Pipelines < Grape::API class Pipelines < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class ProjectExport < Grape::API class ProjectExport < Grape::API
before do before do
......
# frozen_string_literal: true
module API module API
class ProjectHooks < Grape::API class ProjectHooks < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class ProjectImport < Grape::API class ProjectImport < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class ProjectMilestones < Grape::API class ProjectMilestones < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class ProjectSnapshots < Grape::API class ProjectSnapshots < Grape::API
helpers ::API::Helpers::ProjectSnapshotsHelpers helpers ::API::Helpers::ProjectSnapshotsHelpers
......
# frozen_string_literal: true
module API module API
class ProjectSnippets < Grape::API class ProjectSnippets < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
require_dependency 'declarative_policy' require_dependency 'declarative_policy'
module API module API
......
# frozen_string_literal: true
module API module API
module ProjectsRelationBuilder module ProjectsRelationBuilder
extend ActiveSupport::Concern extend ActiveSupport::Concern
......
# frozen_string_literal: true
module API module API
class ProtectedBranches < Grape::API class ProtectedBranches < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class ProtectedTags < Grape::API class ProtectedTags < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
require 'mime/types' require 'mime/types'
module API module API
......
# frozen_string_literal: true
module API module API
class Runner < Grape::API class Runner < Grape::API
helpers ::API::Helpers::Runner helpers ::API::Helpers::Runner
......
# frozen_string_literal: true
module API module API
class Runners < Grape::API class Runners < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
# Encapsulate a scope used for authorization, such as `api`, or `read_user` # Encapsulate a scope used for authorization, such as `api`, or `read_user`
module API module API
class Scope class Scope
......
# frozen_string_literal: true
module API module API
class Search < Grape::API class Search < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class Settings < Grape::API class Settings < Grape::API
before { authenticated_as_admin! } before { authenticated_as_admin! }
......
# frozen_string_literal: true
require 'sidekiq/api' require 'sidekiq/api'
module API module API
......
# frozen_string_literal: true
module API module API
# Snippets API # Snippets API
class Snippets < Grape::API class Snippets < Grape::API
......
# frozen_string_literal: true
module API module API
class Subscriptions < Grape::API class Subscriptions < Grape::API
before { authenticate! } before { authenticate! }
......
# frozen_string_literal: true
module API module API
class SystemHooks < Grape::API class SystemHooks < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class Tags < Grape::API class Tags < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class Templates < Grape::API class Templates < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
module TimeTrackingEndpoints module TimeTrackingEndpoints
extend ActiveSupport::Concern extend ActiveSupport::Concern
......
# frozen_string_literal: true
module API module API
class Todos < Grape::API class Todos < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class Triggers < Grape::API class Triggers < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class Users < Grape::API class Users < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class Variables < Grape::API class Variables < Grape::API
include PaginationParams include PaginationParams
......
# frozen_string_literal: true
module API module API
class Version < Grape::API class Version < Grape::API
before { authenticate! } before { authenticate! }
......
# frozen_string_literal: true
module API module API
class Wikis < Grape::API class Wikis < Grape::API
helpers do helpers do
......
# frozen_string_literal: true
require 'backup/files' require 'backup/files'
module Backup module Backup
......
# frozen_string_literal: true
require 'backup/files' require 'backup/files'
module Backup module Backup
......
# frozen_string_literal: true
require 'yaml' require 'yaml'
module Backup module Backup
......
# frozen_string_literal: true
require 'open3' require 'open3'
require_relative 'helper' require_relative 'helper'
......
# frozen_string_literal: true
module Backup module Backup
module Helper module Helper
def access_denied_error(path) def access_denied_error(path)
......
# frozen_string_literal: true
require 'backup/files' require 'backup/files'
module Backup module Backup
......
# frozen_string_literal: true
module Backup module Backup
class Manager class Manager
ARCHIVES_TO_BACKUP = %w[uploads builds artifacts pages lfs registry].freeze ARCHIVES_TO_BACKUP = %w[uploads builds artifacts pages lfs registry].freeze
......
# frozen_string_literal: true
require 'backup/files' require 'backup/files'
module Backup module Backup
......
# frozen_string_literal: true
require 'backup/files' require 'backup/files'
module Backup module Backup
......
# frozen_string_literal: true
require 'yaml' require 'yaml'
module Backup module Backup
......
# frozen_string_literal: true
require 'backup/files' require 'backup/files'
module Backup module Backup
......
...@@ -11,10 +11,6 @@ describe Backup::Manager do ...@@ -11,10 +11,6 @@ describe Backup::Manager do
allow(progress).to receive(:puts) allow(progress).to receive(:puts)
allow(progress).to receive(:print) allow(progress).to receive(:print)
allow_any_instance_of(String).to receive(:color) do |string, _color|
string
end
@old_progress = $progress # rubocop:disable Style/GlobalVars @old_progress = $progress # rubocop:disable Style/GlobalVars
$progress = progress # rubocop:disable Style/GlobalVars $progress = progress # rubocop:disable Style/GlobalVars
end end
......
...@@ -11,10 +11,6 @@ describe Backup::Repository do ...@@ -11,10 +11,6 @@ describe Backup::Repository do
allow(FileUtils).to receive(:mkdir_p).and_return(true) allow(FileUtils).to receive(:mkdir_p).and_return(true)
allow(FileUtils).to receive(:mv).and_return(true) allow(FileUtils).to receive(:mv).and_return(true)
allow_any_instance_of(String).to receive(:color) do |string, _color|
string
end
allow_any_instance_of(described_class).to receive(:progress).and_return(progress) allow_any_instance_of(described_class).to receive(:progress).and_return(progress)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment