GitLab steht aufgrund wichtiger Wartungsarbeiten am Montag, den 8. März, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

after_import_service.rb 729 Bytes
Newer Older
Lin Jen-Shin's avatar
Lin Jen-Shin committed
1 2 3
module Projects
  class AfterImportService
    RESERVED_REFS_REGEXP =
4
      %r{\Arefs/(?:#{Regexp.union(*Repository::RESERVED_REFS_NAMES)})/}
Lin Jen-Shin's avatar
Lin Jen-Shin committed
5 6 7 8 9 10 11

    def initialize(project)
      @project = project
    end

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

    private

    def garbage_refs
      @garbage_refs ||= repository.all_ref_names_except(RESERVED_REFS_REGEXP)
    end

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