diff --git a/app/helpers/gitlab_routing_helper.rb b/app/helpers/gitlab_routing_helper.rb index 7ae00a70671edad4939b6492b0b928d103a28fac..882ae300796da7b51f1a79c550dad349c11b8fd6 100644 --- a/app/helpers/gitlab_routing_helper.rb +++ b/app/helpers/gitlab_routing_helper.rb @@ -9,6 +9,12 @@ module GitlabRoutingHelper Gitlab::Routing.includes_helpers(self) end + def self.unbound_methods + instance_methods(false).map do |method_name| + instance_method(method_name) + end + end + # Project def project_tree_path(project, ref = nil, *args) namespace_project_tree_path(project.namespace, project, ref || @ref || project.repository.root_ref, *args) # rubocop:disable Cop/ProjectPathHelper diff --git a/app/services/incident_management/create_incident_label_service.rb b/app/services/incident_management/create_incident_label_service.rb index 595f5df184fe5a69742a95c31fb74b58ee5a3d29..31dca29c13e823fc91fc888f454fbed3258ee142 100644 --- a/app/services/incident_management/create_incident_label_service.rb +++ b/app/services/incident_management/create_incident_label_service.rb @@ -2,18 +2,20 @@ module IncidentManagement class CreateIncidentLabelService < BaseService - LABEL_PROPERTIES = { - title: 'incident', - color: '#CC0033', - description: <<~DESCRIPTION.chomp - Denotes a disruption to IT services and \ - the associated issues require immediate attention - DESCRIPTION - }.freeze + def self.label_properties + @label_properties ||= { + title: 'incident', + color: '#CC0033', + description: <<~DESCRIPTION.chomp + Denotes a disruption to IT services and \ + the associated issues require immediate attention + DESCRIPTION + }.freeze + end def execute label = Labels::FindOrCreateService - .new(current_user, project, **LABEL_PROPERTIES) + .new(current_user, project, **self.class.label_properties) .execute(skip_authorization: true) ServiceResponse.success(payload: { label: label }) diff --git a/config/application.rb b/config/application.rb index 341cc36cbdb647920d1af52a942125dd97b3b185..371f6f22d53a48fcf51f6a6fb4576360ddc8eb20 100644 --- a/config/application.rb +++ b/config/application.rb @@ -368,5 +368,9 @@ class Application < Rails::Application end end end + + config.before_eager_load do |config| + ::API::API + end end end diff --git a/config/initializers/8_devise.rb b/config/initializers/8_devise.rb index a4841a11a0049f76e66cc6ad17b37f59ebfbf791..00f50c5161a692af4a782bedabd3a4105fb99204 100644 --- a/config/initializers/8_devise.rb +++ b/config/initializers/8_devise.rb @@ -6,10 +6,9 @@ manager.default_strategies(scope: :user).unshift :two_factor_backupable end - # This is the default. This makes it explicit that Devise loads routes - # before eager loading. Disabling this seems to cause an error loading - # grape-entity `expose` for some reason. - config.reload_routes = true + # Rails applications are already reloading the routes with `set_routes_reloader_hook` + # so there is no need to reload the routes before the eager_load! hook. + config.reload_routes = false # ==> Mailer Configuration # Configure the class responsible to send e-mails. diff --git a/config/routes.rb b/config/routes.rb index 673719abb0000131b6b22c184eaf3844f7a30930..0c3fcf8cd623a0eed78d888db915d6decac618e5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -307,9 +307,22 @@ end end + GitlabRoutingHelper.unbound_methods.each do |method| + bound_method = method.bind(Gitlab::Routing.url_helpers) + + # direct(method.name) do |*args| + # args.pop if args.last == {} + + # bound_method.call(*args) + # end + end + root to: "root#index" get '*unmatched_route', to: 'application#route_not_found' end Gitlab::Routing.add_helpers(TimeboxesRoutingHelper) + +# HACK! +ActionDispatch::Routing::RouteSet::MountedHelpers.prepend(GitlabRoutingHelper) diff --git a/ee/app/services/incident_management/create_incident_sla_exceeded_label_service.rb b/ee/app/services/incident_management/create_incident_sla_exceeded_label_service.rb index 1dfec055e5933a275d594776b99be4238dafd698..17384931d02d39bcb85d524c5bfe25dd913bbeaa 100644 --- a/ee/app/services/incident_management/create_incident_sla_exceeded_label_service.rb +++ b/ee/app/services/incident_management/create_incident_sla_exceeded_label_service.rb @@ -2,21 +2,27 @@ module IncidentManagement class CreateIncidentSlaExceededLabelService < BaseService - def self.doc_url - Rails.application.routes.url_helpers.help_page_url('operations/incident_management/incidents', anchor: 'service-level-agreement-countdown-timer') - end + class << self + def label_properties + @label_properties ||= { + title: 'missed::SLA', + color: '#D9534F', + description: <<~DESCRIPTION.chomp + Incidents that have missed the targeted SLA (Service Level Agreement). #{doc_url} + DESCRIPTION + }.freeze + end + + private - LABEL_PROPERTIES = { - title: 'missed::SLA', - color: '#D9534F', - description: <<~DESCRIPTION.chomp - Incidents that have missed the targeted SLA (Service Level Agreement). #{doc_url} - DESCRIPTION - }.freeze + def doc_url + Rails.application.routes.url_helpers.help_page_url('operations/incident_management/incidents', anchor: 'service-level-agreement-countdown-timer') + end + end def execute label = Labels::FindOrCreateService - .new(current_user, project, **LABEL_PROPERTIES) + .new(current_user, project, **self.class.label_properties) .execute(skip_authorization: true) ServiceResponse.success(payload: { label: label }) diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb index f935c677930805f333559ef31f3854fee7f7f269..9d9da2542206639703cff325e9b60d4a3ccdec90 100644 --- a/lib/gitlab/usage_data.rb +++ b/lib/gitlab/usage_data.rb @@ -142,7 +142,7 @@ def system_usage_data issues_created_manually_from_alerts: issues_created_manually_from_alerts, incident_issues: count(::Issue.incident, start: issue_minimum_id, finish: issue_maximum_id), alert_bot_incident_issues: count(::Issue.authored(::User.alert_bot), start: issue_minimum_id, finish: issue_maximum_id), - incident_labeled_issues: count(::Issue.with_label_attributes(::IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES), start: issue_minimum_id, finish: issue_maximum_id), + incident_labeled_issues: count(::Issue.with_label_attributes(::IncidentManagement::CreateIncidentLabelService.label_properties), start: issue_minimum_id, finish: issue_maximum_id), keys: count(Key), label_lists: count(List.label), lfs_objects: count(LfsObject), diff --git a/spec/factories/labels.rb b/spec/factories/labels.rb index a9a9416c48bb7bb8fa7f313b63e2753ce8b287cc..58975767867734e57a790a31648d983a9c003080 100644 --- a/spec/factories/labels.rb +++ b/spec/factories/labels.rb @@ -19,7 +19,7 @@ end trait :incident do - properties = IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES + properties = IncidentManagement::CreateIncidentLabelService.label_properties title { properties.fetch(:title) } description { properties.fetch(:description) } color { properties.fetch(:color) } diff --git a/spec/migrations/add_incident_settings_to_all_existing_projects_spec.rb b/spec/migrations/add_incident_settings_to_all_existing_projects_spec.rb index a62fc43df02717ad6643b216db7742c4e086db3d..185f5f923be90569d40228296a8991de040a38d1 100644 --- a/spec/migrations/add_incident_settings_to_all_existing_projects_spec.rb +++ b/spec/migrations/add_incident_settings_to_all_existing_projects_spec.rb @@ -67,7 +67,7 @@ context 'when project has incident labels' do before do issue = issues.create!(project_id: project.id) - incident_label_attrs = IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES + incident_label_attrs = IncidentManagement::CreateIncidentLabelService.label_properties incident_label = labels.create!(project_id: project.id, **incident_label_attrs) label_links.create!(target_id: issue.id, label_id: incident_label.id, target_type: 'Issue') end diff --git a/spec/migrations/migrate_incident_issues_to_incident_type_spec.rb b/spec/migrations/migrate_incident_issues_to_incident_type_spec.rb index dc38695c7fe6fe0034f120dd4f8cf5747d7e6d13..1ce02e7bdec5a04e88806ea6f19ec38d0d142e6c 100644 --- a/spec/migrations/migrate_incident_issues_to_incident_type_spec.rb +++ b/spec/migrations/migrate_incident_issues_to_incident_type_spec.rb @@ -11,7 +11,7 @@ let(:labels) { table(:labels) } let(:issues) { table(:issues) } let(:label_links) { table(:label_links) } - let(:label_props) { IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES } + let(:label_props) { IncidentManagement::CreateIncidentLabelService.label_properties } let(:namespace) { namespaces.create!(name: 'foo', path: 'foo') } let!(:project) { projects.create!(namespace_id: namespace.id) } diff --git a/spec/support/shared_examples/services/incident_shared_examples.rb b/spec/support/shared_examples/services/incident_shared_examples.rb index 9fced12b5438240eec4d8eb8d393bba699cabc48..d204b7f6c42129784b1c9a26cda59342ab1f838c 100644 --- a/spec/support/shared_examples/services/incident_shared_examples.rb +++ b/spec/support/shared_examples/services/incident_shared_examples.rb @@ -63,7 +63,7 @@ subject(:execute) { service.execute } describe 'execute' do - let(:incident_label_attributes) { described_class::LABEL_PROPERTIES } + let(:incident_label_attributes) { described_class.label_properties } let(:title) { incident_label_attributes[:title] } let(:color) { incident_label_attributes[:color] } let(:description) { incident_label_attributes[:description] }