Class: Dependabot::PreCommit::FileParser::HookLanguageFetcher

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/pre_commit/file_parser/hook_language_fetcher.rb

Overview

Fetches hook language information from the source repository’s .pre-commit-hooks.yaml file. This is needed because the language field is typically defined in the hook repo, not in the consumer’s .pre-commit-config.yaml file.

Constant Summary collapse

HOOKS_FILE =
".pre-commit-hooks.yaml"

Instance Method Summary collapse

Constructor Details

#initialize(credentials:) ⇒ HookLanguageFetcher

Returns a new instance of HookLanguageFetcher.



30
31
32
33
# File 'lib/dependabot/pre_commit/file_parser/hook_language_fetcher.rb', line 30

def initialize(credentials:)
  @credentials = credentials
  @hooks_cache = T.let({}, T::Hash[String, T.nilable(T::Array[T::Hash[String, T.untyped]])])
end

Instance Method Details

#fetch_language(repo_url:, revision:, hook_id:) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/dependabot/pre_commit/file_parser/hook_language_fetcher.rb', line 48

def fetch_language(repo_url:, revision:, hook_id:)
  hooks = fetch_hooks_from_repo(repo_url, revision)
  return nil unless hooks

  hook = hooks.find { |h| h["id"] == hook_id }
  return nil unless hook

  T.cast(hook["language"], T.nilable(String))
end