class Dependabot::Clients::GitlabWithRetries
Constants
- RETRYABLE_ERRORS
Public Class Methods
for_gitlab_dot_com(credentials:)
click to toggle source
# File lib/dependabot/clients/gitlab_with_retries.rb, line 28 def self.for_gitlab_dot_com(credentials:) access_token = credentials. select { |cred| cred["type"] == "git_source" }. select { |cred| cred["password"] }. find { |cred| cred["host"] == "gitlab.com" }&. fetch("password") new( endpoint: "https://gitlab.com/api/v4", private_token: access_token || "" ) end
for_source(source:, credentials:)
click to toggle source
Constructor methods #
# File lib/dependabot/clients/gitlab_with_retries.rb, line 14 def self.for_source(source:, credentials:) access_token = credentials. select { |cred| cred["type"] == "git_source" }. select { |cred| cred["password"] }. find { |cred| cred["host"] == source.hostname }&. fetch("password") new( endpoint: source.api_endpoint, private_token: access_token || "" ) end
new(max_retries: 3, **args)
click to toggle source
Proxying #
# File lib/dependabot/clients/gitlab_with_retries.rb, line 58 def initialize(max_retries: 3, **args) @max_retries = max_retries || 3 @client = ::Gitlab::Client.new(args) end
Public Instance Methods
fetch_commit(repo, branch)
click to toggle source
VCS Interface #
# File lib/dependabot/clients/gitlab_with_retries.rb, line 46 def fetch_commit(repo, branch) branch(repo, branch).commit.id end
fetch_default_branch(repo)
click to toggle source
# File lib/dependabot/clients/gitlab_with_retries.rb, line 50 def fetch_default_branch(repo) project(repo).default_branch end
method_missing(method_name, *args, &block)
click to toggle source
Calls superclass method
# File lib/dependabot/clients/gitlab_with_retries.rb, line 63 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
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/dependabot/clients/gitlab_with_retries.rb, line 74 def respond_to_missing?(method_name, include_private = false) @client.respond_to?(method_name) || super end
retry_connection_failures() { || ... }
click to toggle source
# File lib/dependabot/clients/gitlab_with_retries.rb, line 78 def retry_connection_failures retry_attempt = 0 begin yield rescue *RETRYABLE_ERRORS retry_attempt += 1 retry_attempt <= @max_retries ? retry : raise end end