Skip to content

Skip approval updates for merged MRs

James Nutt requested to merge jnutt/skip-cb-on-merged-mrs into master

What does this MR do and why?

Skip approval updates for merged MRs

This callback is causing note imports to fail for projects with aproval rules configured. When a merge request is imported, if approvals_before_merge is not nil and the MR has already been merged, the approval rule generated by any_approver_rule will fail validation, and the subsequent call to update_column will result in an exception.

!138154 (merged) validates against updating approval rules for merged MRs, so in this case it should be safe to skip the callback for merged MRs.

Changelog: fixed EE: true

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After
CleanShot_2024-07-02_at_11.22.18_2x CleanShot_2024-07-02_at_11.31.54_2x

Failure record before:

failures = bulk_import.entities.collect { |e| e.has_failures? && e.failures }.flatten
=> [false,
 #<BulkImports::Failure:0x000000031441ec38
  id: 1,
  bulk_import_entity_id: 14,
  created_at: Tue, 02 Jul 2024 09:01:25.463374000 UTC +00:00,
  pipeline_class: "BulkImports::Projects::Pipelines::MergeRequestsPipeline",
  exception_class: "ActiveRecord::ActiveRecordError",
  exception_message: "cannot update a new record",
  correlation_id_value: "01J1SARQ3Z7QJAWZ634AEM109P",
  pipeline_step: "loader",
  source_url: "http://gdk.test:3000/rfh-import/rfh-import/-/merge_requests/1",
  source_title: "a file",
  subrelation: nil>]

How to set up and validate locally

  1. Enable Direct Transfer and local requests via your Rails console:
    ApplicationSetting.first.update(
      allow_local_requests_from_web_hooks_and_services: true,
      bulk_import_enabled: true
    )
  2. Create a source group and a destination group. Make both groups premium/ultimate.
  3. Create a merge request in the source group and merge it. In the Rails console, update the old approvals_before_merge column:
    MergeRequest.last.update(approvals_before_merge: 2)
  4. Trigger a direct transfer from the source group into the destination group.

Outcome before change: The MR is imported, but notes are missing. The bulk import has the attached errors found above.

Outcome after change: The MR is imported with all notes and no errors.

Edited by James Nutt

Merge request reports