Class: Dependabot::Config::File

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/config/file.rb

Overview

Configuration for the repository, a parsed dependabot.yaml.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(updates:, registries: nil) ⇒ File

Returns a new instance of File.



26
27
28
29
# File 'lib/dependabot/config/file.rb', line 26

def initialize(updates:, registries: nil)
  @updates = T.let(updates || [], T::Array[T::Hash[Symbol, String]])
  @registries = T.let(registries || {}, T::Hash[Symbol, T::Hash[Symbol, String]])
end

Instance Attribute Details

#registriesObject (readonly)

Returns the value of attribute registries.



17
18
19
# File 'lib/dependabot/config/file.rb', line 17

def registries
  @registries
end

#updatesObject (readonly)

Returns the value of attribute updates.



14
15
16
# File 'lib/dependabot/config/file.rb', line 14

def updates
  @updates
end

Class Method Details

.parse(config) ⇒ Object

Raises:



50
51
52
53
54
55
56
# File 'lib/dependabot/config/file.rb', line 50

def self.parse(config)
  parsed = YAML.safe_load(config, symbolize_names: true)
  version = parsed[:version]
  raise InvalidConfigError, "invalid version #{version}" if version && version != 2

  File.new(updates: parsed[:updates], registries: parsed[:registries])
end

Instance Method Details

#update_config(package_manager, directory: nil, target_branch: nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dependabot/config/file.rb', line 35

def update_config(package_manager, directory: nil, target_branch: nil)
  dir = directory || "/"
  package_ecosystem = PACKAGE_MANAGER_LOOKUP.invert.fetch(package_manager)
  cfg = updates.find do |u|
    u[:"package-ecosystem"] == package_ecosystem && u[:directory] == dir &&
      (target_branch.nil? || u[:"target-branch"] == target_branch)
  end
  UpdateConfig.new(
    ignore_conditions: ignore_conditions(cfg),
    commit_message_options: commit_message_options(cfg)
  )
end