after_import_service.rb 675 Bytes
Newer Older
1 2
# frozen_string_literal: true

Lin Jen-Shin's avatar
Lin Jen-Shin committed
3 4
module Projects
  class AfterImportService
5
    RESERVED_REF_PREFIXES = Repository::RESERVED_REFS_NAMES.map { |n| File.join('refs', n, '/') }
Lin Jen-Shin's avatar
Lin Jen-Shin committed
6 7 8 9 10 11

    def initialize(project)
      @project = project
    end

    def execute
12
      Projects::HousekeepingService.new(@project, :gc).execute do
13
        repository.delete_all_refs_except(RESERVED_REF_PREFIXES)
Lin Jen-Shin's avatar
Lin Jen-Shin committed
14 15 16 17 18 19 20 21 22 23 24 25 26
      end
    rescue Projects::HousekeepingService::LeaseTaken => e
      Rails.logger.info(
        "Could not perform housekeeping for project #{@project.full_path} (#{@project.id}): #{e}")
    end

    private

    def repository
      @repository ||= @project.repository
    end
  end
end