diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-08 09:08:18 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-08 09:08:18 +0000 |
commit | ae6b82598ff1a9844c132e53799c252225b2c4c1 (patch) | |
tree | ee9faae6518819de06fd6f1ded511251bf100ef6 | |
parent | f9e55cc3c9ec3258051c60562b011bef22075f2a (diff) | |
download | gitlab-ce-ae6b82598ff1a9844c132e53799c252225b2c4c1.tar.gz |
Add latest changes from gitlab-org/gitlab@master
21 files changed, 42 insertions, 39 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d041ce385e3..d30728c1596 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -300,16 +300,6 @@ Style/BarePercentLiterals: Style/CaseLikeIf: Enabled: false -# Offense count: 5 -# Cop supports --auto-correct. -Style/EachWithObject: - Exclude: - - 'lib/expand_variables.rb' - - 'lib/gitlab/ci/ansi2html.rb' - - 'lib/gitlab/hook_data/issuable_builder.rb' - - 'lib/gitlab/i18n/po_linter.rb' - - 'lib/gitlab/import_export/members_mapper.rb' - # Offense count: 55 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. diff --git a/app/assets/javascripts/monitoring/stores/utils.js b/app/assets/javascripts/monitoring/stores/utils.js index c425c819c65..7f75a501635 100644 --- a/app/assets/javascripts/monitoring/stores/utils.js +++ b/app/assets/javascripts/monitoring/stores/utils.js @@ -45,7 +45,7 @@ export const removeLeadingSlash = (str) => (str || '').replace(/^\/+/, ''); /** * GraphQL environments API returns only id and name. * For the environments dropdown we need metrics_path. - * This method parses the results and add neccessart attrs + * This method parses the results and add necessary attrs * * @param {Array} response Environments API result * @param {String} projectPath Current project path @@ -57,7 +57,7 @@ export const parseEnvironmentsResponse = (response = [], projectPath) => return { ...env, id, - metrics_path: `${projectPath}/environments/${id}/metrics`, + metrics_path: `${projectPath}/-/metrics?environment=${id}`, }; }); diff --git a/app/controllers/explore/projects_controller.rb b/app/controllers/explore/projects_controller.rb index f8a6d9f808e..e50369e5f8e 100644 --- a/app/controllers/explore/projects_controller.rb +++ b/app/controllers/explore/projects_controller.rb @@ -110,7 +110,7 @@ class Explore::ProjectsController < Explore::ApplicationController end def load_topic - @topic = Projects::Topic.find_by_name(params[:topic_name]) + @topic = Projects::Topic.find_by_name_case_insensitive(params[:topic_name]) end # rubocop: disable CodeReuse/ActiveRecord diff --git a/app/helpers/environment_helper.rb b/app/helpers/environment_helper.rb index 1f0bf46097d..b6997b6fb70 100644 --- a/app/helpers/environment_helper.rb +++ b/app/helpers/environment_helper.rb @@ -77,7 +77,7 @@ module EnvironmentHelper can_destroy_environment: can_destroy_environment?(environment), can_stop_environment: can?(current_user, :stop_environment, environment), can_admin_environment: can?(current_user, :admin_environment, project), - environment_metrics_path: environment_metrics_path(environment), + environment_metrics_path: project_metrics_dashboard_path(project, environment: environment), environments_fetch_path: project_environments_path(project, format: :json), environment_edit_path: edit_project_environment_path(project, environment), environment_stop_path: stop_project_environment_path(project, environment), diff --git a/app/helpers/environments_helper.rb b/app/helpers/environments_helper.rb index 1894aba7dc0..3b60bda8605 100644 --- a/app/helpers/environments_helper.rb +++ b/app/helpers/environments_helper.rb @@ -92,7 +92,7 @@ module EnvironmentsHelper return path if request.path.include?(path) end - environment_metrics_path(environment) + project_metrics_dashboard_path(project, environment: environment) end def project_and_environment_metrics_data(project, environment) diff --git a/app/helpers/routing/projects_helper.rb b/app/helpers/routing/projects_helper.rb index fb000b29739..859070d59ec 100644 --- a/app/helpers/routing/projects_helper.rb +++ b/app/helpers/routing/projects_helper.rb @@ -18,10 +18,6 @@ module Routing project_environment_path(environment.project, environment, *args) end - def environment_metrics_path(environment, *args) - metrics_project_environment_path(environment.project, environment, *args) - end - def environment_delete_path(environment, *args) expose_path(api_v4_projects_environments_path(id: environment.project.id, environment_id: environment.id)) end diff --git a/app/models/projects/topic.rb b/app/models/projects/topic.rb index b42b03f0618..9214a23e259 100644 --- a/app/models/projects/topic.rb +++ b/app/models/projects/topic.rb @@ -23,6 +23,10 @@ module Projects end class << self + def find_by_name_case_insensitive(name) + find_by('LOWER(name) = ?', name.downcase) + end + def search(query) fuzzy_search(query, [:name]) end diff --git a/app/models/repository.rb b/app/models/repository.rb index c3a0e8ec9d9..dc0b5b54fb0 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -2,6 +2,12 @@ require 'securerandom' +# Explicitly require licensee/license file in order to use Licensee::InvalidLicense class defined in +# https://github.com/licensee/licensee/blob/v9.14.1/lib/licensee/license.rb#L6 +# The problem is that nested classes are not automatically preloaded which may lead to +# uninitialized constant exception being raised: https://gitlab.com/gitlab-org/gitlab/-/issues/356658 +require 'licensee/license' + class Repository REF_MERGE_REQUEST = 'merge-requests' REF_KEEP_AROUND = 'keep-around' diff --git a/app/serializers/environment_status_entity.rb b/app/serializers/environment_status_entity.rb index 40db23c143e..e8cf7980f5e 100644 --- a/app/serializers/environment_status_entity.rb +++ b/app/serializers/environment_status_entity.rb @@ -16,7 +16,7 @@ class EnvironmentStatusEntity < Grape::Entity end expose :metrics_monitoring_url, if: ->(*) { can_read_environment? } do |es| - environment_metrics_path(es.environment) + project_metrics_dashboard_path(es.project, environment: es.environment) end expose :stop_url, if: ->(*) { can_stop_environment? } do |es| diff --git a/lib/expand_variables.rb b/lib/expand_variables.rb index d172df4920f..06160b55f5c 100644 --- a/lib/expand_variables.rb +++ b/lib/expand_variables.rb @@ -50,9 +50,8 @@ module ExpandVariables # Convert hash array to variables if variables.is_a?(Array) - variables = variables.reduce({}) do |hash, variable| + variables = variables.each_with_object({}) do |variable, hash| hash[variable[:key]] = variable[:value] - hash end end diff --git a/lib/gitlab/ci/ansi2html.rb b/lib/gitlab/ci/ansi2html.rb index ef936581c10..10233cf4228 100644 --- a/lib/gitlab/ci/ansi2html.rb +++ b/lib/gitlab/ci/ansi2html.rb @@ -447,9 +447,8 @@ module Gitlab end def state - state = STATE_PARAMS.inject({}) do |h, param| + state = STATE_PARAMS.each_with_object({}) do |param, h| h[param] = send(param) # rubocop:disable GitlabSecurity/PublicSend - h end Base64.urlsafe_encode64(state.to_json) end diff --git a/lib/gitlab/hook_data/issuable_builder.rb b/lib/gitlab/hook_data/issuable_builder.rb index c4e27bf424f..add9e880475 100644 --- a/lib/gitlab/hook_data/issuable_builder.rb +++ b/lib/gitlab/hook_data/issuable_builder.rb @@ -53,10 +53,7 @@ module Gitlab end def final_changes(changes_hash) - changes_hash.reduce({}) do |hash, (key, changes_array)| - hash[key] = Hash[CHANGES_KEYS.zip(changes_array)] - hash - end + changes_hash.transform_values { |changes_array| Hash[CHANGES_KEYS.zip(changes_array)] } end end end diff --git a/lib/gitlab/i18n/po_linter.rb b/lib/gitlab/i18n/po_linter.rb index 3bb34ab2811..74be56df221 100644 --- a/lib/gitlab/i18n/po_linter.rb +++ b/lib/gitlab/i18n/po_linter.rb @@ -248,10 +248,9 @@ module Gitlab variable == '%d' ? Random.rand(1000) : Gitlab::Utils.random_string end else - variables.inject({}) do |hash, variable| + variables.each_with_object({}) do |variable, hash| variable_name = variable[/\w+/] hash[variable_name] = Gitlab::Utils.random_string - hash end end end diff --git a/lib/gitlab/import_export/members_mapper.rb b/lib/gitlab/import_export/members_mapper.rb index d3b1bb6a57d..b1f2a17d4b7 100644 --- a/lib/gitlab/import_export/members_mapper.rb +++ b/lib/gitlab/import_export/members_mapper.rb @@ -16,7 +16,7 @@ module Gitlab def map @map ||= begin - @exported_members.inject(missing_keys_tracking_hash) do |hash, member| + @exported_members.each_with_object(missing_keys_tracking_hash) do |member, hash| if member['user'] old_user_id = member['user']['id'] existing_user_id = existing_users_email_map[get_email(member)] @@ -24,8 +24,6 @@ module Gitlab else add_team_member(member) end - - hash end end end diff --git a/spec/controllers/explore/projects_controller_spec.rb b/spec/controllers/explore/projects_controller_spec.rb index c3f6c653376..bf578489916 100644 --- a/spec/controllers/explore/projects_controller_spec.rb +++ b/spec/controllers/explore/projects_controller_spec.rb @@ -112,6 +112,13 @@ RSpec.describe Explore::ProjectsController do expect(response).to have_gitlab_http_status(:ok) expect(response).to render_template('topic') end + + it 'finds topic by case insensitive name' do + get :topic, params: { topic_name: 'TOPIC1' } + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template('topic') + end end end end diff --git a/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap b/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap index bd2e818df4f..d2d33101f27 100644 --- a/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap +++ b/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap @@ -5,7 +5,7 @@ exports[`Dashboard template matches the default snapshot 1`] = ` class="prometheus-graphs" data-qa-selector="prometheus_graphs" environmentstate="available" - metricsdashboardbasepath="/monitoring/monitor-project/-/environments/1/metrics" + metricsdashboardbasepath="/monitoring/monitor-project/-/metrics?environment=1" metricsendpoint="/monitoring/monitor-project/-/environments/1/additional_metrics.json" > <div> diff --git a/spec/frontend/monitoring/components/dashboard_url_time_spec.js b/spec/frontend/monitoring/components/dashboard_url_time_spec.js index 246dd598d19..64c48100b31 100644 --- a/spec/frontend/monitoring/components/dashboard_url_time_spec.js +++ b/spec/frontend/monitoring/components/dashboard_url_time_spec.js @@ -126,7 +126,7 @@ describe('dashboard invalid url parameters', () => { }); it('redirects to different time range', async () => { - const toUrl = `${mockProjectDir}/-/environments/1/metrics`; + const toUrl = `${mockProjectDir}/-/metrics?environment=1`; removeParams.mockReturnValueOnce(toUrl); createMountedWrapper(); diff --git a/spec/frontend/monitoring/store/utils_spec.js b/spec/frontend/monitoring/store/utils_spec.js index 697bdb9185f..c25de8caa95 100644 --- a/spec/frontend/monitoring/store/utils_spec.js +++ b/spec/frontend/monitoring/store/utils_spec.js @@ -547,7 +547,7 @@ describe('parseEnvironmentsResponse', () => { { id: 1, name: 'env-1', - metrics_path: `${projectPath}/environments/1/metrics`, + metrics_path: `${projectPath}/-/metrics?environment=1`, }, ], }, @@ -562,7 +562,7 @@ describe('parseEnvironmentsResponse', () => { { id: 12, name: 'env-12', - metrics_path: `${projectPath}/environments/12/metrics`, + metrics_path: `${projectPath}/-/metrics?environment=12`, }, ], }, diff --git a/spec/helpers/environment_helper_spec.rb b/spec/helpers/environment_helper_spec.rb index 8e5f38cd95a..1fcbcd8c4f9 100644 --- a/spec/helpers/environment_helper_spec.rb +++ b/spec/helpers/environment_helper_spec.rb @@ -55,7 +55,7 @@ RSpec.describe EnvironmentHelper do can_destroy_environment: true, can_stop_environment: true, can_admin_environment: true, - environment_metrics_path: environment_metrics_path(environment), + environment_metrics_path: project_metrics_dashboard_path(project, environment: environment), environments_fetch_path: project_environments_path(project, format: :json), environment_edit_path: edit_project_environment_path(project, environment), environment_stop_path: stop_project_environment_path(project, environment), diff --git a/spec/helpers/environments_helper_spec.rb b/spec/helpers/environments_helper_spec.rb index 38f06b19b94..52f02fba4ec 100644 --- a/spec/helpers/environments_helper_spec.rb +++ b/spec/helpers/environments_helper_spec.rb @@ -20,7 +20,7 @@ RSpec.describe EnvironmentsHelper do expect(metrics_data).to include( 'settings_path' => edit_project_integration_path(project, 'prometheus'), 'clusters_path' => project_clusters_path(project), - 'metrics_dashboard_base_path' => environment_metrics_path(environment), + 'metrics_dashboard_base_path' => project_metrics_dashboard_path(project, environment: environment), 'current_environment_name' => environment.name, 'documentation_path' => help_page_path('administration/monitoring/prometheus/index.md'), 'add_dashboard_documentation_path' => help_page_path('operations/metrics/dashboards/index.md', anchor: 'add-a-new-dashboard-to-your-project'), diff --git a/spec/models/projects/topic_spec.rb b/spec/models/projects/topic_spec.rb index aa3230da1e6..8fc4d11f0d9 100644 --- a/spec/models/projects/topic_spec.rb +++ b/spec/models/projects/topic_spec.rb @@ -56,6 +56,14 @@ RSpec.describe Projects::Topic do end end + describe '#find_by_name_case_insensitive' do + it 'returns topic with case insensitive name' do + %w(topic TOPIC Topic).each do |name| + expect(described_class.find_by_name_case_insensitive(name)).to eq(topic) + end + end + end + describe '#search' do it 'returns topics with a matching name' do expect(described_class.search(topic.name)).to eq([topic]) |