Class: Dependabot::GithubActions::FileFetcher

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

Constant Summary collapse

FILENAME_PATTERN =
/\.ya?ml$/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, credentials:, repo_contents_path: nil, options: {}) ⇒ FileFetcher

Returns a new instance of FileFetcher.



37
38
39
40
# File 'lib/dependabot/github_actions/file_fetcher.rb', line 37

def initialize(source:, credentials:, repo_contents_path: nil, options: {})
  @workflow_files = T.let([], T::Array[DependencyFile])
  super
end

Class Method Details

.required_files_in?(filenames) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.required_files_in?(filenames)
  filenames.any? { |f| f.match?(FILENAME_PATTERN) }
end

.required_files_messageObject



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

def self.required_files_message
  "Repo must contain a .github/workflows directory with YAML files or an action.yml file"
end

Instance Method Details

#fetch_filesObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/dependabot/github_actions/file_fetcher.rb', line 43

def fetch_files
  fetched_files = []
  fetched_files += correctly_encoded_workflow_files

  return fetched_files if fetched_files.any?

  if incorrectly_encoded_workflow_files.none?
    expected_paths =
      if directory == "/"
        File.join(directory, "action.yml") + " or /.github/workflows/<anything>.yml"
      else
        File.join(directory, "<anything>.yml")
      end

    raise(
      Dependabot::DependencyFileNotFound,
      expected_paths
    )
  else
    raise(
      Dependabot::DependencyFileNotParseable,
      T.must(incorrectly_encoded_workflow_files.first).path
    )
  end
end