Module: Dependabot::Linguist

Defined in:
lib/dependabot/linguist.rb,
lib/dependabot/linguist/version.rb,
lib/dependabot/linguist/repository.rb,
lib/dependabot/linguist/dependabot_file_validator.rb,
lib/dependabot/linguist/languages_to_ecosystems/main.rb,
lib/dependabot/linguist/languages_to_ecosystems/contexts.rb,
lib/dependabot/linguist/languages_to_ecosystems/contexts_applied.rb,
lib/dependabot/linguist/languages_to_ecosystems/manager_ecosystem_maps.rb

Overview

rubocop:disable Style/Documentation

Defined Under Namespace

Modules: ContextRule, PackageEcosystems, PackageManagers Classes: DependabotFileValidator, Repository

Constant Summary collapse

VERSION =
"0.217.0"
CONTEXT_RULES =

Now apply the list of context rules to add ‘PackageManagers::`’s to the LANGUAGE_TO_PACKAGE_MANAGER map.

{
    PackageManagers::BUNDLER => {},
    PackageManagers::CARGO => {},
    PackageManagers::COMPOSER => {},
    PackageManagers::DOCKER => {},
    PackageManagers::HEX => {},
    PackageManagers::ELM_PACKAGE => {},
    PackageManagers::GIT_SUBMODULE => {},
    PackageManagers::GITHUB_ACTIONS => {},
    PackageManagers::GO_MODULES => {},
    PackageManagers::GRADLE => {},
    PackageManagers::MAVEN => {},
    PackageManagers::NPM => {},
    PackageManagers::NUGET => {},
    PackageManagers::PIP => {},
    PackageManagers::PIPENV => {},
    PackageManagers::PIP_COMPILE => {},
    PackageManagers::POETRY => {},
    PackageManagers::PUB => {},
    PackageManagers::TERRAFORM => {},
    PackageManagers::YARN => {}
}.freeze
LANGUAGE_TO_PACKAGE_MANAGER =

LANGUAGE_TO_PACKAGE_MANAGER should map any language linguist can discover, according to the “languages detected by linguist” link at the top, to a corresponding GitHub dependabot package manager.

Any language listed below could be surfaced by being added to the file lib/dependabot/linguist/languages_to_patch.txt, so they should exist in this map.

languages.to_h { |name, _| [name, nil] }.tap do |this|
  # Now apply the context rules to "this"
  CONTEXT_RULES.each do |package_manager, context_map|
    context_map.each do |_context_rule, linguist_languages|
      linguist_languages.each do |linguist_language|
        if this[linguist_language].nil?
          this[linguist_language] = [package_manager]
        else
          this[linguist_language] |= [package_manager]
        end
      end
    end
  end
end
PACKAGE_ECOSYSTEM_TO_FILE_FETCHERS_REGISTRY_KEY =

PACKAGE_ECOSYSTEM_TO_FILE_FETCHERS_REGISTRY_KEY maps PackageEcosystems to our end goal of the keys used to collect the respective file fetcher classes that are registered via the “file_fetchers register function” so each mapping |K,V| element should have a comment linking to the place that its value was registered!

{
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/bundler/lib/dependabot/bundler/file_fetcher.rb#L225
  PackageEcosystems::BUNDLER => "bundler",
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/cargo/lib/dependabot/cargo/file_fetcher.rb#L324
  PackageEcosystems::CARGO => "cargo",
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/composer/lib/dependabot/composer/file_fetcher.rb#L183
  PackageEcosystems::COMPOSER => "composer",
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/docker/lib/dependabot/docker/file_fetcher.rb#L101
  PackageEcosystems::DOCKER => "docker",
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/elm/lib/dependabot/elm/file_fetcher.rb#L46
  PackageEcosystems::ELM => "elm",
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/github_actions/lib/dependabot/github_actions/file_fetcher.rb#L79-L80
  PackageEcosystems::GITHUB_ACTIONS => "github_actions",
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/git_submodules/lib/dependabot/git_submodules/file_fetcher.rb#L88-L89
  PackageEcosystems::GIT_SUBMODULE => "submodules",
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/go_modules/lib/dependabot/go_modules/file_fetcher.rb#L67-L68
  PackageEcosystems::GOMOD => "go_modules",
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/gradle/lib/dependabot/gradle/file_fetcher.rb#L176
  PackageEcosystems::GRADLE => "gradle",
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/maven/lib/dependabot/maven/file_fetcher.rb#L162
  PackageEcosystems::MAVEN => "maven",
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/hex/lib/dependabot/hex/file_fetcher.rb#L97
  PackageEcosystems::MIX => "hex",
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/npm_and_yarn/lib/dependabot/npm_and_yarn/file_fetcher.rb#L527-L528
  PackageEcosystems::NPM => "npm_and_yarn",
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/nuget/lib/dependabot/nuget/file_fetcher.rb#L278
  PackageEcosystems::NUGET => "nuget",
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/python/lib/dependabot/python/file_fetcher.rb#L418
  PackageEcosystems::PIP => "pip",
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/pub/lib/dependabot/pub/file_fetcher.rb#L46
  PackageEcosystems::PUB => "pub",
  # https://github.com/dependabot/dependabot-core/blob/v0.217.0/terraform/lib/dependabot/terraform/file_fetcher.rb#L90-L91
  PackageEcosystems::TERRAFORM => "terraform"
}.freeze
PACKAGE_MANAGER_TO_PACKAGE_ECOSYSTEM =

PACKAGE_MANAGER_TO_PACKAGE_ECOSYSTEM maps PackageManagers to the PackageEcosystems, according to “#package-ecosystem”

{
  PackageManagers::BUNDLER => PackageEcosystems::BUNDLER,
  PackageManagers::CARGO => PackageEcosystems::CARGO,
  PackageManagers::COMPOSER => PackageEcosystems::COMPOSER,
  PackageManagers::DOCKER => PackageEcosystems::DOCKER,
  PackageManagers::HEX => PackageEcosystems::MIX,
  PackageManagers::ELM_PACKAGE => PackageEcosystems::ELM,
  PackageManagers::GIT_SUBMODULE => PackageEcosystems::GIT_SUBMODULE,
  PackageManagers::GITHUB_ACTIONS => PackageEcosystems::GITHUB_ACTIONS,
  PackageManagers::GO_MODULES => PackageEcosystems::GOMOD,
  PackageManagers::GRADLE => PackageEcosystems::GRADLE,
  PackageManagers::MAVEN => PackageEcosystems::MAVEN,
  PackageManagers::NPM => PackageEcosystems::NPM,
  PackageManagers::NUGET => PackageEcosystems::NUGET,
  PackageManagers::PIP => PackageEcosystems::PIP,
  PackageManagers::PIPENV => PackageEcosystems::PIP,
  PackageManagers::PIP_COMPILE => PackageEcosystems::PIP,
  PackageManagers::POETRY => PackageEcosystems::PIP,
  PackageManagers::PUB => PackageEcosystems::PUB,
  PackageManagers::TERRAFORM => PackageEcosystems::TERRAFORM,
  PackageManagers::YARN => PackageEcosystems::NPM
}.freeze

Class Method Summary collapse

Class Method Details

.linguist_languages_to_package_managers(languages) ⇒ Object

Returns the set of package managers mapped to in LANGUAGE_TO_PACKAGE_MANAGER



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dependabot/linguist/languages_to_ecosystems/main.rb', line 17

def self.linguist_languages_to_package_managers(languages)
  package_managers = []
  languages.each do |language|
    unless LANGUAGE_TO_PACKAGE_MANAGER[language].nil?
      if LANGUAGE_TO_PACKAGE_MANAGER[language].is_a?(Array)
        package_managers |= LANGUAGE_TO_PACKAGE_MANAGER[language]
      else
        package_managers |= [LANGUAGE_TO_PACKAGE_MANAGER[language]]
      end
    end
  end
  package_managers
end

.package_ecosystems_to_file_fetcher_registry_keys(package_ecosystems) ⇒ Object

Returns the set of file fetcher registry keys mapped to in PACKAGE_ECOSYSTEM_TO_FILE_FETCHERS_REGISTRY_KEY



45
46
47
48
49
50
51
52
53
# File 'lib/dependabot/linguist/languages_to_ecosystems/main.rb', line 45

def self.package_ecosystems_to_file_fetcher_registry_keys(package_ecosystems)
  file_fetcher_registry_keys = []
  package_ecosystems.each do |package_ecosystem|
    unless PACKAGE_ECOSYSTEM_TO_FILE_FETCHERS_REGISTRY_KEY[package_ecosystem].nil?
      file_fetcher_registry_keys |= [PACKAGE_ECOSYSTEM_TO_FILE_FETCHERS_REGISTRY_KEY[package_ecosystem]]
    end
  end
  file_fetcher_registry_keys
end

.package_managers_to_package_ecosystems(package_managers) ⇒ Object

Returns the set of package ecosystems mapped to in PACKAGE_MANAGER_TO_PACKAGE_ECOSYSTEM



33
34
35
36
37
38
39
40
41
# File 'lib/dependabot/linguist/languages_to_ecosystems/main.rb', line 33

def self.package_managers_to_package_ecosystems(package_managers)
  package_ecosystems = []
  package_managers.each do |package_manager|
    unless PACKAGE_MANAGER_TO_PACKAGE_ECOSYSTEM[package_manager].nil?
      package_ecosystems |= [PACKAGE_MANAGER_TO_PACKAGE_ECOSYSTEM[package_manager]]
    end
  end
  package_ecosystems
end