Class: Dependabot::Clients::BitbucketWithRetries

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/clients/bitbucket_with_retries.rb

Constant Summary collapse

RETRYABLE_ERRORS =
[
  Excon::Error::Timeout,
  Excon::Error::Socket
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_retries: 3, **args) ⇒ BitbucketWithRetries

Proxying #



30
31
32
33
# File 'lib/dependabot/clients/bitbucket_with_retries.rb', line 30

def initialize(max_retries: 3, **args)
  @max_retries = max_retries || 3
  @client = Bitbucket.new(args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/dependabot/clients/bitbucket_with_retries.rb', line 35

def method_missing(method_name, *args, &block)
  retry_connection_failures do
    if @client.respond_to?(method_name)
      mutatable_args = args.map(&:dup)
      @client.public_send(method_name, *mutatable_args, &block)
    else
      super
    end
  end
end

Class Method Details

.for_bitbucket_dot_org(credentials:) ⇒ Object

Constructor methods #



17
18
19
20
21
22
23
24
# File 'lib/dependabot/clients/bitbucket_with_retries.rb', line 17

def self.for_bitbucket_dot_org(credentials:)
  credential =
    credentials.
    select { |cred| cred["type"] == "git_source" }.
    find { |cred| cred["host"] == "bitbucket.org" }

  new(credentials: credential)
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/dependabot/clients/bitbucket_with_retries.rb', line 46

def respond_to_missing?(method_name, include_private = false)
  @client.respond_to?(method_name) || super
end

#retry_connection_failuresObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/dependabot/clients/bitbucket_with_retries.rb', line 50

def retry_connection_failures
  retry_attempt = 0

  begin
    yield
  rescue *RETRYABLE_ERRORS
    retry_attempt += 1
    retry_attempt <= @max_retries ? retry : raise
  end
end