diff options
70 files changed, 381 insertions, 282 deletions
diff --git a/.rubocop_todo/style/rescue_modifier.yml b/.rubocop_todo/style/rescue_modifier.yml deleted file mode 100644 index 298ef3aece9..00000000000 --- a/.rubocop_todo/style/rescue_modifier.yml +++ /dev/null @@ -1,51 +0,0 @@ ---- -# Cop supports --auto-correct. -Style/RescueModifier: - # Offense count: 59 - # Temporarily disabled due to too many offenses - Enabled: false - Exclude: - - 'app/controllers/admin/system_info_controller.rb' - - 'app/controllers/users_controller.rb' - - 'app/finders/ci/daily_build_group_report_results_finder.rb' - - 'app/helpers/blob_helper.rb' - - 'app/models/concerns/diff_positionable_note.rb' - - 'app/models/integrations/jira.rb' - - 'app/models/sent_notification.rb' - - 'app/models/todo.rb' - - 'app/services/security/ci_configuration/sast_parser_service.rb' - - 'config/initializers/active_record_data_types.rb' - - 'config/settings.rb' - - 'ee/app/models/license.rb' - - 'ee/lib/ee/gitlab/background_migration/drop_invalid_remediations.rb' - - 'ee/lib/gitlab/geo.rb' - - 'ee/lib/gitlab/geo/health_check.rb' - - 'lib/api/helpers.rb' - - 'lib/feature.rb' - - 'lib/gitlab/current_settings.rb' - - 'lib/gitlab/dependency_linker/cargo_toml_linker.rb' - - 'lib/gitlab/dependency_linker/json_linker.rb' - - 'lib/gitlab/diff/parser.rb' - - 'lib/gitlab/import_export/after_export_strategy_builder.rb' - - 'lib/gitlab/kubernetes.rb' - - 'lib/gitlab/middleware/read_only/controller.rb' - - 'lib/gitlab/process_management.rb' - - 'lib/gitlab/query_limiting/middleware.rb' - - 'lib/gitlab/quick_actions/command_definition.rb' - - 'lib/gitlab/quick_actions/spend_time_and_date_separator.rb' - - 'lib/gitlab/word_diff/segments/diff_hunk.rb' - - 'lib/gitlab/zentao/client.rb' - - 'lib/tasks/gitlab/praefect.rake' - - 'qa/qa/page/component/access_tokens.rb' - - 'qa/qa/page/profile/ssh_keys.rb' - - 'spec/finders/concerns/finder_with_cross_project_access_spec.rb' - - 'spec/lib/gitlab/database/load_balancing/session_spec.rb' - - 'spec/lib/gitlab/database/migrations/instrumentation_spec.rb' - - 'spec/lib/gitlab/email/handler/service_desk_handler_spec.rb' - - 'spec/lib/gitlab/sidekiq_middleware/monitor_spec.rb' - - 'spec/models/concerns/bulk_insert_safe_spec.rb' - - 'spec/models/design_management/version_spec.rb' - - 'spec/models/group_spec.rb' - - 'spec/models/namespace/traversal_hierarchy_spec.rb' - - 'spec/services/design_management/delete_designs_service_spec.rb' - - 'spec/support/shared_examples/lib/gitlab/config/inheritable_shared_examples.rb' diff --git a/app/assets/javascripts/work_items/components/work_item_links/work_item_links.vue b/app/assets/javascripts/work_items/components/work_item_links/work_item_links.vue index fd568c1dfce..23264a12465 100644 --- a/app/assets/javascripts/work_items/components/work_item_links/work_item_links.vue +++ b/app/assets/javascripts/work_items/components/work_item_links/work_item_links.vue @@ -213,21 +213,23 @@ export default { <template> <div class="gl-rounded-base gl-border-1 gl-border-solid gl-border-gray-100 gl-bg-gray-10"> <div - class="gl-p-4 gl-display-flex gl-justify-content-space-between" + class="gl-px-5 gl-py-3 gl-display-flex gl-justify-content-space-between" :class="{ 'gl-border-b-1 gl-border-b-solid gl-border-b-gray-100': isOpen }" > - <h5 class="gl-m-0 gl-line-height-32 gl-flex-grow-1">{{ $options.i18n.title }}</h5> + <h5 class="gl-m-0 gl-line-height-24 gl-flex-grow-1">{{ $options.i18n.title }}</h5> <gl-button v-if="canUpdate" category="secondary" + size="small" data-testid="toggle-add-form" @click="showAddForm" > {{ $options.i18n.addChildButtonLabel }} </gl-button> - <div class="gl-border-l-1 gl-border-l-solid gl-border-l-gray-50 gl-pl-4 gl-ml-3"> + <div class="gl-border-l-1 gl-border-l-solid gl-border-l-gray-50 gl-pl-3 gl-ml-3"> <gl-button category="tertiary" + size="small" :icon="toggleIcon" :aria-label="toggleLabel" data-testid="toggle-links" @@ -237,14 +239,14 @@ export default { </div> <div v-if="isOpen" - class="gl-bg-gray-10 gl-p-4 gl-rounded-bottom-left-base gl-rounded-bottom-right-base" + class="gl-bg-gray-10 gl-p-5 gl-pb-3 gl-rounded-bottom-left-base gl-rounded-bottom-right-base" data-testid="links-body" > <gl-loading-icon v-if="isLoading" color="dark" class="gl-my-3" /> <template v-else> <div v-if="isChildrenEmpty && !isShownAddForm" data-testid="links-empty"> - <p class="gl-my-3"> + <p class="gl-mt-3 gl-mb-4"> {{ $options.i18n.emptyStateMessage }} </p> </div> diff --git a/app/components/pajamas/avatar_component.rb b/app/components/pajamas/avatar_component.rb index 09d4776557d..073968e0491 100644 --- a/app/components/pajamas/avatar_component.rb +++ b/app/components/pajamas/avatar_component.rb @@ -39,7 +39,11 @@ module Pajamas # Users show a gravatar instead of an identicon. Also avatars of # blocked users are only shown if the current_user is an admin. # To not duplicate this logic, we are using existing helpers here. - current_user = helpers.current_user rescue nil + current_user = begin + helpers.current_user + rescue StandardError + nil + end helpers.avatar_icon_for_user(@record, @size, current_user: current_user) elsif @record.try(:avatar_url) "#{@record.avatar_url}?width=#{@size}" diff --git a/app/controllers/admin/system_info_controller.rb b/app/controllers/admin/system_info_controller.rb index e872a959aa3..41f95addc66 100644 --- a/app/controllers/admin/system_info_controller.rb +++ b/app/controllers/admin/system_info_controller.rb @@ -37,8 +37,16 @@ class Admin::SystemInfoController < Admin::ApplicationController ].freeze def show - @cpus = Vmstat.cpu rescue nil - @memory = Vmstat.memory rescue nil + @cpus = begin + Vmstat.cpu + rescue StandardError + nil + end + @memory = begin + Vmstat.memory + rescue StandardError + nil + end mounts = Sys::Filesystem.mounts @disks = [] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index eaf08cd421b..3c1a3534912 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -155,7 +155,11 @@ class UsersController < ApplicationController end def calendar_activities - @calendar_date = Date.parse(params[:date]) rescue Date.today + @calendar_date = begin + Date.parse(params[:date]) + rescue StandardError + Date.today + end @events = contributions_calendar.events_by_date(@calendar_date).map(&:present) render 'calendar_activities', layout: false diff --git a/app/finders/ci/daily_build_group_report_results_finder.rb b/app/finders/ci/daily_build_group_report_results_finder.rb index 33aefe29392..b93b7dbe0c5 100644 --- a/app/finders/ci/daily_build_group_report_results_finder.rb +++ b/app/finders/ci/daily_build_group_report_results_finder.rb @@ -82,14 +82,20 @@ module Ci end def start_date - start_date = Date.strptime(params[:start_date], DATE_FORMAT_ALLOWED) rescue REPORT_WINDOW.ago.to_date + start_date = begin + Date.strptime(params[:start_date], DATE_FORMAT_ALLOWED) + rescue StandardError + REPORT_WINDOW.ago.to_date + end # The start_date cannot be older than `end_date - 90 days` [start_date, end_date - REPORT_WINDOW].max end def end_date - Date.strptime(params[:end_date], DATE_FORMAT_ALLOWED) rescue Date.current + Date.strptime(params[:end_date], DATE_FORMAT_ALLOWED) + rescue StandardError + Date.current end end end diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index e42ac759cd6..2c84da4862a 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -298,7 +298,9 @@ module BlobHelper def readable_blob(options, path, project, ref) blob = options.fetch(:blob) do - project.repository.blob_at(ref, path) rescue nil + project.repository.blob_at(ref, path) + rescue StandardError + nil end blob if blob&.readable_text? diff --git a/app/models/concerns/diff_positionable_note.rb b/app/models/concerns/diff_positionable_note.rb index 051158e5de5..7a6076c7d2e 100644 --- a/app/models/concerns/diff_positionable_note.rb +++ b/app/models/concerns/diff_positionable_note.rb @@ -17,7 +17,11 @@ module DiffPositionableNote %i(original_position position change_position).each do |meth| define_method "#{meth}=" do |new_position| if new_position.is_a?(String) - new_position = Gitlab::Json.parse(new_position) rescue nil + new_position = begin + Gitlab::Json.parse(new_position) + rescue StandardError + nil + end end if new_position.is_a?(Hash) diff --git a/app/models/integration.rb b/app/models/integration.rb index 54809bdbb06..1d966ac4da0 100644 --- a/app/models/integration.rb +++ b/app/models/integration.rb @@ -48,6 +48,9 @@ class Integration < ApplicationRecord SECTION_TYPE_CONNECTION = 'connection' SECTION_TYPE_TRIGGER = 'trigger' + SNOWPLOW_EVENT_ACTION = 'perform_integrations_action' + SNOWPLOW_EVENT_LABEL = 'redis_hll_counters.ecosystem.ecosystem_total_unique_counts_monthly' + attr_encrypted :properties, mode: :per_attribute_iv, key: Settings.attr_encrypted_db_key_base_32, diff --git a/app/models/integrations/jira.rb b/app/models/integrations/jira.rb index 8759932bc62..d84029e53c2 100644 --- a/app/models/integrations/jira.rb +++ b/app/models/integrations/jira.rb @@ -19,8 +19,6 @@ module Integrations SECTION_TYPE_JIRA_ISSUES = 'jira_issues' SNOWPLOW_EVENT_CATEGORY = self.name - SNOWPLOW_EVENT_ACTION = 'perform_integrations_action' - SNOWPLOW_EVENT_LABEL = 'redis_hll_counters.ecosystem.ecosystem_total_unique_counts_monthly' validates :url, public_url: true, presence: true, if: :activated? validates :api_url, public_url: true, allow_blank: true @@ -372,7 +370,11 @@ module Integrations end def transition_issue_to_done(issue) - transitions = issue.transitions rescue [] + transitions = begin + issue.transitions + rescue StandardError + [] + end transition = transitions.find do |transition| status = transition&.to&.statusCategory @@ -398,8 +400,8 @@ module Integrations Gitlab::Tracking.event( SNOWPLOW_EVENT_CATEGORY, - SNOWPLOW_EVENT_ACTION, - label: SNOWPLOW_EVENT_LABEL, + Integration::SNOWPLOW_EVENT_ACTION, + label: Integration::SNOWPLOW_EVENT_LABEL, property: key, user: user, **optional_arguments diff --git a/app/models/integrations/slack.rb b/app/models/integrations/slack.rb index 93263229109..c254ea379bb 100644 --- a/app/models/integrations/slack.rb +++ b/app/models/integrations/slack.rb @@ -9,6 +9,7 @@ module Integrations push issue confidential_issue merge_request note confidential_note tag_push wiki_page deployment ].freeze + SNOWPLOW_EVENT_CATEGORY = self.name prop_accessor EVENT_CHANNEL['alert'] @@ -54,6 +55,22 @@ module Integrations key = "i_ecosystem_slack_service_#{event}_notification" Gitlab::UsageDataCounters::HLLRedisCounter.track_event(key, values: user_id) + + return unless Feature.enabled?(:route_hll_to_snowplow_phase2) + + optional_arguments = { + project: project, + namespace: group || project&.namespace + }.compact + + Gitlab::Tracking.event( + SNOWPLOW_EVENT_CATEGORY, + Integration::SNOWPLOW_EVENT_ACTION, + label: Integration::SNOWPLOW_EVENT_LABEL, + property: key, + user: User.find(user_id), + **optional_arguments + ) end override :configurable_channels? diff --git a/app/models/sent_notification.rb b/app/models/sent_notification.rb index 5d7b3879d75..8fea0d6d993 100644 --- a/app/models/sent_notification.rb +++ b/app/models/sent_notification.rb @@ -68,7 +68,11 @@ class SentNotification < ApplicationRecord def noteable if for_commit? - project.commit(commit_id) rescue nil + begin + project.commit(commit_id) + rescue StandardError + nil + end else super end @@ -76,7 +80,11 @@ class SentNotification < ApplicationRecord def position=(new_position) if new_position.is_a?(String) - new_position = Gitlab::Json.parse(new_position) rescue nil + new_position = begin + Gitlab::Json.parse(new_position) + rescue StandardError + nil + end end if new_position.is_a?(Hash) diff --git a/app/models/todo.rb b/app/models/todo.rb index c698783d750..f366f854b9c 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -238,7 +238,11 @@ class Todo < ApplicationRecord # override to return commits, which are not active record def target if for_commit? - project.commit(commit_id) rescue nil + begin + project.commit(commit_id) + rescue StandardError + nil + end else super end diff --git a/app/presenters/merge_request_presenter.rb b/app/presenters/merge_request_presenter.rb index efab1e84923..417a2f9c51f 100644 --- a/app/presenters/merge_request_presenter.rb +++ b/app/presenters/merge_request_presenter.rb @@ -191,18 +191,7 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated end def mergeable_discussions_state - if Feature.enabled?(:change_response_code_merge_status, project) - merge_request.mergeable_discussions_state? - else - # This avoids calling MergeRequest#mergeable_discussions_state without - # considering the state of the MR first. If a MR isn't mergeable, we can - # safely short-circuit it. - if merge_request.mergeable_state?(skip_ci_check: true, skip_discussions_check: true) - merge_request.mergeable_discussions_state? - else - false - end - end + merge_request.mergeable_discussions_state? end delegator_override :subscribed? diff --git a/app/serializers/merge_request_poll_widget_entity.rb b/app/serializers/merge_request_poll_widget_entity.rb index fc1534a88aa..40bb905c5c9 100644 --- a/app/serializers/merge_request_poll_widget_entity.rb +++ b/app/serializers/merge_request_poll_widget_entity.rb @@ -33,18 +33,7 @@ class MergeRequestPollWidgetEntity < Grape::Entity # Booleans expose :mergeable_discussions_state?, as: :mergeable_discussions_state do |merge_request| - if Feature.enabled?(:change_response_code_merge_status, merge_request.project) - merge_request.mergeable_discussions_state? - else - # This avoids calling MergeRequest#mergeable_discussions_state without - # considering the state of the MR first. If a MR isn't mergeable, we can - # safely short-circuit it. - if merge_request.mergeable_state?(skip_ci_check: true, skip_discussions_check: true) - merge_request.mergeable_discussions_state? - else - false - end - end + merge_request.mergeable_discussions_state? end expose :project_archived do |merge_request| diff --git a/app/services/security/ci_configuration/sast_parser_service.rb b/app/services/security/ci_configuration/sast_parser_service.rb index cae9a90f0a0..16a9efcefdf 100644 --- a/app/services/security/ci_configuration/sast_parser_service.rb +++ b/app/services/security/ci_configuration/sast_parser_service.rb @@ -75,7 +75,11 @@ module Security def sast_excluded_analyzers strong_memoize(:sast_excluded_analyzers) do excluded_analyzers = gitlab_ci_yml_attributes["SAST_EXCLUDED_ANALYZERS"] || sast_template_attributes["SAST_EXCLUDED_ANALYZERS"] - excluded_analyzers.split(',').map(&:strip) rescue [] + begin + excluded_analyzers.split(',').map(&:strip) + rescue StandardError + [] + end end end diff --git a/config/feature_flags/development/change_response_code_merge_status.yml b/config/feature_flags/development/change_response_code_merge_status.yml deleted file mode 100644 index 9f102d70354..00000000000 --- a/config/feature_flags/development/change_response_code_merge_status.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -name: change_response_code_merge_status -introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/82465/ -rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/356930 -milestone: '15.1' -type: development -group: group::code review -default_enabled: true diff --git a/config/initializers/active_record_data_types.rb b/config/initializers/active_record_data_types.rb index f8f0a69622f..7f4bd32c221 100644 --- a/config/initializers/active_record_data_types.rb +++ b/config/initializers/active_record_data_types.rb @@ -45,9 +45,13 @@ class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter NATIVE_DATABASE_TYPES[:datetime_with_timezone] = { name: 'timestamptz' } end -# Ensure `datetime_with_timezone` columns are correctly written to schema.rb -if (ActiveRecord::Base.connection.active? rescue false) - ActiveRecord::Base.connection.send :reload_type_map +def connection_active? + ActiveRecord::Base.connection.active? # rubocop:disable Database/MultipleDatabases +rescue StandardError + false end +# Ensure `datetime_with_timezone` columns are correctly written to schema.rb +ActiveRecord::Base.connection.send(:reload_type_map) if connection_active? + ActiveRecord::Base.time_zone_aware_types += [:datetime_with_timezone] diff --git a/config/settings.rb b/config/settings.rb index 35c8ad72bcf..51d54817646 100644 --- a/config/settings.rb +++ b/config/settings.rb @@ -109,7 +109,11 @@ class Settings < Settingslogic constant = modul.constants.find { |name| modul.const_get(name, false) == current } value = constant.nil? ? default : modul.const_get(constant, false) if current.is_a? String - value = modul.const_get(current.upcase, false) rescue default + value = begin + modul.const_get(current.upcase, false) + rescue StandardError + default + end end value diff --git a/doc/api/merge_requests.md b/doc/api/merge_requests.md index c6714459643..1d563673a20 100644 --- a/doc/api/merge_requests.md +++ b/doc/api/merge_requests.md @@ -1624,9 +1624,9 @@ This API returns specific HTTP status codes on failure: | HTTP Status | Message | Reason | |:------------|--------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------| | `401` | `Unauthorized` | This user does not have permission to accept this merge request. | -| `405` | `Method Not Allowed` | The merge request cannot be accepted because it is `Draft`, `Closed`, `Pipeline Pending Completion`, or `Failed`. `Success` is required. | -| `406` | `Branch cannot be merged` | The merge request can not be merged. | +| `405` | `Method Not Allowed` | The merge request is not able to be merged. | | `409` | `SHA does not match HEAD of source branch` | The provided `sha` parameter does not match the HEAD of the source. | +| `422` | `Branch cannot be merged` | The merge request failed to merge. | For additional important notes on response data, read [Single merge request response notes](#single-merge-request-response-notes). diff --git a/doc/api/version.md b/doc/api/version.md index 80269bc5697..7d072e23410 100644 --- a/doc/api/version.md +++ b/doc/api/version.md @@ -6,6 +6,10 @@ info: To determine the technical writer assigned to the Stage/Group associated w # Version API **(FREE)** +NOTE: +We recommend you use the [Metadata API](metadata.md) instead of the Version API. +It contains additional information and is aligned with the GraphQL metadata endpoint. + Retrieve version information for this GitLab instance. Responds `200 OK` for authenticated users. diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index cfe1a042129..1d0f0c6e7bb 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -22,7 +22,11 @@ module API 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 StandardError + nil + end if if_unmodified_since && last_modified && last_modified > if_unmodified_since render_api_error!('412 Precondition Failed', 412) diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index 0bcf76497a0..e241c0297d2 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -455,11 +455,7 @@ module API not_allowed! if !immediately_mergeable && !automatically_mergeable - if Feature.enabled?(:change_response_code_merge_status, user_project) - render_api_error!('Branch cannot be merged', 422) unless merge_request.mergeable?(skip_ci_check: automatically_mergeable) - else - render_api_error!('Branch cannot be merged', 406) unless merge_request.mergeable?(skip_ci_check: automatically_mergeable) - end + render_api_error!('Branch cannot be merged', 422) unless merge_request.mergeable?(skip_ci_check: automatically_mergeable) check_sha_param!(params, merge_request) @@ -482,7 +478,7 @@ module API end if immediately_mergeable && !merge_request.merged? - render_api_error!("Failed to merge branch", 422) + render_api_error!("Branch cannot be merged", 422) else present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project end diff --git a/lib/feature.rb b/lib/feature.rb index ca91d86c199..f317e8cb2c5 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -31,7 +31,11 @@ module Feature def feature_flags_available? # When the DBMS is not available, an exception (e.g. PG::ConnectionBad) is raised - active_db_connection = ActiveRecord::Base.connection.active? rescue false # rubocop:disable Database/MultipleDatabases + active_db_connection = begin + ActiveRecord::Base.connection.active? # rubocop:disable Database/MultipleDatabases + rescue StandardError + false + end active_db_connection && Feature::FlipperFeature.table_exists? rescue ActiveRecord::NoDatabaseError diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb index 8ef4977177a..5c4899da11f 100644 --- a/lib/gitlab/current_settings.rb +++ b/lib/gitlab/current_settings.rb @@ -84,7 +84,11 @@ module Gitlab def connect_to_db? # When the DBMS is not available, an exception (e.g. PG::ConnectionBad) is raised - active_db_connection = ::ApplicationSetting.connection.active? rescue false + active_db_connection = begin + ::ApplicationSetting.connection.active? + rescue StandardError + false + end active_db_connection && ApplicationSetting.database.cached_table_exists? diff --git a/lib/gitlab/dependency_linker/cargo_toml_linker.rb b/lib/gitlab/dependency_linker/cargo_toml_linker.rb index 57e0a5f4699..cba4319ce83 100644 --- a/lib/gitlab/dependency_linker/cargo_toml_linker.rb +++ b/lib/gitlab/dependency_linker/cargo_toml_linker.rb @@ -39,7 +39,11 @@ module Gitlab end def toml - @toml ||= TomlRB.parse(plain_text) rescue nil + @toml ||= begin + TomlRB.parse(plain_text) + rescue StandardError + nil + end end end end diff --git a/lib/gitlab/dependency_linker/json_linker.rb b/lib/gitlab/dependency_linker/json_linker.rb index 86dc7efb0d9..15c17132283 100644 --- a/lib/gitlab/dependency_linker/json_linker.rb +++ b/lib/gitlab/dependency_linker/json_linker.rb @@ -39,7 +39,11 @@ module Gitlab end def json - @json ||= Gitlab::Json.parse(plain_text) rescue nil + @json ||= begin + Gitlab::Json.parse(plain_text) + rescue StandardError + nil + end end end end diff --git a/lib/gitlab/diff/parser.rb b/lib/gitlab/diff/parser.rb index adb711ca89f..924c28e3db5 100644 --- a/lib/gitlab/diff/parser.rb +++ b/lib/gitlab/diff/parser.rb @@ -28,9 +28,11 @@ module Gitlab if line =~ /^@@ -/ type = "match" - line_old = line.match(/\-[0-9]*/)[0].to_i.abs rescue 0 - line_new = line.match(/\+[0-9]*/)[0].to_i.abs rescue 0 + diff_hunk = Gitlab::WordDiff::Segments::DiffHunk.new(line) + line_old = diff_hunk.pos_old + line_new = diff_hunk.pos_new + # not using diff_hunk.first_line? because of defaults next if line_old <= 1 && line_new <= 1 # top of file yielder << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new, parent_file: diff_file) diff --git a/lib/gitlab/github_import/importer/issue_importer.rb b/lib/gitlab/github_import/importer/issue_importer.rb index e7d41856b04..d964bae3dd2 100644 --- a/lib/gitlab/github_import/importer/issue_importer.rb +++ b/lib/gitlab/github_import/importer/issue_importer.rb @@ -56,7 +56,8 @@ module Gitlab milestone_id: milestone_finder.id_for(issue), state_id: ::Issue.available_states[issue.state], created_at: issue.created_at, - updated_at: issue.updated_at + updated_at: issue.updated_at, + work_item_type_id: issue.work_item_type_id } insert_and_return_id(attributes, project.issues) diff --git a/lib/gitlab/github_import/importer/issues_importer.rb b/lib/gitlab/github_import/importer/issues_importer.rb index 6cc1a61b332..21d9ce8cd2d 100644 --- a/lib/gitlab/github_import/importer/issues_importer.rb +++ b/lib/gitlab/github_import/importer/issues_importer.rb @@ -6,6 +6,12 @@ module Gitlab class IssuesImporter include ParallelScheduling + def initialize(project, client, parallel: true) + super + + @work_item_type_id = ::WorkItems::Type.default_issue_type.id + end + def importer_class IssueAndLabelLinksImporter end @@ -33,6 +39,12 @@ module Gitlab def collection_options { state: 'all', sort: 'created', direction: 'asc' } end + + private + + def additional_object_data + { work_item_type_id: @work_item_type_id } + end end end end diff --git a/lib/gitlab/github_import/parallel_scheduling.rb b/lib/gitlab/github_import/parallel_scheduling.rb index ab20b372d53..a8c18c74d24 100644 --- a/lib/gitlab/github_import/parallel_scheduling.rb +++ b/lib/gitlab/github_import/parallel_scheduling.rb @@ -63,7 +63,7 @@ module Gitlab # Imports all the objects in sequence in the current thread. def sequential_import each_object_to_import do |object| - repr = representation_class.from_api_response(object) + repr = representation_class.from_api_response(object, additional_object_data) importer_class.new(repr, project, client).execute end @@ -72,26 +72,9 @@ module Gitlab # Imports all objects in parallel by scheduling a Sidekiq job for every # individual object. def parallel_import - if parallel_import_batch.present? - spread_parallel_import - else - parallel_import_deprecated - end - end - - def parallel_import_deprecated - waiter = JobWaiter.new - - each_object_to_import do |object| - repr = representation_class.from_api_response(object) - - sidekiq_worker_class - .perform_async(project.id, repr.to_hash, waiter.key) + raise 'Batch settings must be defined for parallel import' if parallel_import_batch.blank? - waiter.jobs_remaining += 1 - end - - waiter + spread_parallel_import end def spread_parallel_import @@ -100,7 +83,7 @@ module Gitlab import_arguments = [] each_object_to_import do |object| - repr = representation_class.from_api_response(object) + repr = representation_class.from_api_response(object, additional_object_data) import_arguments << [project.id, repr.to_hash, waiter.key] @@ -223,6 +206,10 @@ module Gitlab private + def additional_object_data + {} + end + def info(project_id, extra = {}) Logger.info(log_attributes(project_id, extra)) end diff --git a/lib/gitlab/github_import/representation/diff_note.rb b/lib/gitlab/github_import/representation/diff_note.rb index 883abef9bdb..64aa6ea5cb4 100644 --- a/lib/gitlab/github_import/representation/diff_note.rb +++ b/lib/gitlab/github_import/representation/diff_note.rb @@ -20,7 +20,7 @@ module Gitlab # Builds a diff note from a GitHub API response. # # note - An instance of `Sawyer::Resource` containing the note details. - def self.from_api_response(note) + def self.from_api_response(note, additional_data = {}) matches = note.html_url.match(NOTEABLE_ID_REGEX) unless matches diff --git a/lib/gitlab/github_import/representation/issue.rb b/lib/gitlab/github_import/representation/issue.rb index db4a8188c03..9d457ec1c2f 100644 --- a/lib/gitlab/github_import/representation/issue.rb +++ b/lib/gitlab/github_import/representation/issue.rb @@ -11,13 +11,13 @@ module Gitlab expose_attribute :iid, :title, :description, :milestone_number, :created_at, :updated_at, :state, :assignees, - :label_names, :author + :label_names, :author, :work_item_type_id # Builds an issue from a GitHub API response. # # issue - An instance of `Sawyer::Resource` containing the issue # details. - def self.from_api_response(issue) + def self.from_api_response(issue, additional_data = {}) user = if issue.user Representation::User.from_api_response(issue.user) @@ -36,7 +36,8 @@ module Gitlab author: user, created_at: issue.created_at, updated_at: issue.updated_at, - pull_request: issue.pull_request ? true : false + pull_request: issue.pull_request ? true : false, + work_item_type_id: additional_data[:work_item_type_id] } new(hash) diff --git a/lib/gitlab/github_import/representation/issue_event.rb b/lib/gitlab/github_import/representation/issue_event.rb index b01887f50ee..67a5df73a97 100644 --- a/lib/gitlab/github_import/representation/issue_event.rb +++ b/lib/gitlab/github_import/representation/issue_event.rb @@ -34,7 +34,7 @@ module Gitlab # Builds an event from a GitHub API response. # # event - An instance of `Sawyer::Resource` containing the event details. - def from_api_response(event) + def from_api_response(event, additional_data = {}) new( id: event.id, actor: user_representation(event.actor), diff --git a/lib/gitlab/github_import/representation/lfs_object.rb b/lib/gitlab/github_import/representation/lfs_object.rb index 18737bfcde3..cd614db2161 100644 --- a/lib/gitlab/github_import/representation/lfs_object.rb +++ b/lib/gitlab/github_import/representation/lfs_object.rb @@ -12,7 +12,7 @@ module Gitlab expose_attribute :oid, :link, :size # Builds a lfs_object - def self.from_api_response(lfs_object) + def self.from_api_response(lfs_object, additional_data = {}) new( oid: lfs_object.oid, link: lfs_object.link, diff --git a/lib/gitlab/github_import/representation/note.rb b/lib/gitlab/github_import/representation/note.rb index bbf20b7e9e6..ae56c370b19 100644 --- a/lib/gitlab/github_import/representation/note.rb +++ b/lib/gitlab/github_import/representation/note.rb @@ -17,7 +17,7 @@ module Gitlab # Builds a note from a GitHub API response. # # note - An instance of `Sawyer::Resource` containing the note details. - def self.from_api_response(note) + def self.from_api_response(note, additional_data = {}) matches = note.html_url.match(NOTEABLE_TYPE_REGEX) if !matches || !matches[:type] diff --git a/lib/gitlab/github_import/representation/pull_request.rb b/lib/gitlab/github_import/representation/pull_request.rb index 82bcdee8b2b..2adac2af502 100644 --- a/lib/gitlab/github_import/representation/pull_request.rb +++ b/lib/gitlab/github_import/representation/pull_request.rb @@ -18,7 +18,7 @@ module Gitlab # Builds a PR from a GitHub API response. # # issue - An instance of `Sawyer::Resource` containing the PR details. - def self.from_api_response(pr) + def self.from_api_response(pr, additional_data = {}) assignee = Representation::User.from_api_response(pr.assignee) if pr.assignee user = Representation::User.from_api_response(pr.user) if pr.user merged_by = Representation::User.from_api_response(pr.merged_by) if pr.merged_by diff --git a/lib/gitlab/github_import/representation/pull_request_review.rb b/lib/gitlab/github_import/representation/pull_request_review.rb index 70c1e51ffdd..8a7ecf0c588 100644 --- a/lib/gitlab/github_import/representation/pull_request_review.rb +++ b/lib/gitlab/github_import/representation/pull_request_review.rb @@ -11,7 +11,7 @@ module Gitlab expose_attribute :author, :note, :review_type, :submitted_at, :merge_request_id, :review_id - def self.from_api_response(review) + def self.from_api_response(review, additional_data = {}) user = Representation::User.from_api_response(review.user) if review.user new( diff --git a/lib/gitlab/github_import/representation/user.rb b/lib/gitlab/github_import/representation/user.rb index fac8920a3f2..4ef916cc41c 100644 --- a/lib/gitlab/github_import/representation/user.rb +++ b/lib/gitlab/github_import/representation/user.rb @@ -14,7 +14,7 @@ module Gitlab # Builds a user from a GitHub API response. # # user - An instance of `Sawyer::Resource` containing the user details. - def self.from_api_response(user) + def self.from_api_response(user, additional_data = {}) new( id: user.id, login: user.login diff --git a/lib/gitlab/i18n.rb b/lib/gitlab/i18n.rb index cad0e773b05..0c3c9060b46 100644 --- a/lib/gitlab/i18n.rb +++ b/lib/gitlab/i18n.rb @@ -67,7 +67,7 @@ module Gitlab 'uk' => 49, 'zh_CN' => 99, 'zh_HK' => 2, - 'zh_TW' => 4 + 'zh_TW' => 100 }.freeze private_constant :TRANSLATION_LEVELS diff --git a/lib/gitlab/import_export/after_export_strategy_builder.rb b/lib/gitlab/import_export/after_export_strategy_builder.rb index d7b30f46903..90618922dfe 100644 --- a/lib/gitlab/import_export/after_export_strategy_builder.rb +++ b/lib/gitlab/import_export/after_export_strategy_builder.rb @@ -9,7 +9,11 @@ module Gitlab return default_strategy.new unless strategy_klass attributes ||= {} - klass = strategy_klass.constantize rescue nil + klass = begin + strategy_klass.constantize + rescue StandardError + nil + end unless klass && klass < AfterExportStrategies::BaseAfterExportStrategy raise StrategyNotFoundError, "Strategy #{strategy_klass} not found" diff --git a/lib/gitlab/kubernetes.rb b/lib/gitlab/kubernetes.rb index 22bd00751bc..15163bd4a57 100644 --- a/lib/gitlab/kubernetes.rb +++ b/lib/gitlab/kubernetes.rb @@ -63,7 +63,11 @@ module Gitlab return unless containers.present? && pod_name.present? && phase == "Running" - created_at = DateTime.parse(metadata["creationTimestamp"]) rescue nil + created_at = begin + DateTime.parse(metadata["creationTimestamp"]) + rescue StandardError + nil + end containers.map do |container| { diff --git a/lib/gitlab/middleware/read_only/controller.rb b/lib/gitlab/middleware/read_only/controller.rb index 65c08664a2b..69e2ae55cb0 100644 --- a/lib/gitlab/middleware/read_only/controller.rb +++ b/lib/gitlab/middleware/read_only/controller.rb @@ -83,7 +83,11 @@ module Gitlab end def route_hash - @route_hash ||= Rails.application.routes.recognize_path(request_url, { method: request.request_method }) rescue {} + @route_hash ||= begin + Rails.application.routes.recognize_path(request_url, { method: request.request_method }) + rescue StandardError + {} + end end def request_url diff --git a/lib/gitlab/process_management.rb b/lib/gitlab/process_management.rb index 25a198e4a6a..f8a1a3a97de 100644 --- a/lib/gitlab/process_management.rb +++ b/lib/gitlab/process_management.rb @@ -43,7 +43,9 @@ module Gitlab # Waits for the given process to complete using a separate thread. def self.wait_async(pid) Thread.new do - Process.wait(pid) rescue Errno::ECHILD + Process.wait(pid) + rescue StandardError + nil # There is no reason to return `Errno::ECHILD` if it catches a `TypeError` end end diff --git a/lib/gitlab/query_limiting/middleware.rb b/lib/gitlab/query_limiting/middleware.rb index 76de547b14f..0ee700caf5b 100644 --- a/lib/gitlab/query_limiting/middleware.rb +++ b/lib/gitlab/query_limiting/middleware.rb @@ -46,7 +46,11 @@ module Gitlab def action_for_grape(env) endpoint = env[ENDPOINT_KEY] - route = endpoint.route rescue nil + route = begin + endpoint.route + rescue StandardError + nil + end "#{route.request_method} #{route.path}" if route end diff --git a/lib/gitlab/quick_actions/command_definition.rb b/lib/gitlab/quick_actions/command_definition.rb index fcb7bc967ca..d9135d1bacb 100644 --- a/lib/gitlab/quick_actions/command_definition.rb +++ b/lib/gitlab/quick_actions/command_definition.rb @@ -89,17 +89,29 @@ module Gitlab def to_h(context) desc = description if desc.respond_to?(:call) - desc = context.instance_exec(&desc) rescue '' + desc = begin + context.instance_exec(&desc) + rescue StandardError + '' + end end warn = warning if warn.respond_to?(:call) - warn = context.instance_exec(&warn) rescue '' + warn = begin + context.instance_exec(&warn) + rescue StandardError + '' + end end prms = params if prms.respond_to?(:call) - prms = Array(context.instance_exec(&prms)) rescue params + prms = begin + Array(context.instance_exec(&prms)) + rescue StandardError + params + end end { diff --git a/lib/gitlab/quick_actions/spend_time_and_date_separator.rb b/lib/gitlab/quick_actions/spend_time_and_date_separator.rb index 03b2a1086bb..3794f2f8818 100644 --- a/lib/gitlab/quick_actions/spend_time_and_date_separator.rb +++ b/lib/gitlab/quick_actions/spend_time_and_date_separator.rb @@ -43,7 +43,11 @@ module Gitlab def valid_date? string_date = @spend_arg.match(DATE_REGEX)[0] - date = Date.parse(string_date) rescue nil + date = begin + Date.parse(string_date) + rescue StandardError + nil + end date_past_or_today?(date) end diff --git a/lib/gitlab/word_diff/segments/diff_hunk.rb b/lib/gitlab/word_diff/segments/diff_hunk.rb index 88b6817676f..13f71f2bc04 100644 --- a/lib/gitlab/word_diff/segments/diff_hunk.rb +++ b/lib/gitlab/word_diff/segments/diff_hunk.rb @@ -16,11 +16,15 @@ module Gitlab end def pos_old - line.match(/\-[0-9]*/)[0].to_i.abs rescue 0 + line.match(/\-[0-9]*/)[0].to_i.abs + rescue StandardError + 0 end def pos_new - line.match(/\+[0-9]*/)[0].to_i.abs rescue 0 + line.match(/\+[0-9]*/)[0].to_i.abs + rescue StandardError + 0 end def first_line? diff --git a/lib/gitlab/zentao/client.rb b/lib/gitlab/zentao/client.rb index 4da4631eecf..0c2b3049670 100644 --- a/lib/gitlab/zentao/client.rb +++ b/lib/gitlab/zentao/client.rb @@ -15,7 +15,11 @@ module Gitlab end def ping - response = fetch_product(zentao_product_xid) rescue {} + response = begin + fetch_product(zentao_product_xid) + rescue StandardError + {} + end active = response['deleted'] == '0' if active { success: true } diff --git a/lib/tasks/gitlab/praefect.rake b/lib/tasks/gitlab/praefect.rake index 28b70f8986e..0a34a004690 100644 --- a/lib/tasks/gitlab/praefect.rake +++ b/lib/tasks/gitlab/praefect.rake @@ -3,7 +3,9 @@ namespace :gitlab do namespace :praefect do def int?(string) - true if Integer(string) rescue false + true if Integer(string) + rescue StandardError + false end def print_checksums(header, row) diff --git a/qa/qa/page/component/access_tokens.rb b/qa/qa/page/component/access_tokens.rb index f143e5b9e1f..6f0ff436439 100644 --- a/qa/qa/page/component/access_tokens.rb +++ b/qa/qa/page/component/access_tokens.rb @@ -54,7 +54,11 @@ module QA def fill_expiry_date(date) date = date.to_s if date.is_a?(Date) - Date.strptime(date, '%Y-%m-%d') rescue ArgumentError raise "Expiry date must be in YYYY-MM-DD format" + begin + Date.strptime(date, '%Y-%m-%d') + rescue ArgumentError + raise "Expiry date must be in YYYY-MM-DD format" + end fill_element(:expiry_date_field, date) end diff --git a/qa/qa/page/profile/ssh_keys.rb b/qa/qa/page/profile/ssh_keys.rb index 8da484003f4..db71062cec6 100644 --- a/qa/qa/page/profile/ssh_keys.rb +++ b/qa/qa/page/profile/ssh_keys.rb @@ -31,7 +31,11 @@ module QA def fill_expiry_date(date) date = date.strftime('%m/%d/%Y') if date.is_a?(Date) - Date.strptime(date, '%m/%d/%Y') rescue ArgumentError raise "Expiry date must be in mm/dd/yyyy format" + begin + Date.strptime(date, '%m/%d/%Y') + rescue ArgumentError + raise "Expiry date must be in mm/dd/yyyy format" + end fill_element(:key_expiry_date_field, date) end diff --git a/spec/finders/concerns/finder_with_cross_project_access_spec.rb b/spec/finders/concerns/finder_with_cross_project_access_spec.rb index 0798528c200..a4b483a8e5e 100644 --- a/spec/finders/concerns/finder_with_cross_project_access_spec.rb +++ b/spec/finders/concerns/finder_with_cross_project_access_spec.rb @@ -97,7 +97,11 @@ RSpec.describe FinderWithCrossProjectAccess do end it 're-enables the check after the find failed' do - finder.find(non_existing_record_id) rescue ActiveRecord::RecordNotFound + begin + finder.find(non_existing_record_id) + rescue ActiveRecord::RecordNotFound + nil + end expect(finder.instance_variable_get(:@should_skip_cross_project_check)) .to eq(false) diff --git a/spec/lib/gitlab/database/load_balancing/session_spec.rb b/spec/lib/gitlab/database/load_balancing/session_spec.rb index 74512f76fd4..05b44579c62 100644 --- a/spec/lib/gitlab/database/load_balancing/session_spec.rb +++ b/spec/lib/gitlab/database/load_balancing/session_spec.rb @@ -132,7 +132,11 @@ RSpec.describe Gitlab::Database::LoadBalancing::Session do it 'does not prevent using primary if an exception is raised' do instance = described_class.new - instance.ignore_writes { raise ArgumentError } rescue ArgumentError + begin + instance.ignore_writes { raise ArgumentError } + rescue ArgumentError + nil + end instance.write! expect(instance).to be_using_primary diff --git a/spec/lib/gitlab/database/migrations/instrumentation_spec.rb b/spec/lib/gitlab/database/migrations/instrumentation_spec.rb index c31244060ec..3540a120b8f 100644 --- a/spec/lib/gitlab/database/migrations/instrumentation_spec.rb +++ b/spec/lib/gitlab/database/migrations/instrumentation_spec.rb @@ -122,7 +122,11 @@ RSpec.describe Gitlab::Database::Migrations::Instrumentation do it 'records observations for all migrations' do subject.observe(version: migration_version, name: migration_name, connection: connection) {} - subject.observe(version: migration_version_2, name: migration_name_2, connection: connection) { raise 'something went wrong' } rescue nil + begin + subject.observe(version: migration_version_2, name: migration_name_2, connection: connection) { raise 'something went wrong' } + rescue StandardError + nil + end expect { load_observation(result_dir, migration_name) }.not_to raise_error expect { load_observation(result_dir, migration_name_2) }.not_to raise_error diff --git a/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb b/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb index b282e2f9de8..08a7383700b 100644 --- a/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb +++ b/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb @@ -493,11 +493,19 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do end it 'does not create an issue' do - expect { receiver.execute rescue nil }.not_to change { Issue.count } + expect do + receiver.execute + rescue StandardError + nil + end.not_to change { Issue.count } end it 'does not send thank you email' do - expect { receiver.execute rescue nil }.not_to have_enqueued_job.on_queue('mailers') + expect do + receiver.execute + rescue StandardError + nil + end.not_to have_enqueued_job.on_queue('mailers') end end @@ -540,7 +548,11 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do end it "doesn't create an issue" do - expect { receiver.execute rescue nil }.not_to change { Issue.count } + expect do + receiver.execute + rescue StandardError + nil + end.not_to change { Issue.count } end end end diff --git a/spec/lib/gitlab/github_import/importer/issue_importer_spec.rb b/spec/lib/gitlab/github_import/importer/issue_importer_spec.rb index 570d26cdf2d..1692aac49f2 100644 --- a/spec/lib/gitlab/github_import/importer/issue_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/issue_importer_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Importer::IssueImporter, :clean_gitlab_redis_cache do + let_it_be(:work_item_type_id) { ::WorkItems::Type.default_issue_type.id } + let(:project) { create(:project) } let(:client) { double(:client) } let(:user) { create(:user) } @@ -25,7 +27,8 @@ RSpec.describe Gitlab::GithubImport::Importer::IssueImporter, :clean_gitlab_redi author: Gitlab::GithubImport::Representation::User.new(id: 4, login: 'alice'), created_at: created_at, updated_at: updated_at, - pull_request: false + pull_request: false, + work_item_type_id: work_item_type_id ) end @@ -116,6 +119,17 @@ RSpec.describe Gitlab::GithubImport::Importer::IssueImporter, :clean_gitlab_redi .and_return(milestone.id) end + it 'creates issues with a work item type id' do + allow(importer.user_finder) + .to receive(:author_id_for) + .with(issue) + .and_return([user.id, true]) + + issue_id = importer.create_issue + + expect(Issue.find(issue_id).work_item_type_id).to eq(work_item_type_id) + end + context 'when the issue author could be found' do it 'creates the issue with the found author as the issue author' do allow(importer.user_finder) @@ -136,7 +150,8 @@ RSpec.describe Gitlab::GithubImport::Importer::IssueImporter, :clean_gitlab_redi milestone_id: milestone.id, state_id: 1, created_at: created_at, - updated_at: updated_at + updated_at: updated_at, + work_item_type_id: work_item_type_id }, project.issues ) @@ -166,7 +181,8 @@ RSpec.describe Gitlab::GithubImport::Importer::IssueImporter, :clean_gitlab_redi milestone_id: milestone.id, state_id: 1, created_at: created_at, - updated_at: updated_at + updated_at: updated_at, + work_item_type_id: work_item_type_id }, project.issues ) diff --git a/spec/lib/gitlab/github_import/parallel_scheduling_spec.rb b/spec/lib/gitlab/github_import/parallel_scheduling_spec.rb index 999f8ffb21e..738e7c88d7d 100644 --- a/spec/lib/gitlab/github_import/parallel_scheduling_spec.rb +++ b/spec/lib/gitlab/github_import/parallel_scheduling_spec.rb @@ -243,7 +243,7 @@ RSpec.describe Gitlab::GithubImport::ParallelScheduling do expect(repr_class) .to receive(:from_api_response) - .with(object) + .with(object, {}) .and_return(repr_instance) expect(importer) @@ -281,7 +281,7 @@ RSpec.describe Gitlab::GithubImport::ParallelScheduling do allow(repr_class) .to receive(:from_api_response) - .with(object) + .with(object, {}) .and_return({ title: 'Foo' }) end diff --git a/spec/lib/gitlab/github_import/representation/issue_spec.rb b/spec/lib/gitlab/github_import/representation/issue_spec.rb index f3052efea70..5898518343a 100644 --- a/spec/lib/gitlab/github_import/representation/issue_spec.rb +++ b/spec/lib/gitlab/github_import/representation/issue_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Representation::Issue do + let_it_be(:work_item_type_id) { ::WorkItems::Type.default_issue_type.id } + let(:created_at) { Time.new(2017, 1, 1, 12, 00) } let(:updated_at) { Time.new(2017, 1, 1, 12, 15) } @@ -60,6 +62,10 @@ RSpec.describe Gitlab::GithubImport::Representation::Issue do expect(issue.updated_at).to eq(updated_at) end + it 'includes the work_item_type_id' do + expect(issue.work_item_type_id).to eq(work_item_type_id) + end + it 'is not a pull request' do expect(issue.pull_request?).to eq(false) end @@ -84,8 +90,10 @@ RSpec.describe Gitlab::GithubImport::Representation::Issue do ) end + let(:additional_data) { { work_item_type_id: work_item_type_id } } + it_behaves_like 'an Issue' do - let(:issue) { described_class.from_api_response(response) } + let(:issue) { described_class.from_api_response(response, additional_data) } end it 'does not set the user if the response did not include a user' do @@ -93,7 +101,7 @@ RSpec.describe Gitlab::GithubImport::Representation::Issue do .to receive(:user) .and_return(nil) - issue = described_class.from_api_response(response) + issue = described_class.from_api_response(response, additional_data) expect(issue.author).to be_nil end @@ -113,7 +121,8 @@ RSpec.describe Gitlab::GithubImport::Representation::Issue do 'author' => { 'id' => 4, 'login' => 'alice' }, 'created_at' => created_at.to_s, 'updated_at' => updated_at.to_s, - 'pull_request' => false + 'pull_request' => false, + 'work_item_type_id' => work_item_type_id } end diff --git a/spec/lib/gitlab/sidekiq_middleware/monitor_spec.rb b/spec/lib/gitlab/sidekiq_middleware/monitor_spec.rb index 85cddfa7bf1..d61c9765753 100644 --- a/spec/lib/gitlab/sidekiq_middleware/monitor_spec.rb +++ b/spec/lib/gitlab/sidekiq_middleware/monitor_spec.rb @@ -41,7 +41,9 @@ RSpec.describe Gitlab::SidekiqMiddleware::Monitor do ::Sidekiq::DeadSet.new.clear expect do - subject rescue Sidekiq::JobRetry::Skip + subject + rescue Sidekiq::JobRetry::Skip + nil end.to change { ::Sidekiq::DeadSet.new.size }.by(1) end end diff --git a/spec/models/concerns/bulk_insert_safe_spec.rb b/spec/models/concerns/bulk_insert_safe_spec.rb index e6b197f34ca..569dc3a3a3e 100644 --- a/spec/models/concerns/bulk_insert_safe_spec.rb +++ b/spec/models/concerns/bulk_insert_safe_spec.rb @@ -170,7 +170,9 @@ RSpec.describe BulkInsertSafe do all_items = bulk_insert_item_class.valid_list(10) + bulk_insert_item_class.invalid_list(10) expect do - bulk_insert_item_class.bulk_insert!(all_items, batch_size: 2) rescue nil + bulk_insert_item_class.bulk_insert!(all_items, batch_size: 2) + rescue StandardError + nil end.not_to change { bulk_insert_item_class.count } end diff --git a/spec/models/design_management/version_spec.rb b/spec/models/design_management/version_spec.rb index 303bac61e1e..519ba3c67b4 100644 --- a/spec/models/design_management/version_spec.rb +++ b/spec/models/design_management/version_spec.rb @@ -142,14 +142,18 @@ RSpec.describe DesignManagement::Version do it 'does not leave invalid versions around if creation fails' do expect do - described_class.create_for_designs([], 'abcdef', author) rescue nil + described_class.create_for_designs([], 'abcdef', author) + rescue StandardError + nil end.not_to change { described_class.count } end it 'does not leave orphaned design-versions around if creation fails' do actions = as_actions(designs) expect do - described_class.create_for_designs(actions, '', author) rescue nil + described_class.create_for_designs(actions, '', author) + rescue StandardError + nil end.not_to change { DesignManagement::Action.count } end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 5b0466c46a2..5e4685ac148 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -2603,7 +2603,11 @@ RSpec.describe Group do it 'does not enable shared runners' do expect do - subject rescue nil + begin + subject + rescue StandardError + nil + end parent.reload group.reload @@ -2704,7 +2708,11 @@ RSpec.describe Group do it 'does not allow descendants to override' do expect do - subject rescue nil + begin + subject + rescue StandardError + nil + end parent.reload group.reload diff --git a/spec/models/integrations/slack_spec.rb b/spec/models/integrations/slack_spec.rb index 5801a4c3749..ed282f1d39d 100644 --- a/spec/models/integrations/slack_spec.rb +++ b/spec/models/integrations/slack_spec.rb @@ -6,7 +6,8 @@ RSpec.describe Integrations::Slack do it_behaves_like Integrations::SlackMattermostNotifier, "Slack" describe '#execute' do - let_it_be(:slack_integration) { create(:integrations_slack, branches_to_be_notified: 'all') } + let(:slack_integration) { create(:integrations_slack, branches_to_be_notified: 'all', project_id: project.id) } + let(:project) { create_default(:project, :repository, :wiki_repo) } before do stub_request(:post, slack_integration.webhook) @@ -20,13 +21,23 @@ RSpec.describe Integrations::Slack do context 'hook data includes a user object' do let_it_be(:user) { create_default(:user) } - let_it_be(:project) { create_default(:project, :repository, :wiki_repo) } shared_examples 'increases the usage data counter' do |event_name| + subject(:execute) { slack_integration.execute(data) } + it 'increases the usage data counter' do expect(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).with(event_name, values: user.id).and_call_original - slack_integration.execute(data) + execute + end + + it_behaves_like 'Snowplow event tracking' do + let(:feature_flag_name) { :route_hll_to_snowplow_phase2 } + let(:category) { 'Integrations::Slack' } + let(:action) { 'perform_integrations_action' } + let(:namespace) { project.namespace } + let(:label) { 'redis_hll_counters.ecosystem.ecosystem_total_unique_counts_monthly' } + let(:property) { event_name } end end diff --git a/spec/models/namespace/traversal_hierarchy_spec.rb b/spec/models/namespace/traversal_hierarchy_spec.rb index 51932ab943c..918ff6aa154 100644 --- a/spec/models/namespace/traversal_hierarchy_spec.rb +++ b/spec/models/namespace/traversal_hierarchy_spec.rb @@ -85,7 +85,11 @@ RSpec.describe Namespace::TraversalHierarchy, type: :model do it { expect { subject }.to raise_error(ActiveRecord::Deadlocked) } it 'increment db_deadlock counter' do - expect { subject rescue nil }.to change { db_deadlock_total('Namespace#sync_traversal_ids!') }.by(1) + expect do + subject + rescue StandardError + nil + end.to change { db_deadlock_total('Namespace#sync_traversal_ids!') }.by(1) end end end diff --git a/spec/presenters/merge_request_presenter_spec.rb b/spec/presenters/merge_request_presenter_spec.rb index 798bee70e42..31aa4778d3c 100644 --- a/spec/presenters/merge_request_presenter_spec.rb +++ b/spec/presenters/merge_request_presenter_spec.rb @@ -17,29 +17,8 @@ RSpec.describe MergeRequestPresenter do allow(resource).to receive(:mergeable_discussions_state?).and_return(discussions_state) end - context 'when change_response_code_merge_status is enabled' do - it 'returns the mergeable_discussions_state' do - is_expected.to eq(discussions_state) - end - end - - context 'when change_response_code_merge_status is disabled' do - before do - stub_feature_flags(change_response_code_merge_status: false) - end - - context 'when it is not mergeable' do - it 'returns false' do - resource.close! - is_expected.to eq(false) - end - end - - context 'when it is mergeable' do - it 'returns the mergeable_discussions_state' do - is_expected.to eq(discussions_state) - end - end + it 'returns the mergeable_discussions_state' do + is_expected.to eq(discussions_state) end end diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index 698fe955ae3..fc138743b7b 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -2500,38 +2500,19 @@ RSpec.describe API::MergeRequests do .not_to change { merge_request.reload.merged? } expect(response).to have_gitlab_http_status(:unprocessable_entity) - expect(json_response['message']).to eq("Failed to merge branch") + expect(json_response['message']).to eq("Branch cannot be merged") end end - context 'when change_response_code_merge_status is enabled' do - it "returns 422 if branch can't be merged" do - allow_next_found_instance_of(MergeRequest) do |merge_request| - allow(merge_request).to receive(:can_be_merged?).and_return(false) - end - - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user) - - expect(response).to have_gitlab_http_status(:unprocessable_entity) - expect(json_response['message']).to eq('Branch cannot be merged') - end - end - - context 'when change_response_code_merge_status is disabled' do - before do - stub_feature_flags(change_response_code_merge_status: false) + it "returns 422 if branch can't be merged" do + allow_next_found_instance_of(MergeRequest) do |merge_request| + allow(merge_request).to receive(:can_be_merged?).and_return(false) end - it "returns 406 if branch can't be merged" do - allow_next_found_instance_of(MergeRequest) do |merge_request| - allow(merge_request).to receive(:can_be_merged?).and_return(false) - end - - put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user) + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user) - expect(response).to have_gitlab_http_status(:not_acceptable) - expect(json_response['message']).to eq('Branch cannot be merged') - end + expect(response).to have_gitlab_http_status(:unprocessable_entity) + expect(json_response['message']).to eq('Branch cannot be merged') end it "returns 405 if merge_request is not open" do diff --git a/spec/serializers/merge_request_poll_widget_entity_spec.rb b/spec/serializers/merge_request_poll_widget_entity_spec.rb index 409585e52f1..90a82d16e38 100644 --- a/spec/serializers/merge_request_poll_widget_entity_spec.rb +++ b/spec/serializers/merge_request_poll_widget_entity_spec.rb @@ -184,38 +184,8 @@ RSpec.describe MergeRequestPollWidgetEntity do end describe '#mergeable_discussions_state?' do - context 'when change_response_code_merge_status is true' do - before do - stub_feature_flags(change_response_code_merge_status: true) - end - - it 'returns mergeable discussions state' do - expect(subject[:mergeable_discussions_state]).to eq(true) - end - end - - context 'when change_response_code_merge_status is false' do - context 'when merge request is in a mergeable state' do - before do - stub_feature_flags(change_response_code_merge_status: false) - allow(resource).to receive(:mergeable_discussions_state?).and_return(true) - end - - it 'returns mergeable discussions state' do - expect(subject[:mergeable_discussions_state]).to eq(true) - end - end - - context 'when merge request is not in a mergeable state' do - before do - stub_feature_flags(change_response_code_merge_status: false) - allow(resource).to receive(:mergeable_state?).and_return(false) - end - - it 'returns mergeable discussions state' do - expect(subject[:mergeable_discussions_state]).to eq(false) - end - end + it 'returns mergeable discussions state' do + expect(subject[:mergeable_discussions_state]).to eq(true) end end end diff --git a/spec/services/design_management/delete_designs_service_spec.rb b/spec/services/design_management/delete_designs_service_spec.rb index bc7625d7c28..a0e049ea42a 100644 --- a/spec/services/design_management/delete_designs_service_spec.rb +++ b/spec/services/design_management/delete_designs_service_spec.rb @@ -59,7 +59,11 @@ RSpec.describe DesignManagement::DeleteDesignsService do it_behaves_like "a service error" it 'does not create any events in the activity stream' do - expect { run_service rescue nil }.not_to change { Event.count } + expect do + run_service + rescue StandardError + nil + end.not_to change { Event.count } end end @@ -78,7 +82,11 @@ RSpec.describe DesignManagement::DeleteDesignsService do it 'does not log any events' do counter = ::Gitlab::UsageDataCounters::DesignsCounter - expect { run_service rescue nil } + expect do + run_service + rescue StandardError + nil + end .not_to change { [counter.totals, Event.count] } end @@ -86,10 +94,18 @@ RSpec.describe DesignManagement::DeleteDesignsService do redis_hll = ::Gitlab::UsageDataCounters::HLLRedisCounter event = Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_DESIGNS_REMOVED - expect { run_service rescue nil } + expect do + run_service + rescue StandardError + nil + end .not_to change { redis_hll.unique_events(event_names: event, start_date: 1.day.ago, end_date: 1.day.from_now) } - run_service rescue nil + begin + run_service + rescue StandardError + nil + end end end diff --git a/spec/support/shared_examples/lib/gitlab/config/inheritable_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/config/inheritable_shared_examples.rb index 95772b1774a..5eae8777a20 100644 --- a/spec/support/shared_examples/lib/gitlab/config/inheritable_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/config/inheritable_shared_examples.rb @@ -86,7 +86,10 @@ RSpec.shared_examples 'with inheritable CI config' do expect do # we ignore exceptions as `#overwrite_entry` # can raise exception on duplicates - entry.send(:inherit!, deps) rescue described_class::InheritError + + entry.send(:inherit!, deps) + rescue described_class::InheritError + nil end.not_to change { entry[entry_key] } end end |