From 81e485128217cabfab4d0616ed073cf6cdc65d52 Mon Sep 17 00:00:00 2001 From: Darren Worrall Date: Wed, 13 Nov 2024 16:01:55 +0000 Subject: [PATCH] Fix stack deletion take two --- app/jobs/shipit/destroy_stack_job.rb | 11 +++++++++-- test/jobs/destroy_stack_job_test.rb | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/jobs/shipit/destroy_stack_job.rb b/app/jobs/shipit/destroy_stack_job.rb index 585b226a0..6d26fa7d2 100644 --- a/app/jobs/shipit/destroy_stack_job.rb +++ b/app/jobs/shipit/destroy_stack_job.rb @@ -22,8 +22,15 @@ def perform(stack) commit_deployments_ids = Shipit::CommitDeployment.where(task_id: tasks_ids).pluck(:id) Shipit::CommitDeploymentStatus.where(commit_deployment_id: commit_deployments_ids).in_batches(&:delete_all) Shipit::CommitDeployment.where(id: commit_deployments_ids).in_batches(&:delete_all) - Shipit::Status.where(commit_id: commits_ids).in_batches(&:delete_all) - Shipit::Commit.where(id: commits_ids).in_batches(&:delete_all) + + Shipit::Status.where(commit_id: commits_ids).find_in_batches do |batch| + Shipit::Status.where(id: batch.map(&:id)).delete_all + end + + Shipit::Commit.where(id: commits_ids).find_in_batches do |batch| + Shipit::Commit.where(id: batch.map(&:id)).delete_all + end + Shipit::GithubHook.where(stack_id: stack.id).destroy_all Shipit::Hook.where(stack_id: stack.id).in_batches(&:delete_all) Shipit::MergeRequest.where(stack_id: stack.id).in_batches(&:delete_all) diff --git a/test/jobs/destroy_stack_job_test.rb b/test/jobs/destroy_stack_job_test.rb index 48e817f75..59db7a102 100644 --- a/test/jobs/destroy_stack_job_test.rb +++ b/test/jobs/destroy_stack_job_test.rb @@ -24,5 +24,14 @@ class DestroyStackJobTest < ActiveSupport::TestCase @job.perform(stack) end end + + test "perform destroys the all Status of related commits" do + stack = shipit_stacks(:shipit) + Shipit.legacy_github_api.stubs(:remove_hook) + + assert_changes -> { Status.count }, 'Statuses are not deleted' do + @job.perform(stack) + end + end end end