Class: Dependabot::Clients::BitbucketWithRetries

Inherits:
Object
  • 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.



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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

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

Class Method Details

.for_bitbucket_dot_org(credentials:) ⇒ Object



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

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)


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

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

#retry_connection_failures(&_blk) ⇒ Object



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

def retry_connection_failures(&_blk)
  retry_attempt = 0

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