From 7b78125a3829026f54bd87ab560758de3f37ad82 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 1 Dec 2021 21:13:44 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- GITALY_SERVER_VERSION | 2 +- .../components/extensions/base.vue | 2 +- .../components/states/merge_checks_failed.vue | 2 +- .../components/manage_via_mr.vue | 2 +- app/controllers/projects/notes_controller.rb | 2 +- app/models/note.rb | 9 +++ app/serializers/note_entity.rb | 2 +- .../outdated_discussion_diff_lines_service.rb | 10 +-- doc/development/contributing/style_guides.md | 6 +- .../admin_area/settings/continuous_integration.md | 10 +-- .../application_security/configuration/index.md | 4 +- .../dependency_scanning/index.md | 4 +- .../application_security/iac_scanning/index.md | 4 +- .../application_security/secret_detection/index.md | 4 +- doc/user/infrastructure/iac/terraform_state.md | 8 +-- doc/user/project/code_owners.md | 20 ++++-- .../migrations/background_migration_helpers.rb | 2 + .../database/partitioning/partition_manager.rb | 1 + lib/gitlab/import/import_failure_service.rb | 27 +++++-- locale/gitlab.pot | 11 ++- spec/factories/protected_branches.rb | 16 ++++- .../partitioning/sliding_list_strategy_spec.rb | 4 +- .../gitlab/import/import_failure_service_spec.rb | 83 ++++++++++------------ spec/models/integrations/microsoft_teams_spec.rb | 2 +- .../models/chat_integration_shared_examples.rb | 4 +- .../slack_mattermost_notifier_shared_examples.rb | 8 +-- 26 files changed, 144 insertions(+), 105 deletions(-) diff --git a/GITALY_SERVER_VERSION b/GITALY_SERVER_VERSION index 855ef1b74ba..8e2779fa0a1 100644 --- a/GITALY_SERVER_VERSION +++ b/GITALY_SERVER_VERSION @@ -1 +1 @@ -f87bc1e983d11788fdbce953dced45ec5554af23 +4dd8bfe1307ffcc5a2a3f4eb70da7977a7c1d915 diff --git a/app/assets/javascripts/vue_merge_request_widget/components/extensions/base.vue b/app/assets/javascripts/vue_merge_request_widget/components/extensions/base.vue index 5f77c0cd2f3..02c2d852fc7 100644 --- a/app/assets/javascripts/vue_merge_request_widget/components/extensions/base.vue +++ b/app/assets/javascripts/vue_merge_request_widget/components/extensions/base.vue @@ -171,7 +171,7 @@ export default { :icon-name="statusIconName" />
diff --git a/app/assets/javascripts/vue_merge_request_widget/components/states/merge_checks_failed.vue b/app/assets/javascripts/vue_merge_request_widget/components/states/merge_checks_failed.vue index 503ddf8a396..ce572f8b0bf 100644 --- a/app/assets/javascripts/vue_merge_request_widget/components/states/merge_checks_failed.vue +++ b/app/assets/javascripts/vue_merge_request_widget/components/states/merge_checks_failed.vue @@ -9,7 +9,7 @@ export default { pipelineFailed: s__( 'mrWidget|The pipeline for this merge request did not complete. Push a new commit to fix the failure.', ), - approvalNeeded: s__('mrWidget|You can only merge once this merge request is approved.'), + approvalNeeded: s__('mrWidget|Merge blocked: this merge request must be approved.'), unresolvedDiscussions: s__('mrWidget|Merge blocked: all threads must be resolved.'), }, components: { diff --git a/app/assets/javascripts/vue_shared/security_configuration/components/manage_via_mr.vue b/app/assets/javascripts/vue_shared/security_configuration/components/manage_via_mr.vue index 42272c222fc..d1630c9ac13 100644 --- a/app/assets/javascripts/vue_shared/security_configuration/components/manage_via_mr.vue +++ b/app/assets/javascripts/vue_shared/security_configuration/components/manage_via_mr.vue @@ -85,7 +85,7 @@ export default { ); }, i18n: { - buttonLabel: s__('SecurityConfiguration|Configure via Merge Request'), + buttonLabel: s__('SecurityConfiguration|Configure with a merge request'), noSuccessPathError: s__( 'SecurityConfiguration|%{featureName} merge request creation mutation failed', ), diff --git a/app/controllers/projects/notes_controller.rb b/app/controllers/projects/notes_controller.rb index e8057308386..7322e08e62e 100644 --- a/app/controllers/projects/notes_controller.rb +++ b/app/controllers/projects/notes_controller.rb @@ -57,7 +57,7 @@ class Projects::NotesController < Projects::ApplicationController def outdated_line_change diff_lines = Rails.cache.fetch(['note', note.id, 'oudated_line_change'], expires_in: 7.days) do - ::MergeRequests::OutdatedDiscussionDiffLinesService.new(project: @project, note: note).execute.to_json + ::MergeRequests::OutdatedDiscussionDiffLinesService.new(project: note.noteable.source_project, note: note).execute.to_json end render json: diff_lines diff --git a/app/models/note.rb b/app/models/note.rb index 990e0c1b49b..a143c21c0f9 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -603,6 +603,15 @@ class Note < ApplicationRecord }) end + def show_outdated_changes? + return false unless for_merge_request? + return false unless Feature.enabled?(:display_outdated_line_diff, noteable.source_project, default_enabled: :yaml) + return false unless system? + return false unless change_position&.line_range + + change_position.line_range["end"] || change_position.line_range["start"] + end + private def system_note_viewable_by?(user) diff --git a/app/serializers/note_entity.rb b/app/serializers/note_entity.rb index 8f189f14dea..58ad5812801 100644 --- a/app/serializers/note_entity.rb +++ b/app/serializers/note_entity.rb @@ -51,7 +51,7 @@ class NoteEntity < API::Entities::Note SystemNoteHelper.system_note_icon_name(note) end - expose :outdated_line_change_path, if: -> (note, _) { note.system? && note.change_position&.line_range && Feature.enabled?(:display_outdated_line_diff, note.project, default_enabled: :yaml) } do |note| + expose :outdated_line_change_path, if: -> (note, _) { note.show_outdated_changes? } do |note| outdated_line_change_namespace_project_note_path(namespace_id: note.project.namespace, project_id: note.project, id: note) end diff --git a/app/services/merge_requests/outdated_discussion_diff_lines_service.rb b/app/services/merge_requests/outdated_discussion_diff_lines_service.rb index a2de5a32963..ad65a9afa6b 100644 --- a/app/services/merge_requests/outdated_discussion_diff_lines_service.rb +++ b/app/services/merge_requests/outdated_discussion_diff_lines_service.rb @@ -14,12 +14,12 @@ module MergeRequests end def execute - end_position = position.line_range["end"] + line_position = position.line_range["end"] || position.line_range["start"] diff_line_index = diff_lines.find_index do |l| - if end_position["new_line"] - l.new_line == end_position["new_line"] - elsif end_position["old_line"] - l.old_line == end_position["old_line"] + if line_position["new_line"] + l.new_line == line_position["new_line"] + elsif line_position["old_line"] + l.old_line == line_position["old_line"] end end initial_line_index = [diff_line_index - OVERFLOW_LINES_COUNT, 0].max diff --git a/doc/development/contributing/style_guides.md b/doc/development/contributing/style_guides.md index e3b8f7372b9..fdb6e99fdcd 100644 --- a/doc/development/contributing/style_guides.md +++ b/doc/development/contributing/style_guides.md @@ -171,10 +171,8 @@ we should track our progress through the exception list. When auto-generating the `.rubocop_todo.yml` exception list for a particular Cop, and more than 15 files are affected, we should add the exception list to -a different file within `.rubocop_todo/` directory. - -For example, the configuration for the cop `Gitlab/NamespacedClass` is located -in `.rubocop_todo/gitlab/namespaced_class.yml`. +a different file in the directory `.rubocop_todo/`. For example, the configuration for the cop +`Gitlab/NamespacedClass` is in `.rubocop_todo/gitlab/namespaced_class.yml`. This ensures that our list isn't mistakenly removed by another auto generation of the `.rubocop_todo.yml`. This also allows us greater visibility into the exceptions diff --git a/doc/user/admin_area/settings/continuous_integration.md b/doc/user/admin_area/settings/continuous_integration.md index 565e905d732..2ed417a2933 100644 --- a/doc/user/admin_area/settings/continuous_integration.md +++ b/doc/user/admin_area/settings/continuous_integration.md @@ -232,11 +232,11 @@ To enable or disable the banner: ## Required pipeline configuration **(PREMIUM SELF)** -WARNING: -This feature is being re-evaluated in favor of a different -[compliance solution](https://gitlab.com/groups/gitlab-org/-/epics/3156). -We recommend that users who haven't yet implemented this feature wait for -the new solution. +NOTE: +An alternative [compliance solution](../../project/settings/index.md#compliance-pipeline-configuration) +is available for Ultimate tier users on both SaaS and self-managed instances. +We recommend this alternative solution for Ultimate-tier users because it provides greater flexibility, +allowing required pipelines to be assigned to specific compliance framework labels. You can set a [CI/CD template](../../../ci/examples/index.md#cicd-templates) as a required pipeline configuration for all projects on a GitLab instance. You can diff --git a/doc/user/application_security/configuration/index.md b/doc/user/application_security/configuration/index.md index a913d5fba92..cdcd334dba6 100644 --- a/doc/user/application_security/configuration/index.md +++ b/doc/user/application_security/configuration/index.md @@ -46,14 +46,14 @@ You can configure the following security controls: - Select **Manage scans** to manage the saved DAST scans, site profiles, and scanner profiles. For more details, read [DAST on-demand scans](../dast/index.md#on-demand-scans). - [Dependency Scanning](../dependency_scanning/index.md) - - Select **Configure via Merge Request** to create a merge request with the changes required to + - Select **Configure with a merge request** to create a merge request with the changes required to enable Dependency Scanning. For more details, see [Enable Dependency Scanning via an automatic merge request](../dependency_scanning/index.md#enable-dependency-scanning-via-an-automatic-merge-request). - [Container Scanning](../container_scanning/index.md) - Can be configured with `.gitlab-ci.yml`. For more details, read [Container Scanning](../../../user/application_security/container_scanning/index.md#configuration). - [Cluster Image Scanning](../cluster_image_scanning/index.md) - Can be configured with `.gitlab-ci.yml`. For more details, read [Cluster Image Scanning](../../../user/application_security/cluster_image_scanning/#configuration). - [Secret Detection](../secret_detection/index.md) - - Select **Configure via Merge Request** to create a merge request with the changes required to + - Select **Configure with a merge request** to create a merge request with the changes required to enable Secret Detection. For more details, read [Enable Secret Detection via an automatic merge request](../secret_detection/index.md#enable-secret-detection-via-an-automatic-merge-request). - [API Fuzzing](../api_fuzzing/index.md) - Select **Enable API Fuzzing** to use API Fuzzing for the current project. For more details, read [API Fuzzing](../../../user/application_security/api_fuzzing/index.md#enable-web-api-fuzzing). diff --git a/doc/user/application_security/dependency_scanning/index.md b/doc/user/application_security/dependency_scanning/index.md index 4b6da3fd482..e7ae8687488 100644 --- a/doc/user/application_security/dependency_scanning/index.md +++ b/doc/user/application_security/dependency_scanning/index.md @@ -9,7 +9,7 @@ info: To determine the technical writer assigned to the Stage/Group associated w INFO: Try out Dependency Scanning in GitLab Ultimate. -[It's free for 30 days](https://about.gitlab.com/free-trial?glm_source=docs.gitlab.com&glm_content=u-dependency-scanning-docs). +[It's free for 30 days](https://about.gitlab.com/free-trial?glm_source=docs.gitlab.com&glm_content=u-dependency-scanning-docs). The Dependency Scanning feature can automatically find security vulnerabilities in your dependencies while you're developing and testing your applications. For example, dependency scanning @@ -444,7 +444,7 @@ from the Security Configuration page. 1. In the project where you want to enable Dependency Scanning, navigate to **Security & Compliance > Configuration**. -1. In the **Dependency Scanning** row, select **Configure via Merge Request**. +1. In the **Dependency Scanning** row, select **Configure with a merge request**. This automatically creates a merge request with the changes necessary to enable Dependency Scanning that you can review and merge to complete the configuration. diff --git a/doc/user/application_security/iac_scanning/index.md b/doc/user/application_security/iac_scanning/index.md index 3d164165de1..8c63996a133 100644 --- a/doc/user/application_security/iac_scanning/index.md +++ b/doc/user/application_security/iac_scanning/index.md @@ -39,7 +39,7 @@ GitLab IaC scanning supports a variety of IaC configuration files. Our IaC secur ### Making IaC analyzers available to all GitLab tiers -All open source (OSS) analyzers are availibile with the GitLab Free tier. Future propietary analyzers may be restricted to higher tiers. +All open source (OSS) analyzers are availibile with the GitLab Free tier. Future propietary analyzers may be restricted to higher tiers. #### Summary of features per tier @@ -84,7 +84,7 @@ from the Security Configuration page: 1. On the top bar, select **Menu > Projects** and find your project. 1. On the left sidebar, select **Security & Compliance > Configuration**. -1. In the **Infrastructure as Code (IaC) Scanning** row, select **Configure via Merge Request**. +1. In the **Infrastructure as Code (IaC) Scanning** row, select **Configure with a merge request**. This automatically creates a merge request with the changes necessary to enable IaC Scanning that you can review and merge to complete the configuration. diff --git a/doc/user/application_security/secret_detection/index.md b/doc/user/application_security/secret_detection/index.md index 4339b5c499d..056c8ac6079 100644 --- a/doc/user/application_security/secret_detection/index.md +++ b/doc/user/application_security/secret_detection/index.md @@ -123,10 +123,10 @@ from the Security Configuration page. 1. In the project where you want to enable Secret Detection, go to **Security & Compliance > Configuration**. -1. In the **Secret Detection** row, select **Configure via Merge Request**. +1. In the **Secret Detection** row, select **Configure with a merge request**. This automatically creates a merge request with the changes necessary to enable Secret Detection -that you can review and merge to complete the configuration. +that you can review and merge to complete the configuration. NOTE: The configuration tool works best with no existing `.gitlab-ci.yml` file, or with a minimal diff --git a/doc/user/infrastructure/iac/terraform_state.md b/doc/user/infrastructure/iac/terraform_state.md index 84d1edbe2f7..a45ef02622f 100644 --- a/doc/user/infrastructure/iac/terraform_state.md +++ b/doc/user/infrastructure/iac/terraform_state.md @@ -17,7 +17,7 @@ to securely store the state files in local storage (the default) or WARNING: Using local storage (the default) on clustered deployments of GitLab will result in a split state across nodes, making subsequent executions of Terraform inconsistent. -You are highly advised to use a remote storage in that case. +You are highly advised to use a remote storage resource in that case. The GitLab managed Terraform state backend can store your Terraform state easily and securely, and spares you from setting up additional remote resources like @@ -28,7 +28,7 @@ Amazon S3 or Google Cloud Storage. Its features include: - Locking and unlocking state. - Remote Terraform plan and apply execution. -A GitLab **administrator** must [setup the Terraform state storage configuration](../../../administration/terraform_state.md) +A GitLab **administrator** must [set up the Terraform state storage configuration](../../../administration/terraform_state.md) before using this feature. ## Permissions for using Terraform @@ -89,7 +89,7 @@ local machine, this is a simple way to get started: ``` If you already have a GitLab-managed Terraform state, you can use the `terraform init` command -with the prepopulated parameters values: +with the pre-populated parameters values: 1. On the top bar, select **Menu > Projects** and find your project. 1. On the left sidebar, select **Infrastructure > Terraform**. @@ -300,7 +300,7 @@ any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, -rerun this command to reinitialize your working directory. If you forget, other +re-run this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary. ``` diff --git a/doc/user/project/code_owners.md b/doc/user/project/code_owners.md index 7057abe8a0f..7cc8c314c63 100644 --- a/doc/user/project/code_owners.md +++ b/doc/user/project/code_owners.md @@ -177,12 +177,16 @@ entries under **Database**. The entries defined under the sections **Documentati ### Make a Code Owners section optional -> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/232995) in GitLab Premium 13.8 behind a feature flag, enabled by default. -> - [Feature flag removed](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/53227) in GitLab 13.9. +> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/232995) in GitLab Premium 13.8. -You can make a section optional, so that approval from the Code Owners in that section is optional. +You can designate optional sections in your Code Owners file. Prepend the +section name with the caret `^` character to treat the entire section as optional. +Optional sections enable you to designate responsible parties for various parts +of your codebase, but not require approval from them. This approach provides +a more relaxed policy for parts of your project that are frequently updated, +but don't require stringent reviews. -Put a caret `^` character before the Code Owners section name. For example: +In this example, the `[Go]` section is optional: ```plaintext [Documentation] @@ -204,8 +208,12 @@ If a section is duplicated in the file, and one of them is marked as optional an Optional sections in the `CODEOWNERS` file are treated as optional only when changes are submitted by using merge requests. If a change is submitted directly to the protected branch, approval from Code Owners is still required, even if the -section is marked as optional. [An issue exists](https://gitlab.com/gitlab-org/gitlab/-/issues/297638) -to allow direct pushes to the protected branch for sections marked as optional. +section is marked as optional. + +### Allowed to Push + +The Code Owner approval and protected branch features do not apply to users who +are **Allowed to push**. ## Example `CODEOWNERS` file diff --git a/lib/gitlab/database/migrations/background_migration_helpers.rb b/lib/gitlab/database/migrations/background_migration_helpers.rb index 27c600d7347..8c33c41ce77 100644 --- a/lib/gitlab/database/migrations/background_migration_helpers.rb +++ b/lib/gitlab/database/migrations/background_migration_helpers.rb @@ -85,6 +85,7 @@ module Gitlab # Requeue pending jobs previously queued with #queue_background_migration_jobs_by_range_at_intervals # # This method is useful to schedule jobs that had previously failed. + # It can only be used if the previous background migration used job tracking like the queue_background_migration_jobs_by_range_at_intervals helper. # # job_class_name - The background migration job class as a string # delay_interval - The duration between each job's scheduled time @@ -129,6 +130,7 @@ module Gitlab # 4. Optionally remove job tracking information. # # This method does not garauntee that all jobs completed successfully. + # It can only be used if the previous background migration used the queue_background_migration_jobs_by_range_at_intervals helper. def finalize_background_migration(class_name, delete_tracking_jobs: ['succeeded']) # Empty the sidekiq queue. Gitlab::BackgroundMigration.steal(class_name) diff --git a/lib/gitlab/database/partitioning/partition_manager.rb b/lib/gitlab/database/partitioning/partition_manager.rb index 3a4e120651e..d810ae63c5a 100644 --- a/lib/gitlab/database/partitioning/partition_manager.rb +++ b/lib/gitlab/database/partitioning/partition_manager.rb @@ -73,6 +73,7 @@ module Gitlab partition_name: partition.partition_name, table_name: partition.table) end + model.partitioning_strategy.after_adding_partitions end end diff --git a/lib/gitlab/import/import_failure_service.rb b/lib/gitlab/import/import_failure_service.rb index 142c00f7a6b..bebd64b29a9 100644 --- a/lib/gitlab/import/import_failure_service.rb +++ b/lib/gitlab/import/import_failure_service.rb @@ -15,11 +15,21 @@ module Gitlab exception: exception, import_state: import_state, project_id: project_id, - error_source: error_source - ).execute(fail_import: fail_import, metrics: metrics) + error_source: error_source, + fail_import: fail_import, + metrics: metrics + ).execute end - def initialize(exception:, import_state: nil, project_id: nil, error_source: nil) + def initialize( + exception:, + import_state: nil, + project_id: nil, + error_source: nil, + fail_import: false, + metrics: false + ) + if import_state.blank? && project_id.blank? raise ArgumentError, 'import_state OR project_id must be provided' end @@ -34,9 +44,11 @@ module Gitlab @exception = exception @error_source = error_source + @fail_import = fail_import + @metrics = metrics end - def execute(fail_import:, metrics:) + def execute track_exception persist_failure @@ -46,7 +58,7 @@ module Gitlab private - attr_reader :exception, :import_state, :project, :error_source + attr_reader :exception, :import_state, :project, :error_source, :fail_import, :metrics def track_exception attributes = { @@ -65,12 +77,15 @@ module Gitlab Gitlab::ErrorTracking.track_exception(exception, attributes) end + # Failures with `retry_count: 0` are considered "hard_failures" and those + # are exposed on the REST API projects/:id/import def persist_failure project.import_failures.create( source: error_source, exception_class: exception.class.to_s, exception_message: exception.message.truncate(255), - correlation_id_value: Labkit::Correlation::CorrelationId.current_or_new_id + correlation_id_value: Labkit::Correlation::CorrelationId.current_or_new_id, + retry_count: fail_import ? 0 : nil ) end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index e82b4e64e59..03bc507ce97 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -30776,7 +30776,7 @@ msgstr "" msgid "SecurityConfiguration|Configure %{feature}" msgstr "" -msgid "SecurityConfiguration|Configure via Merge Request" +msgid "SecurityConfiguration|Configure with a merge request" msgstr "" msgid "SecurityConfiguration|Copy code and open .gitlab-ci.yml file" @@ -39736,9 +39736,6 @@ msgstr "" msgid "You can only edit files when you are on a branch" msgstr "" -msgid "You can only merge once this merge request is approved." -msgstr "" - msgid "You can only transfer the project to namespaces you manage." msgstr "" @@ -41629,6 +41626,9 @@ msgstr "" msgid "mrWidget|Merge blocked: pipeline must succeed. It's waiting for a manual action to continue." msgstr "" +msgid "mrWidget|Merge blocked: this merge request must be approved." +msgstr "" + msgid "mrWidget|Merge failed." msgstr "" @@ -41773,9 +41773,6 @@ msgstr "" msgid "mrWidget|What is a merge train?" msgstr "" -msgid "mrWidget|You can only merge once this merge request is approved." -msgstr "" - msgid "mrWidget|Your password" msgstr "" diff --git a/spec/factories/protected_branches.rb b/spec/factories/protected_branches.rb index 2d3abc77350..bac1cf21596 100644 --- a/spec/factories/protected_branches.rb +++ b/spec/factories/protected_branches.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :protected_branch do - name + sequence(:name) { |n| "protected_branch_#{n}" } project transient do @@ -11,6 +11,20 @@ FactoryBot.define do default_access_level { true } end + trait :create_branch_on_repository do + association :project, factory: [:project, :repository] + + transient do + repository_branch_name { name } + end + + after(:create) do |protected_branch, evaluator| + project = protected_branch.project + + project.repository.create_branch(evaluator.repository_branch_name, project.default_branch_or_main) + end + end + trait :developers_can_push do transient do default_push_level { false } diff --git a/spec/lib/gitlab/database/partitioning/sliding_list_strategy_spec.rb b/spec/lib/gitlab/database/partitioning/sliding_list_strategy_spec.rb index 73474e8b38a..636a09e5710 100644 --- a/spec/lib/gitlab/database/partitioning/sliding_list_strategy_spec.rb +++ b/spec/lib/gitlab/database/partitioning/sliding_list_strategy_spec.rb @@ -37,8 +37,8 @@ RSpec.describe Gitlab::Database::Partitioning::SlidingListStrategy do describe '#current_partitions' do it 'detects both partitions' do expect(strategy.current_partitions).to eq([ - Gitlab::Database::Partitioning::SingleNumericListPartition.new(table_name, 1, partition_name: '_test_partitioned_test_1'), - Gitlab::Database::Partitioning::SingleNumericListPartition.new(table_name, 2, partition_name: '_test_partitioned_test_2') + Gitlab::Database::Partitioning::SingleNumericListPartition.new(table_name, 1, partition_name: '_test_partitioned_test_1'), + Gitlab::Database::Partitioning::SingleNumericListPartition.new(table_name, 2, partition_name: '_test_partitioned_test_2') ]) end end diff --git a/spec/lib/gitlab/import/import_failure_service_spec.rb b/spec/lib/gitlab/import/import_failure_service_spec.rb index c16d4a7c804..e3fec63adde 100644 --- a/spec/lib/gitlab/import/import_failure_service_spec.rb +++ b/spec/lib/gitlab/import/import_failure_service_spec.rb @@ -7,58 +7,48 @@ RSpec.describe Gitlab::Import::ImportFailureService, :aggregate_failures do let_it_be(:project) { create(:project, :import_started, import_type: import_type) } let(:exception) { StandardError.new('some error') } - let(:arguments) { { project_id: project.id } } - let(:base_arguments) { { error_source: 'SomeImporter', exception: exception }.merge(arguments) } - let(:exe_arguments) { { fail_import: false, metrics: false } } + let(:import_state) { nil } + let(:fail_import) { false } + let(:metrics) { false } + + let(:arguments) do + { + project_id: project.id, + error_source: 'SomeImporter', + exception: exception, + fail_import: fail_import, + metrics: metrics, + import_state: import_state + } + end describe '.track' do + let(:instance) { double(:failure_service) } + context 'with all arguments provided' do - let(:instance) { double(:failure_service) } - let(:instance_arguments) do + let(:arguments) do { exception: exception, import_state: '_import_state_', project_id: '_project_id_', - error_source: '_error_source_' - } - end - - let(:exe_arguments) do - { + error_source: '_error_source_', fail_import: '_fail_import_', metrics: '_metrics_' } end it 'invokes a new instance and executes' do - expect(described_class).to receive(:new).with(**instance_arguments).and_return(instance) - expect(instance).to receive(:execute).with(**exe_arguments) + expect(described_class).to receive(:new).with(**arguments).and_return(instance) + expect(instance).to receive(:execute) - described_class.track(**instance_arguments.merge(exe_arguments)) + described_class.track(**arguments) end end context 'with only necessary arguments utilizing defaults' do - let(:instance) { double(:failure_service) } - let(:instance_arguments) do - { - exception: exception, - import_state: nil, - project_id: nil, - error_source: nil - } - end - - let(:exe_arguments) do - { - fail_import: false, - metrics: false - } - end - it 'invokes a new instance and executes' do - expect(described_class).to receive(:new).with(**instance_arguments).and_return(instance) - expect(instance).to receive(:execute).with(**exe_arguments) + expect(described_class).to receive(:new).with(a_hash_including(exception: exception)).and_return(instance) + expect(instance).to receive(:execute) described_class.track(exception: exception) end @@ -66,7 +56,7 @@ RSpec.describe Gitlab::Import::ImportFailureService, :aggregate_failures do end describe '#execute' do - subject(:service) { described_class.new(**base_arguments) } + subject(:service) { described_class.new(**arguments) } shared_examples 'logs the exception and fails the import' do it 'when the failure does not abort the import' do @@ -89,13 +79,14 @@ RSpec.describe Gitlab::Import::ImportFailureService, :aggregate_failures do source: 'SomeImporter' ) - service.execute(**exe_arguments) + service.execute expect(project.import_state.reload.status).to eq('failed') expect(project.import_failures).not_to be_empty expect(project.import_failures.last.exception_class).to eq('StandardError') expect(project.import_failures.last.exception_message).to eq('some error') + expect(project.import_failures.last.retry_count).to eq(0) end end @@ -120,32 +111,36 @@ RSpec.describe Gitlab::Import::ImportFailureService, :aggregate_failures do source: 'SomeImporter' ) - service.execute(**exe_arguments) + service.execute expect(project.import_state.reload.status).to eq('started') expect(project.import_failures).not_to be_empty expect(project.import_failures.last.exception_class).to eq('StandardError') expect(project.import_failures.last.exception_message).to eq('some error') + expect(project.import_failures.last.retry_count).to eq(nil) end end context 'when tracking metrics' do - let(:exe_arguments) { { fail_import: false, metrics: true } } + let(:metrics) { true } it 'tracks the failed import' do - metrics = double(:metrics) + metrics_double = double(:metrics) - expect(Gitlab::Import::Metrics).to receive(:new).with("#{project.import_type}_importer", project).and_return(metrics) - expect(metrics).to receive(:track_failed_import) + expect(Gitlab::Import::Metrics) + .to receive(:new) + .with("#{project.import_type}_importer", project) + .and_return(metrics_double) + expect(metrics_double).to receive(:track_failed_import) - service.execute(**exe_arguments) + service.execute end end context 'when using the project as reference' do context 'when it fails the import' do - let(:exe_arguments) { { fail_import: true, metrics: false } } + let(:fail_import) { true } it_behaves_like 'logs the exception and fails the import' end @@ -156,10 +151,10 @@ RSpec.describe Gitlab::Import::ImportFailureService, :aggregate_failures do end context 'when using the import_state as reference' do - let(:arguments) { { import_state: project.import_state } } + let(:import_state) { project.import_state } context 'when it fails the import' do - let(:exe_arguments) { { fail_import: true, metrics: false } } + let(:fail_import) { true } it_behaves_like 'logs the exception and fails the import' end diff --git a/spec/models/integrations/microsoft_teams_spec.rb b/spec/models/integrations/microsoft_teams_spec.rb index 21b9a005746..033432f31a0 100644 --- a/spec/models/integrations/microsoft_teams_spec.rb +++ b/spec/models/integrations/microsoft_teams_spec.rb @@ -304,7 +304,7 @@ RSpec.describe Integrations::MicrosoftTeams do context 'with protected branch' do before do - create(:protected_branch, project: project, name: 'a-protected-branch') + create(:protected_branch, :create_branch_on_repository, project: project, name: 'a-protected-branch') end let(:pipeline) do diff --git a/spec/support/shared_examples/models/chat_integration_shared_examples.rb b/spec/support/shared_examples/models/chat_integration_shared_examples.rb index 72659dd5f3b..9ae727a87de 100644 --- a/spec/support/shared_examples/models/chat_integration_shared_examples.rb +++ b/spec/support/shared_examples/models/chat_integration_shared_examples.rb @@ -113,7 +113,7 @@ RSpec.shared_examples "chat integration" do |integration_name| context "with protected branch" do before do - create(:protected_branch, project: project, name: "a-protected-branch") + create(:protected_branch, :create_branch_on_repository, project: project, name: "a-protected-branch") end let(:sample_data) do @@ -309,7 +309,7 @@ RSpec.shared_examples "chat integration" do |integration_name| context "with protected branch" do before do - create(:protected_branch, project: project, name: "a-protected-branch") + create(:protected_branch, :create_branch_on_repository, project: project, name: "a-protected-branch") end let(:sample_data) do diff --git a/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb b/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb index 2d4c0b60f2b..ad15f82be5e 100644 --- a/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb +++ b/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb @@ -305,7 +305,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |service_name| context 'on a protected branch' do before do - create(:protected_branch, project: project, name: 'a-protected-branch') + create(:protected_branch, :create_branch_on_repository, project: project, name: 'a-protected-branch') end let(:data) do @@ -347,7 +347,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |service_name| context 'on a protected branch with protected branches defined using wildcards' do before do - create(:protected_branch, project: project, name: '*-stable') + create(:protected_branch, :create_branch_on_repository, repository_branch_name: '1-stable', project: project, name: '*-stable') end let(:data) do @@ -560,7 +560,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |service_name| context 'on a protected branch' do before do - create(:protected_branch, project: project, name: 'a-protected-branch') + create(:protected_branch, :create_branch_on_repository, project: project, name: 'a-protected-branch') end let(:pipeline) do @@ -590,7 +590,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |service_name| context 'on a protected branch with protected branches defined usin wildcards' do before do - create(:protected_branch, project: project, name: '*-stable') + create(:protected_branch, :create_branch_on_repository, repository_branch_name: '1-stable', project: project, name: '*-stable') end let(:pipeline) do -- cgit v1.2.3