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.



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

def initialize(updates:, registries: nil)
  @updates = updates || []
  @registries = registries || []
end

Instance Attribute Details

#registriesObject (readonly)

Returns the value of attribute registries.



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

def registries
  @registries
end

#updatesObject (readonly)

Returns the value of attribute updates.



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

def updates
  @updates
end

Class Method Details

.parse(config) ⇒ Object

Raises:



39
40
41
42
43
44
45
# File 'lib/dependabot/config/file.rb', line 39

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



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dependabot/config/file.rb', line 24

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