2018-07-17 12:50:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-03 08:55:14 -04:00
|
|
|
module Projects
|
|
|
|
class UpdateRemoteMirrorService < BaseService
|
|
|
|
attr_reader :errors
|
|
|
|
|
|
|
|
def execute(remote_mirror)
|
|
|
|
return success unless remote_mirror.enabled?
|
|
|
|
|
2018-09-10 15:12:49 -04:00
|
|
|
errors = []
|
|
|
|
|
2018-05-03 08:55:14 -04:00
|
|
|
begin
|
2018-08-22 13:43:15 -04:00
|
|
|
remote_mirror.ensure_remote!
|
2018-11-12 05:52:48 -05:00
|
|
|
repository.fetch_remote(remote_mirror.remote_name, ssh_auth: remote_mirror, no_tags: true)
|
2018-05-03 08:55:14 -04:00
|
|
|
|
|
|
|
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
|