Skip to content

Resolve "Clean up merge request branches that failed to be deleted"

What does this MR do and why?

Originally we had an issue where branches weren't being deleted after being merged, when they should have been. This impacted repo's that used merge trains, but didn't impact every merge request.

This rake task is designed to clean up those branches missed.

In this issue #385097 (closed), we discuss deleting

One batch for the query:

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/17617/commands/58825

To Test:

  • Run a DRY RUN with a valid project id bundle exec rake gitlab:cleanup:remove_missed_source_branches PROJECT_ID=X USER_ID=1 DRY_RUN=true
  • If it returns no merge requests add some by:
    • Starts rails console bundle exec rails c
    • Choose a project with merged MR's project = Project.find(X)
    • Load the mrs mrs = MergeRequest.merged.where(project: project).where( "merge_params LIKE '%force_remove_source_branch: ''1''%' OR merge_params LIKE '%should_remove_source_branch: ''1''%'")
    • Create branches for the merged mrs mrs.first(10).each { |mr| mr.source_project.repository.create_branch(mr.source_branch, mr.diff_head_sha) }
  • Run a DRY RUN with a valid project id bundle exec rake gitlab:cleanup:remove_missed_source_branches PROJECT_ID=X USER_ID=1 DRY_RUN=true
  • Run again but not dry run bundle exec rake gitlab:cleanup:remove_missed_source_branches PROJECT_ID=X USER_ID=1 DRY_RUN=false
  • Run a DRY RUN again and ensure it is empty
Edited by Marc Shaw

Merge request reports

Loading