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