debian-mirror-gitlab/app/services/projects/update_remote_mirror_service.rb

34 lines
771 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2018-10-15 14:42:47 +05:30
module Projects
class UpdateRemoteMirrorService < BaseService
attr_reader :errors
def execute(remote_mirror)
return success unless remote_mirror.enabled?
2018-12-05 23:21:45 +05:30
errors = []
2018-10-15 14:42:47 +05:30
begin
2018-11-20 20:47:30 +05:30
remote_mirror.ensure_remote!
2019-02-15 15:39:39 +05:30
repository.fetch_remote(remote_mirror.remote_name, ssh_auth: remote_mirror, no_tags: true)
2018-10-15 14:42:47 +05:30
opts = {}
if remote_mirror.only_protected_branches?
opts[:only_branches_matching] = project.protected_branches.select(:name).map(&:name)
end
remote_mirror.update_repository(opts)
rescue => e
errors << e.message.strip
end
if errors.present?
error(errors.join("\n\n"))
else
success
end
end
end
end