Commit 6f169b23 authored by Patrick Bajao's avatar Patrick Bajao

Do not fail when cleaning up MR with no repository

When we clean up refs of a merge request that is on a project
with no repository anymore, the MergeRequests::CleanupRefsService
will fail.

Before this fix, it'll throw an error and retry and will not set
the cleanup schedule as completed. When the cleanup schedule is
not marked as completed, it'll be picked up by the scheduler
again.

To fix that, we are now checking if the repository exists before
deleting refs. This way, we can still update the cleanup schedule.
parent 10e7586d
......@@ -31,7 +31,7 @@ module MergeRequests
return error('Failed to create keep around refs.') unless kept_around?
return error('Failed to cache merge ref sha.') unless cache_merge_ref_sha
delete_refs
delete_refs if repository.exists?
return error('Failed to update schedule.') unless update_schedule
......
---
title: Do not fail when cleaning up MR with no repository
merge_request: 47744
author:
type: fixed
......@@ -115,6 +115,19 @@ RSpec.describe MergeRequests::CleanupRefsService do
it_behaves_like 'service that does not clean up merge request refs'
end
context 'when repository no longer exists' do
before do
Repositories::DestroyService.new(merge_request.project.repository).execute
end
it 'does not fail and still mark schedule as complete' do
aggregate_failures do
expect(result[:status]).to eq(:success)
expect(merge_request.cleanup_schedule.completed_at).to be_present
end
end
end
end
shared_examples_for 'service that does not clean up merge request refs' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment