Class: Dependabot::Cargo::FileFetcher

Inherits:
FileFetchers::Base
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/dependabot/cargo/file_fetcher.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.required_files_in?(filenames) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/dependabot/cargo/file_fetcher.rb', line 20

def self.required_files_in?(filenames)
  filenames.include?("Cargo.toml")
end

.required_files_messageObject



24
25
26
# File 'lib/dependabot/cargo/file_fetcher.rb', line 24

def self.required_files_message
  "Repo must contain a Cargo.toml."
end

Instance Method Details

#ecosystem_versionsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dependabot/cargo/file_fetcher.rb', line 28

def ecosystem_versions
  channel = if rust_toolchain
              TomlRB.parse(rust_toolchain.content).fetch("toolchain", nil)&.fetch("channel", nil)
            else
              "default"
            end

  {
    package_managers: {
      "cargo" => channel
    }
  }
rescue TomlRB::ParseError
  raise Dependabot::DependencyFileNotParseable.new(
    rust_toolchain.path,
    "only rust-toolchain files formatted as TOML are supported, the non-TOML format was deprecated by Rust"
  )
end

#fetch_filesObject



48
49
50
51
52
53
54
55
56
# File 'lib/dependabot/cargo/file_fetcher.rb', line 48

def fetch_files
  fetched_files = T.let([], T::Array[DependencyFile])
  fetched_files << cargo_toml
  fetched_files << cargo_lock if cargo_lock
  fetched_files << cargo_config if cargo_config
  fetched_files << rust_toolchain if rust_toolchain
  fetched_files += fetch_path_dependency_and_workspace_files
  fetched_files.uniq
end