diff options
Diffstat (limited to 'app/services/merge_requests')
-rw-r--r-- | app/services/merge_requests/cleanup_refs_service.rb | 16 | ||||
-rw-r--r-- | app/services/merge_requests/refresh_service.rb | 6 | ||||
-rw-r--r-- | app/services/merge_requests/reopen_service.rb | 2 |
3 files changed, 19 insertions, 5 deletions
diff --git a/app/services/merge_requests/cleanup_refs_service.rb b/app/services/merge_requests/cleanup_refs_service.rb index d003124a112..23ac8e393f4 100644 --- a/app/services/merge_requests/cleanup_refs_service.rb +++ b/app/services/merge_requests/cleanup_refs_service.rb @@ -9,7 +9,7 @@ module MergeRequests attr_reader :merge_request def self.schedule(merge_request) - MergeRequestCleanupRefsWorker.perform_in(TIME_THRESHOLD, merge_request.id) + merge_request.create_cleanup_schedule(scheduled_at: TIME_THRESHOLD.from_now) end def initialize(merge_request) @@ -22,6 +22,7 @@ module MergeRequests end def execute + return error("Merge request is not scheduled to be cleaned up yet.") unless scheduled? return error("Merge request has not been closed nor merged for #{TIME_THRESHOLD.inspect}.") unless eligible? # Ensure that commit shas of refs are kept around so we won't lose them when GC runs. @@ -30,7 +31,10 @@ 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 + success end @@ -38,6 +42,10 @@ module MergeRequests attr_reader :repository, :ref_path, :merge_ref_path, :ref_head_sha, :merge_ref_sha + def scheduled? + merge_request.cleanup_schedule.present? && merge_request.cleanup_schedule.scheduled_at <= Time.current + end + def eligible? return met_time_threshold?(merge_request.metrics&.latest_closed_at) if merge_request.closed? @@ -71,5 +79,9 @@ module MergeRequests def delete_refs repository.delete_refs(ref_path, merge_ref_path) end + + def update_schedule + merge_request.cleanup_schedule.update(completed_at: Time.current) + end end end diff --git a/app/services/merge_requests/refresh_service.rb b/app/services/merge_requests/refresh_service.rb index e5d0b216d6c..ed977a5a872 100644 --- a/app/services/merge_requests/refresh_service.rb +++ b/app/services/merge_requests/refresh_service.rb @@ -42,7 +42,7 @@ module MergeRequests end notify_about_push(mr) - mark_mr_as_wip_from_commits(mr) + mark_mr_as_draft_from_commits(mr) execute_mr_web_hooks(mr) end @@ -246,7 +246,7 @@ module MergeRequests notification_service.push_to_merge_request(merge_request, @current_user, new_commits: new_commits, existing_commits: existing_commits) end - def mark_mr_as_wip_from_commits(merge_request) + def mark_mr_as_draft_from_commits(merge_request) return unless @commits.present? commit_shas = merge_request.commit_shas @@ -257,7 +257,7 @@ module MergeRequests if wip_commit && !merge_request.work_in_progress? merge_request.update(title: merge_request.wip_title) - SystemNoteService.add_merge_request_wip_from_commit( + SystemNoteService.add_merge_request_draft_from_commit( merge_request, merge_request.project, @current_user, diff --git a/app/services/merge_requests/reopen_service.rb b/app/services/merge_requests/reopen_service.rb index f87005bcb6c..bcedbc61c65 100644 --- a/app/services/merge_requests/reopen_service.rb +++ b/app/services/merge_requests/reopen_service.rb @@ -15,6 +15,8 @@ module MergeRequests invalidate_cache_counts(merge_request, users: merge_request.assignees) merge_request.update_project_counter_caches merge_request.cache_merge_request_closes_issues!(current_user) + merge_request.cleanup_schedule&.destroy + merge_request.update_column(:merge_ref_sha, nil) end merge_request |