Class: Dependabot::Clients::BitbucketWithRetries

Inherits:
SimpleDelegator
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/clients/bitbucket_with_retries.rb

Constant Summary collapse

RETRYABLE_ERRORS =
T.let(
  [Excon::Error::Timeout, Excon::Error::Socket].freeze,
  T::Array[T.class_of(Excon::Error)]
)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credentials:, max_retries: 3) ⇒ BitbucketWithRetries

Returns a new instance of BitbucketWithRetries.



38
39
40
41
42
# File 'lib/dependabot/clients/bitbucket_with_retries.rb', line 38

def initialize(credentials:, max_retries: 3)
  @max_retries = T.let(max_retries || 3, Integer)
  @client = T.let(Bitbucket.new(credentials: credentials), Dependabot::Clients::Bitbucket)
  super(@client)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

def method_missing(method_name, *args, &block)
  original_args = args
  retry_connection_failures do
    args = original_args.map(&:dup)
    super
  end
end

Class Method Details

.for_bitbucket_dot_org(credentials:) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/dependabot/clients/bitbucket_with_retries.rb', line 24

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)


67
68
69
# File 'lib/dependabot/clients/bitbucket_with_retries.rb', line 67

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

#retry_connection_failures(&_blk) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/dependabot/clients/bitbucket_with_retries.rb', line 76

def retry_connection_failures(&_blk)
  retry_attempt = 0

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