Class: Dependabot::Config::File

Inherits:
Object
  • Object
show all
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.


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

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

Instance Attribute Details

#registriesObject (readonly)

Returns the value of attribute registries.


9
10
11
# File 'lib/dependabot/config/file.rb', line 9

def registries
  @registries
end

#updatesObject (readonly)

Returns the value of attribute updates.


9
10
11
# File 'lib/dependabot/config/file.rb', line 9

def updates
  @updates
end

Class Method Details

.parse(config) ⇒ Object

Parse the YAML config file

Raises:


30
31
32
33
34
35
36
# File 'lib/dependabot/config/file.rb', line 30

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


16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dependabot/config/file.rb', line 16

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
  Dependabot::Config::UpdateConfig.new(
    ignore_conditions: ignore_conditions(cfg),
    commit_message_options: commit_message_options(cfg)
  )
end