Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2022-08-09 12:11:57 +00:00
parent 7a98d98974
commit 1f229cdc22
70 changed files with 381 additions and 282 deletions

View File

@ -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'

View File

@ -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>

View File

@ -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}"

View File

@ -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 = []

View File

@ -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

View File

@ -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

View File

@ -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?

View File

@ -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)

View File

@ -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,

View File

@ -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

View File

@ -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?

View File

@ -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)

View File

@ -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

View File

@ -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?

View File

@ -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|

View File

@ -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

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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).

View File

@ -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.

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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?

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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
raise 'Batch settings must be defined for parallel import' if parallel_import_batch.blank?
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)
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

View File

@ -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

View File

@ -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)

View File

@ -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),

View File

@ -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,

View File

@ -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]

View File

@ -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

View File

@ -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(

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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|
{

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
{

View File

@ -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

View File

@ -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?

View File

@ -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 }

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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