diff options
35 files changed, 111 insertions, 80 deletions
diff --git a/.gitlab/ci/docs.gitlab-ci.yml b/.gitlab/ci/docs.gitlab-ci.yml index cd0e4085e10..c776e546f11 100644 --- a/.gitlab/ci/docs.gitlab-ci.yml +++ b/.gitlab/ci/docs.gitlab-ci.yml @@ -11,7 +11,10 @@ stage: review dependencies: [] variables: - GIT_STRATEGY: none + # We're cloning the repo instead of downloading the script for now + # because some repos are private and CI_JOB_TOKEN cannot access files. + # See https://gitlab.com/gitlab-org/gitlab/issues/191273 + GIT_DEPTH: 1 environment: name: review-docs/$DOCS_GITLAB_REPO_SUFFIX-$CI_MERGE_REQUEST_IID # DOCS_REVIEW_APPS_DOMAIN and DOCS_GITLAB_REPO_SUFFIX are CI variables @@ -19,11 +22,7 @@ url: http://docs-preview-$DOCS_GITLAB_REPO_SUFFIX-$CI_MERGE_REQUEST_IID.$DOCS_REVIEW_APPS_DOMAIN/$DOCS_GITLAB_REPO_SUFFIX on_stop: review-docs-cleanup before_script: - # We don't clone the repo by using GIT_STRATEGY: none and only download the - # single script we need here so it's much faster than cloning. - apk add --update openssl - - wget $CI_PROJECT_URL/raw/$CI_COMMIT_SHA/scripts/trigger-build-docs - - chmod 755 trigger-build-docs - gem install httparty --no-document --version 0.17.3 - gem install gitlab --no-document --version 4.13.0 @@ -32,7 +31,7 @@ review-docs-deploy: extends: .review-docs script: - - ./trigger-build-docs deploy + - ./scripts/trigger-build-docs deploy when: manual # Cleanup remote environment of gitlab-docs @@ -42,7 +41,7 @@ review-docs-cleanup: name: review-docs/$DOCS_GITLAB_REPO_SUFFIX-$CI_MERGE_REQUEST_IID action: stop script: - - ./trigger-build-docs cleanup + - ./scripts/trigger-build-docs cleanup when: manual docs lint: diff --git a/.gitlab/ci/review.gitlab-ci.yml b/.gitlab/ci/review.gitlab-ci.yml index 53311ab08d3..43686a5c8e7 100644 --- a/.gitlab/ci/review.gitlab-ci.yml +++ b/.gitlab/ci/review.gitlab-ci.yml @@ -171,15 +171,14 @@ schedule:review-deploy: environment: action: stop variables: - GIT_STRATEGY: none + # We're cloning the repo instead of downloading the script for now + # because some repos are private and CI_JOB_TOKEN cannot access files. + # See https://gitlab.com/gitlab-org/gitlab/issues/191273 + GIT_DEPTH: 1 before_script: - # We don't clone the repo by using GIT_STRATEGY: none and only download the - # single script we need here so it's much faster than cloning. - apk add --update openssl - - wget $CI_PROJECT_URL/raw/$CI_COMMIT_SHA/scripts/review_apps/review-apps.sh - - wget $CI_PROJECT_URL/raw/$CI_COMMIT_SHA/scripts/utils.sh - - source utils.sh - - source review-apps.sh + - source ./scripts/utils.sh + - source ./scripts/review_apps/review-apps.sh review-stop-failed-deployment: extends: .base-review-stop diff --git a/changelogs/unreleased/fix-on-train-method-in-mr.yml b/changelogs/unreleased/fix-on-train-method-in-mr.yml new file mode 100644 index 00000000000..5599964638d --- /dev/null +++ b/changelogs/unreleased/fix-on-train-method-in-mr.yml @@ -0,0 +1,5 @@ +--- +title: Fix RefreshMergeRequestsService raises an exception and unnecessary sidekiq retry +merge_request: 22262 +author: +type: fixed diff --git a/config/initializers/0_runtime_identify.rb b/config/initializers/0_runtime_identify.rb index 21abd637417..e6be19ffb79 100644 --- a/config/initializers/0_runtime_identify.rb +++ b/config/initializers/0_runtime_identify.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true begin - current_runtime = Gitlab::Runtime.identify - Gitlab::AppLogger.info("Process #{Process.pid} (#{$0}) identified as: #{current_runtime}") -rescue => e + Gitlab::Runtime.identify +rescue Gitlab::Runtime::IdentificationError => e message = <<-NOTICE \n!! RUNTIME IDENTIFICATION FAILED: #{e} Runtime based configuration settings may not work properly. diff --git a/db/migrate/20180831164905_add_common_to_prometheus_metrics.rb b/db/migrate/20180831164905_add_common_to_prometheus_metrics.rb index 5eb77d0480d..6654e6d1957 100644 --- a/db/migrate/20180831164905_add_common_to_prometheus_metrics.rb +++ b/db/migrate/20180831164905_add_common_to_prometheus_metrics.rb @@ -8,7 +8,7 @@ class AddCommonToPrometheusMetrics < ActiveRecord::Migration[4.2] disable_ddl_transaction! def up - add_column_with_default(:prometheus_metrics, :common, :boolean, default: false) + add_column_with_default(:prometheus_metrics, :common, :boolean, default: false) # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20180907015926_add_legacy_abac_to_cluster_providers_gcp.rb b/db/migrate/20180907015926_add_legacy_abac_to_cluster_providers_gcp.rb index c57611a0f7d..8bfb0c5612a 100644 --- a/db/migrate/20180907015926_add_legacy_abac_to_cluster_providers_gcp.rb +++ b/db/migrate/20180907015926_add_legacy_abac_to_cluster_providers_gcp.rb @@ -8,7 +8,7 @@ class AddLegacyAbacToClusterProvidersGcp < ActiveRecord::Migration[4.2] disable_ddl_transaction! def up - add_column_with_default(:cluster_providers_gcp, :legacy_abac, :boolean, default: true) + add_column_with_default(:cluster_providers_gcp, :legacy_abac, :boolean, default: true) # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20181017001059_add_cluster_type_to_clusters.rb b/db/migrate/20181017001059_add_cluster_type_to_clusters.rb index d032afe1a43..75abcfedfc9 100644 --- a/db/migrate/20181017001059_add_cluster_type_to_clusters.rb +++ b/db/migrate/20181017001059_add_cluster_type_to_clusters.rb @@ -9,7 +9,7 @@ class AddClusterTypeToClusters < ActiveRecord::Migration[4.2] disable_ddl_transaction! def up - add_column_with_default(:clusters, :cluster_type, :smallint, default: PROJECT_CLUSTER_TYPE) + add_column_with_default(:clusters, :cluster_type, :smallint, default: PROJECT_CLUSTER_TYPE) # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20190220142344_add_email_header_and_footer_enabled_flag_to_appearances_table.rb b/db/migrate/20190220142344_add_email_header_and_footer_enabled_flag_to_appearances_table.rb index 85b9e0580f4..33fb6b8ef0d 100644 --- a/db/migrate/20190220142344_add_email_header_and_footer_enabled_flag_to_appearances_table.rb +++ b/db/migrate/20190220142344_add_email_header_and_footer_enabled_flag_to_appearances_table.rb @@ -8,7 +8,7 @@ class AddEmailHeaderAndFooterEnabledFlagToAppearancesTable < ActiveRecord::Migra DOWNTIME = false def up - add_column_with_default(:appearances, :email_header_and_footer_enabled, :boolean, default: false) + add_column_with_default(:appearances, :email_header_and_footer_enabled, :boolean, default: false) # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20190322164830_add_auto_ssl_enabled_to_pages_domain.rb b/db/migrate/20190322164830_add_auto_ssl_enabled_to_pages_domain.rb index e74a9535ddf..41552b0e2e3 100644 --- a/db/migrate/20190322164830_add_auto_ssl_enabled_to_pages_domain.rb +++ b/db/migrate/20190322164830_add_auto_ssl_enabled_to_pages_domain.rb @@ -8,7 +8,7 @@ class AddAutoSslEnabledToPagesDomain < ActiveRecord::Migration[5.0] disable_ddl_transaction! def up - add_column_with_default :pages_domains, :auto_ssl_enabled, :boolean, default: false + add_column_with_default :pages_domains, :auto_ssl_enabled, :boolean, default: false # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20190325165127_add_managed_to_cluster.rb b/db/migrate/20190325165127_add_managed_to_cluster.rb index e960df9d502..14ed4db143e 100644 --- a/db/migrate/20190325165127_add_managed_to_cluster.rb +++ b/db/migrate/20190325165127_add_managed_to_cluster.rb @@ -8,7 +8,7 @@ class AddManagedToCluster < ActiveRecord::Migration[5.0] DOWNTIME = false def up - add_column_with_default(:clusters, :managed, :boolean, default: true) + add_column_with_default(:clusters, :managed, :boolean, default: true) # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20190415030217_add_variable_type_to_ci_variables.rb b/db/migrate/20190415030217_add_variable_type_to_ci_variables.rb index 433f510299a..ed7af455e12 100644 --- a/db/migrate/20190415030217_add_variable_type_to_ci_variables.rb +++ b/db/migrate/20190415030217_add_variable_type_to_ci_variables.rb @@ -8,7 +8,7 @@ class AddVariableTypeToCiVariables < ActiveRecord::Migration[5.0] ENV_VAR_VARIABLE_TYPE = 1 def up - add_column_with_default(:ci_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE) + add_column_with_default(:ci_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE) # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20190416213556_add_variable_type_to_ci_group_variables.rb b/db/migrate/20190416213556_add_variable_type_to_ci_group_variables.rb index dce73caeb5e..4d329cea1b5 100644 --- a/db/migrate/20190416213556_add_variable_type_to_ci_group_variables.rb +++ b/db/migrate/20190416213556_add_variable_type_to_ci_group_variables.rb @@ -8,7 +8,7 @@ class AddVariableTypeToCiGroupVariables < ActiveRecord::Migration[5.0] ENV_VAR_VARIABLE_TYPE = 1 def up - add_column_with_default(:ci_group_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE) + add_column_with_default(:ci_group_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE) # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20190416213615_add_variable_type_to_ci_pipeline_variables.rb b/db/migrate/20190416213615_add_variable_type_to_ci_pipeline_variables.rb index 1010d9bd29e..aa3002a3dcd 100644 --- a/db/migrate/20190416213615_add_variable_type_to_ci_pipeline_variables.rb +++ b/db/migrate/20190416213615_add_variable_type_to_ci_pipeline_variables.rb @@ -8,7 +8,7 @@ class AddVariableTypeToCiPipelineVariables < ActiveRecord::Migration[5.0] ENV_VAR_VARIABLE_TYPE = 1 def up - add_column_with_default(:ci_pipeline_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE) + add_column_with_default(:ci_pipeline_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE) # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20190416213631_add_variable_type_to_ci_pipeline_schedule_variables.rb b/db/migrate/20190416213631_add_variable_type_to_ci_pipeline_schedule_variables.rb index 3079b2afd9c..b7d80cb2d0d 100644 --- a/db/migrate/20190416213631_add_variable_type_to_ci_pipeline_schedule_variables.rb +++ b/db/migrate/20190416213631_add_variable_type_to_ci_pipeline_schedule_variables.rb @@ -8,7 +8,7 @@ class AddVariableTypeToCiPipelineScheduleVariables < ActiveRecord::Migration[5.0 ENV_VAR_VARIABLE_TYPE = 1 def up - add_column_with_default(:ci_pipeline_schedule_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE) + add_column_with_default(:ci_pipeline_schedule_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE) # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20190520200123_add_rule_type_to_approval_merge_request_approval_rules.rb b/db/migrate/20190520200123_add_rule_type_to_approval_merge_request_approval_rules.rb index 7339a4fccba..7bdb48f3eec 100644 --- a/db/migrate/20190520200123_add_rule_type_to_approval_merge_request_approval_rules.rb +++ b/db/migrate/20190520200123_add_rule_type_to_approval_merge_request_approval_rules.rb @@ -12,7 +12,7 @@ class AddRuleTypeToApprovalMergeRequestApprovalRules < ActiveRecord::Migration[5 disable_ddl_transaction! def up - add_column_with_default(:approval_merge_request_rules, :rule_type, :integer, limit: 2, default: 1) + add_column_with_default(:approval_merge_request_rules, :rule_type, :integer, limit: 2, default: 1) # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20190607085356_add_source_to_pages_domains.rb b/db/migrate/20190607085356_add_source_to_pages_domains.rb index 0a845d7d11f..d681ab67431 100644 --- a/db/migrate/20190607085356_add_source_to_pages_domains.rb +++ b/db/migrate/20190607085356_add_source_to_pages_domains.rb @@ -12,7 +12,7 @@ class AddSourceToPagesDomains < ActiveRecord::Migration[5.1] disable_ddl_transaction! def up - add_column_with_default(:pages_domains, :certificate_source, :smallint, default: 0) + add_column_with_default(:pages_domains, :certificate_source, :smallint, default: 0) # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20190628145246_add_strategies_to_operations_feature_flag_scopes.rb b/db/migrate/20190628145246_add_strategies_to_operations_feature_flag_scopes.rb index ed1f16ee69a..030ef9e4bd6 100644 --- a/db/migrate/20190628145246_add_strategies_to_operations_feature_flag_scopes.rb +++ b/db/migrate/20190628145246_add_strategies_to_operations_feature_flag_scopes.rb @@ -8,7 +8,7 @@ class AddStrategiesToOperationsFeatureFlagScopes < ActiveRecord::Migration[5.1] disable_ddl_transaction! def up - add_column_with_default :operations_feature_flag_scopes, :strategies, :jsonb, default: [{ name: "default", parameters: {} }] + add_column_with_default :operations_feature_flag_scopes, :strategies, :jsonb, default: [{ name: "default", parameters: {} }] # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20190712064021_add_namespace_per_environment_flag_to_clusters.rb b/db/migrate/20190712064021_add_namespace_per_environment_flag_to_clusters.rb index 4c8a0ab3def..771eb21c4b6 100644 --- a/db/migrate/20190712064021_add_namespace_per_environment_flag_to_clusters.rb +++ b/db/migrate/20190712064021_add_namespace_per_environment_flag_to_clusters.rb @@ -11,7 +11,7 @@ class AddNamespacePerEnvironmentFlagToClusters < ActiveRecord::Migration[5.1] disable_ddl_transaction! def up - add_column_with_default :clusters, :namespace_per_environment, :boolean, default: false + add_column_with_default :clusters, :namespace_per_environment, :boolean, default: false # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20190715173819_add_object_storage_flag_to_geo_node.rb b/db/migrate/20190715173819_add_object_storage_flag_to_geo_node.rb index 2d3243f3357..cbc353b6282 100644 --- a/db/migrate/20190715173819_add_object_storage_flag_to_geo_node.rb +++ b/db/migrate/20190715173819_add_object_storage_flag_to_geo_node.rb @@ -12,7 +12,7 @@ class AddObjectStorageFlagToGeoNode < ActiveRecord::Migration[5.2] disable_ddl_transaction! def up - add_column_with_default :geo_nodes, :sync_object_storage, :boolean, default: false + add_column_with_default :geo_nodes, :sync_object_storage, :boolean, default: false # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20190729180447_add_merge_requests_require_code_owner_approval_to_protected_branches.rb b/db/migrate/20190729180447_add_merge_requests_require_code_owner_approval_to_protected_branches.rb index 098fcff9ace..bfac67606d6 100644 --- a/db/migrate/20190729180447_add_merge_requests_require_code_owner_approval_to_protected_branches.rb +++ b/db/migrate/20190729180447_add_merge_requests_require_code_owner_approval_to_protected_branches.rb @@ -9,7 +9,7 @@ class AddMergeRequestsRequireCodeOwnerApprovalToProtectedBranches < ActiveRecord disable_ddl_transaction! def up - add_column_with_default( + add_column_with_default( # rubocop:disable Migration/AddColumnWithDefault :protected_branches, :code_owner_approval_required, :boolean, diff --git a/db/migrate/20190816151221_add_active_jobs_limit_to_plans.rb b/db/migrate/20190816151221_add_active_jobs_limit_to_plans.rb index 951ff41f1a8..193e6cb188e 100644 --- a/db/migrate/20190816151221_add_active_jobs_limit_to_plans.rb +++ b/db/migrate/20190816151221_add_active_jobs_limit_to_plans.rb @@ -8,7 +8,7 @@ class AddActiveJobsLimitToPlans < ActiveRecord::Migration[5.2] disable_ddl_transaction! def up - add_column_with_default :plans, :active_jobs_limit, :integer, default: 0 + add_column_with_default :plans, :active_jobs_limit, :integer, default: 0 # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20190901174200_add_max_issue_count_to_list.rb b/db/migrate/20190901174200_add_max_issue_count_to_list.rb index 59359f28d6a..7408d2f1c93 100644 --- a/db/migrate/20190901174200_add_max_issue_count_to_list.rb +++ b/db/migrate/20190901174200_add_max_issue_count_to_list.rb @@ -7,7 +7,7 @@ class AddMaxIssueCountToList < ActiveRecord::Migration[4.2] DOWNTIME = false def up - add_column_with_default :lists, :max_issue_count, :integer, default: 0 + add_column_with_default :lists, :max_issue_count, :integer, default: 0 # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20190905140605_add_cloud_run_to_clusters_providers_gcp.rb b/db/migrate/20190905140605_add_cloud_run_to_clusters_providers_gcp.rb index e7ffd7cd4d3..cd6b2fb7d4f 100644 --- a/db/migrate/20190905140605_add_cloud_run_to_clusters_providers_gcp.rb +++ b/db/migrate/20190905140605_add_cloud_run_to_clusters_providers_gcp.rb @@ -8,7 +8,7 @@ class AddCloudRunToClustersProvidersGcp < ActiveRecord::Migration[5.2] disable_ddl_transaction! def up - add_column_with_default(:cluster_providers_gcp, :cloud_run, :boolean, default: false) + add_column_with_default(:cluster_providers_gcp, :cloud_run, :boolean, default: false) # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20191014123159_add_expire_notification_delivered_to_personal_access_tokens.rb b/db/migrate/20191014123159_add_expire_notification_delivered_to_personal_access_tokens.rb index f172d3bdcbd..41a81e3ac87 100644 --- a/db/migrate/20191014123159_add_expire_notification_delivered_to_personal_access_tokens.rb +++ b/db/migrate/20191014123159_add_expire_notification_delivered_to_personal_access_tokens.rb @@ -8,7 +8,7 @@ class AddExpireNotificationDeliveredToPersonalAccessTokens < ActiveRecord::Migra disable_ddl_transaction! def up - add_column_with_default :personal_access_tokens, :expire_notification_delivered, :boolean, default: false + add_column_with_default :personal_access_tokens, :expire_notification_delivered, :boolean, default: false # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20191023093207_add_comment_actions_to_services.rb b/db/migrate/20191023093207_add_comment_actions_to_services.rb index f3fc12ac7c7..0bd528cc85d 100644 --- a/db/migrate/20191023093207_add_comment_actions_to_services.rb +++ b/db/migrate/20191023093207_add_comment_actions_to_services.rb @@ -8,7 +8,7 @@ class AddCommentActionsToServices < ActiveRecord::Migration[5.2] disable_ddl_transaction! def up - add_column_with_default(:services, :comment_on_event_enabled, :boolean, default: true) + add_column_with_default(:services, :comment_on_event_enabled, :boolean, default: true) # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20191028130054_add_max_issue_weight_to_list.rb b/db/migrate/20191028130054_add_max_issue_weight_to_list.rb index eec7c42c907..f15b65067f6 100644 --- a/db/migrate/20191028130054_add_max_issue_weight_to_list.rb +++ b/db/migrate/20191028130054_add_max_issue_weight_to_list.rb @@ -8,7 +8,7 @@ class AddMaxIssueWeightToList < ActiveRecord::Migration[5.2] DOWNTIME = false def up - add_column_with_default :lists, :max_issue_weight, :integer, default: 0 + add_column_with_default :lists, :max_issue_weight, :integer, default: 0 # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20191105155113_add_secret_to_snippet.rb b/db/migrate/20191105155113_add_secret_to_snippet.rb index ae514d48494..8f0a330238b 100644 --- a/db/migrate/20191105155113_add_secret_to_snippet.rb +++ b/db/migrate/20191105155113_add_secret_to_snippet.rb @@ -9,7 +9,7 @@ class AddSecretToSnippet < ActiveRecord::Migration[5.2] def up unless column_exists?(:snippets, :secret) - add_column_with_default :snippets, :secret, :boolean, default: false + add_column_with_default :snippets, :secret, :boolean, default: false # rubocop:disable Migration/AddColumnWithDefault end add_concurrent_index :snippets, [:visibility_level, :secret] diff --git a/db/migrate/20191106144901_add_state_to_merge_trains.rb b/db/migrate/20191106144901_add_state_to_merge_trains.rb index e2256705f53..64a70575c91 100644 --- a/db/migrate/20191106144901_add_state_to_merge_trains.rb +++ b/db/migrate/20191106144901_add_state_to_merge_trains.rb @@ -9,7 +9,7 @@ class AddStateToMergeTrains < ActiveRecord::Migration[5.2] disable_ddl_transaction! def up - add_column_with_default :merge_trains, :status, :integer, limit: 2, default: MERGE_TRAIN_STATUS_CREATED + add_column_with_default :merge_trains, :status, :integer, limit: 2, default: MERGE_TRAIN_STATUS_CREATED # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20191121193110_add_issue_links_type.rb b/db/migrate/20191121193110_add_issue_links_type.rb index 61ef2e7d7e8..86bfd41b916 100644 --- a/db/migrate/20191121193110_add_issue_links_type.rb +++ b/db/migrate/20191121193110_add_issue_links_type.rb @@ -8,7 +8,7 @@ class AddIssueLinksType < ActiveRecord::Migration[5.1] disable_ddl_transaction! def up - add_column_with_default :issue_links, :link_type, :integer, default: 0, limit: 2 + add_column_with_default :issue_links, :link_type, :integer, default: 0, limit: 2 # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20191127221608_add_wildcard_and_domain_type_to_pages_domains.rb b/db/migrate/20191127221608_add_wildcard_and_domain_type_to_pages_domains.rb index 6893a02bcad..4ca7ad29691 100644 --- a/db/migrate/20191127221608_add_wildcard_and_domain_type_to_pages_domains.rb +++ b/db/migrate/20191127221608_add_wildcard_and_domain_type_to_pages_domains.rb @@ -9,8 +9,10 @@ class AddWildcardAndDomainTypeToPagesDomains < ActiveRecord::Migration[5.2] disable_ddl_transaction! def up + # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :pages_domains, :wildcard, :boolean, default: false add_column_with_default :pages_domains, :domain_type, :integer, limit: 2, default: PROJECT_TYPE + # rubocop:enable Migration/AddColumnWithDefault end def down diff --git a/db/migrate/20191129134844_add_broadcast_type_to_broadcast_message.rb b/db/migrate/20191129134844_add_broadcast_type_to_broadcast_message.rb index 84d17f558d1..884d9ac6d7f 100644 --- a/db/migrate/20191129134844_add_broadcast_type_to_broadcast_message.rb +++ b/db/migrate/20191129134844_add_broadcast_type_to_broadcast_message.rb @@ -10,7 +10,7 @@ class AddBroadcastTypeToBroadcastMessage < ActiveRecord::Migration[5.2] disable_ddl_transaction! def up - add_column_with_default(:broadcast_messages, :broadcast_type, :smallint, default: BROADCAST_MESSAGE_BANNER_TYPE) + add_column_with_default(:broadcast_messages, :broadcast_type, :smallint, default: BROADCAST_MESSAGE_BANNER_TYPE) # rubocop:disable Migration/AddColumnWithDefault end def down diff --git a/lib/gitlab/runtime.rb b/lib/gitlab/runtime.rb index 33b7b68e64e..c9e5d71c107 100644 --- a/lib/gitlab/runtime.rb +++ b/lib/gitlab/runtime.rb @@ -4,8 +4,9 @@ module Gitlab # Provides routines to identify the current runtime as which the application # executes, such as whether it is an application server and which one. module Runtime - AmbiguousProcessError = Class.new(StandardError) - UnknownProcessError = Class.new(StandardError) + IdentificationError = Class.new(RuntimeError) + AmbiguousProcessError = Class.new(IdentificationError) + UnknownProcessError = Class.new(IdentificationError) class << self def identify @@ -14,6 +15,8 @@ module Gitlab matches << :unicorn if unicorn? matches << :console if console? matches << :sidekiq if sidekiq? + matches << :rake if rake? + matches << :rspec if rspec? if matches.one? matches.first @@ -41,6 +44,14 @@ module Gitlab !!(defined?(::Sidekiq) && Sidekiq.server?) end + def rake? + !!(defined?(::Rake) && Rake.application.top_level_tasks.any?) + end + + def rspec? + Rails.env.test? && process_name == 'rspec' + end + def console? !!defined?(::Rails::Console) end @@ -52,6 +63,10 @@ module Gitlab def multi_threaded? puma? || sidekiq? end + + def process_name + File.basename($0) + end end end end diff --git a/rubocop/cop/migration/add_column_with_default.rb b/rubocop/cop/migration/add_column_with_default.rb index 8d1ab333dcf..d9f8fe62a86 100644 --- a/rubocop/cop/migration/add_column_with_default.rb +++ b/rubocop/cop/migration/add_column_with_default.rb @@ -12,52 +12,33 @@ module RuboCop WHITELISTED_TABLES = [:application_settings].freeze - MSG = '`add_column_with_default` with `allow_null: false` may cause prolonged lock situations and downtime, ' \ + MSG = '`add_column_with_default` without `allow_null: true` may cause prolonged lock situations and downtime, ' \ 'see https://gitlab.com/gitlab-org/gitlab/issues/38060'.freeze + def_node_matcher :add_column_with_default?, <<~PATTERN + (send _ :add_column_with_default $_ ... (hash $...)) + PATTERN + def on_send(node) return unless in_migration?(node) - name = node.children[1] - - return unless name == :add_column_with_default + add_column_with_default?(node) do |table, options| + break if table_whitelisted?(table) || nulls_allowed?(options) - # Ignore whitelisted tables. - return if table_whitelisted?(node.children[2]) - - opts = node.children.last + add_offense(node, location: :selector) + end + end - return unless opts && opts.type == :hash + private - opts.each_node(:pair) do |pair| - if disallows_null_values?(pair) - add_offense(node, location: :selector) - end - end + def nulls_allowed?(options) + options.find { |opt| opt.key.value == :allow_null && opt.value.true_type? } end def table_whitelisted?(symbol) symbol && symbol.type == :sym && WHITELISTED_TABLES.include?(symbol.children[0]) end - - def disallows_null_values?(pair) - options = [hash_key_type(pair), hash_key_name(pair), hash_value(pair)] - - options == [:sym, :allow_null, :false] # rubocop:disable Lint/BooleanSymbol - end - - def hash_key_type(pair) - pair.children[0].type - end - - def hash_key_name(pair) - pair.children[0].children[0] - end - - def hash_value(pair) - pair.children[1].type - end end end end diff --git a/spec/lib/gitlab/runtime_spec.rb b/spec/lib/gitlab/runtime_spec.rb index ff8b383ba45..6059644a1b2 100644 --- a/spec/lib/gitlab/runtime_spec.rb +++ b/spec/lib/gitlab/runtime_spec.rb @@ -3,6 +3,10 @@ require 'spec_helper' describe Gitlab::Runtime do + before do + allow(described_class).to receive(:process_name).and_return('ruby') + end + context "when unknown" do it "raises an exception when trying to identify" do expect { subject.identify }.to raise_error(subject::UnknownProcessError) @@ -36,6 +40,8 @@ describe Gitlab::Runtime do expect(subject.unicorn?).to be(false) expect(subject.sidekiq?).to be(false) expect(subject.console?).to be(false) + expect(subject.rake?).to be(false) + expect(subject.rspec?).to be(false) end end @@ -57,6 +63,8 @@ describe Gitlab::Runtime do expect(subject.puma?).to be(false) expect(subject.sidekiq?).to be(false) expect(subject.console?).to be(false) + expect(subject.rake?).to be(false) + expect(subject.rspec?).to be(false) end end @@ -77,6 +85,8 @@ describe Gitlab::Runtime do expect(subject.unicorn?).to be(false) expect(subject.puma?).to be(false) expect(subject.console?).to be(false) + expect(subject.rake?).to be(false) + expect(subject.rspec?).to be(false) end end @@ -96,6 +106,26 @@ describe Gitlab::Runtime do expect(subject.unicorn?).to be(false) expect(subject.sidekiq?).to be(false) expect(subject.puma?).to be(false) + expect(subject.rake?).to be(false) + expect(subject.rspec?).to be(false) + end + end + + context "rspec" do + before do + allow(described_class).to receive(:process_name).and_return('rspec') + end + + it "identifies itself" do + expect(subject.identify).to eq(:rspec) + expect(subject.rspec?).to be(true) + end + + it "does not identify as others" do + expect(subject.unicorn?).to be(false) + expect(subject.sidekiq?).to be(false) + expect(subject.rake?).to be(false) + expect(subject.puma?).to be(false) end end end diff --git a/spec/rubocop/cop/migration/add_column_with_default_spec.rb b/spec/rubocop/cop/migration/add_column_with_default_spec.rb index 3d2315ddfa1..d309a960e2f 100644 --- a/spec/rubocop/cop/migration/add_column_with_default_spec.rb +++ b/spec/rubocop/cop/migration/add_column_with_default_spec.rb @@ -27,7 +27,7 @@ describe RuboCop::Cop::Migration::AddColumnWithDefault do allow(cop).to receive(:in_migration?).and_return(true) end - let(:offense) { '`add_column_with_default` with `allow_null: false` may cause prolonged lock situations and downtime, see https://gitlab.com/gitlab-org/gitlab/issues/38060' } + let(:offense) { '`add_column_with_default` without `allow_null: true` may cause prolonged lock situations and downtime, see https://gitlab.com/gitlab-org/gitlab/issues/38060' } it 'registers an offense when specifying allow_null: false' do expect_offense(<<~RUBY) @@ -46,10 +46,11 @@ describe RuboCop::Cop::Migration::AddColumnWithDefault do RUBY end - it 'registers no offense when allow_null is not specified' do - expect_no_offenses(<<~RUBY) + it 'registers an offense when allow_null is not specified' do + expect_offense(<<~RUBY) def up add_column_with_default(:ci_build_needs, :artifacts, :boolean, default: true) + ^^^^^^^^^^^^^^^^^^^^^^^ #{offense} end RUBY end |