Class: Projects::UpdateRemoteMirrorService

Inherits:
BaseService
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/projects/update_remote_mirror_service.rb

Constant Summary collapse

MAX_TRIES =
3

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#execute(remote_mirror, tries) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/projects/update_remote_mirror_service.rb', line 9

def execute(remote_mirror, tries)
  return success unless remote_mirror.enabled?

  # Blocked URLs are a hard failure, no need to attempt to retry
  if Gitlab::HTTP_V2::UrlBlocker.blocked_url?(
    normalized_url(remote_mirror.url),
    schemes: Project::VALID_MIRROR_PROTOCOLS,
    allow_localhost: Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?,
    allow_local_network: Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?,
    deny_all_requests_except_allowed: Gitlab::CurrentSettings.deny_all_requests_except_allowed?,
    outbound_local_requests_allowlist: Gitlab::CurrentSettings.outbound_local_requests_whitelist # rubocop:disable Naming/InclusiveLanguage -- existing setting
  )
    hard_retry_or_fail(remote_mirror, _('The remote mirror URL is invalid.'), tries)
    return error(remote_mirror.last_error)
  end

  update_mirror(remote_mirror)

  success
rescue Gitlab::Git::CommandError => e
  # This happens if one of the gitaly calls above fail, for example when
  # branches have diverged, or the pre-receive hook fails.
  hard_retry_or_fail(remote_mirror, e.message, tries)

  error(e.message)
rescue StandardError => e
  remote_mirror.hard_fail!(e.message)
  raise e
end