Class: Dependabot::Bundler::UpdateChecker::LatestVersionFinder::DependencySource

Inherits:
Object
  • Object
show all
Includes:
SharedBundlerHelpers
Defined in:
lib/dependabot/bundler/update_checker/latest_version_finder/dependency_source.rb

Constant Summary collapse

RUBYGEMS =
"rubygems"
PRIVATE_REGISTRY =
"private"
GIT =
"git"
OTHER =
"other"

Constants included from SharedBundlerHelpers

SharedBundlerHelpers::GIT_REF_REGEX, SharedBundlerHelpers::GIT_REGEX, SharedBundlerHelpers::PATH_REGEX, SharedBundlerHelpers::RETRYABLE_ERRORS, SharedBundlerHelpers::RETRYABLE_PRIVATE_REGISTRY_ERRORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SharedBundlerHelpers

#base_directory, #handle_bundler_errors, #in_a_native_bundler_context, #inaccessible_git_dependencies, #jfrog_source, #private_registry_credentials, #retryable_error?, #sanitized_lockfile_body, #write_temporary_dependency_files

Constructor Details

#initialize(dependency:, dependency_files:, credentials:, options:) ⇒ DependencySource

Returns a new instance of DependencySource.



22
23
24
25
26
27
28
29
30
# File 'lib/dependabot/bundler/update_checker/latest_version_finder/dependency_source.rb', line 22

def initialize(dependency:,
               dependency_files:,
               credentials:,
               options:)
  @dependency          = dependency
  @dependency_files    = dependency_files
  @credentials         = credentials
  @options             = options
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



19
20
21
# File 'lib/dependabot/bundler/update_checker/latest_version_finder/dependency_source.rb', line 19

def credentials
  @credentials
end

#dependencyObject (readonly)

Returns the value of attribute dependency.



19
20
21
# File 'lib/dependabot/bundler/update_checker/latest_version_finder/dependency_source.rb', line 19

def dependency
  @dependency
end

#dependency_filesObject (readonly)

Returns the value of attribute dependency_files.



19
20
21
# File 'lib/dependabot/bundler/update_checker/latest_version_finder/dependency_source.rb', line 19

def dependency_files
  @dependency_files
end

#optionsObject (readonly)

Returns the value of attribute options.



19
20
21
# File 'lib/dependabot/bundler/update_checker/latest_version_finder/dependency_source.rb', line 19

def options
  @options
end

#repo_contents_pathObject (readonly)

Returns the value of attribute repo_contents_path.



19
20
21
# File 'lib/dependabot/bundler/update_checker/latest_version_finder/dependency_source.rb', line 19

def repo_contents_path
  @repo_contents_path
end

Instance Method Details

#git?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/dependabot/bundler/update_checker/latest_version_finder/dependency_source.rb', line 77

def git?
  source_type == GIT
end

#latest_git_version_detailsHash{Symbol => String}?

The latest version details for the dependency from a git repo

Returns:

  • (Hash{Symbol => String}, nil)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/dependabot/bundler/update_checker/latest_version_finder/dependency_source.rb', line 52

def latest_git_version_details
  return unless git?

  source_details =
    dependency.requirements.map { |r| r.fetch(:source) }.
    uniq.compact.first

  SharedHelpers.with_git_configured(credentials: credentials) do
    in_a_native_bundler_context do |tmp_dir|
      NativeHelpers.run_bundler_subprocess(
        bundler_version: bundler_version,
        function: "depencency_source_latest_git_version",
        args: {
          dir: tmp_dir,
          gemfile_name: gemfile.name,
          dependency_name: dependency.name,
          credentials: credentials,
          dependency_source_url: source_details[:url],
          dependency_source_branch: source_details[:branch]
        }
      )
    end
  end.transform_keys(&:to_sym)
end

#versionsArray<Gem::Version>

The latest version details for the dependency from a registry

Returns:

  • (Array<Gem::Version>)


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dependabot/bundler/update_checker/latest_version_finder/dependency_source.rb', line 35

def versions
  return rubygems_versions if dependency.name == "bundler"
  return rubygems_versions unless gemfile

  case source_type
  when OTHER, GIT
    []
  when PRIVATE_REGISTRY
    private_registry_versions
  else
    rubygems_versions
  end
end