Class: Dependabot::Pub::FileFetcher

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.required_files_in?(filenames) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/dependabot/pub/file_fetcher.rb', line 18

def self.required_files_in?(filenames)
  filenames.include?("pubspec.yaml")
end

.required_files_messageObject



23
24
25
# File 'lib/dependabot/pub/file_fetcher.rb', line 23

def self.required_files_message
  "Repo must contain a pubspec.yaml."
end

Instance Method Details

#fetch_filesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dependabot/pub/file_fetcher.rb', line 28

def fetch_files
  fetched_files = []
  fetched_files << pubspec_yaml
  fetched_files << pubspec_lock if pubspec_lock
  # Fetch any additional pubspec.yamls in the same git repo for resolving
  # local path-dependencies and workspace packages.
  extra_pubspecs = Dir.glob("**/pubspec.yaml", base: clone_repo_contents)
  fetched_files += extra_pubspecs.filter_map do |pubspec|
    relative_name = Pathname.new("/#{pubspec}").relative_path_from(directory)

    # Skip excluded workspace pubspec files
    next nil if Dependabot::FileFiltering.should_exclude_path?(
      relative_name.to_s,
      "workspace pubspec file",
      @exclude_paths
    )

    fetch_file_from_host(relative_name)
  end

  # Filter excluded files from final collection
  filtered_files = fetched_files.uniq.reject do |file|
    file_name = T.cast(file, DependencyFile).name
    Dependabot::FileFiltering.should_exclude_path?(
      file_name,
      "file from final collection",
      @exclude_paths
    )
  end

  filtered_files
end