Class: Dependabot::NpmAndYarn::RegistryParser
- Inherits:
-
Object
- Object
- Dependabot::NpmAndYarn::RegistryParser
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/npm_and_yarn/registry_parser.rb
Instance Method Summary collapse
- #dependency_name ⇒ Object
-
#initialize(resolved_url:, credentials:) ⇒ RegistryParser
constructor
A new instance of RegistryParser.
- #registry_source_for(name) ⇒ Object
Constructor Details
#initialize(resolved_url:, credentials:) ⇒ RegistryParser
Returns a new instance of RegistryParser.
12 13 14 15 |
# File 'lib/dependabot/npm_and_yarn/registry_parser.rb', line 12 def initialize(resolved_url:, credentials:) @resolved_url = resolved_url @credentials = credentials end |
Instance Method Details
#dependency_name ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dependabot/npm_and_yarn/registry_parser.rb', line 41 def dependency_name url_base = if resolved_url.include?("/-/") T.must(resolved_url.split("/-/").first) else resolved_url end package_name = url_base.gsub("%2F", "/").match(%r{@.*/}) return T.must(url_base.gsub("%2F", "/").split("/").last) unless package_name "#{package_name}#{T.must(url_base.gsub('%2F', '/').split('/').last)}" end |
#registry_source_for(name) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dependabot/npm_and_yarn/registry_parser.rb', line 18 def registry_source_for(name) url = if resolved_url.include?("/~/") # Gemfury format resolved_url.split("/~/").first elsif resolved_url.include?("/#{name}/-/#{name}") # MyGet / Bintray format T.must(resolved_url.split("/#{name}/-/#{name}").first) .gsub("dl.bintray.com//", "api.bintray.com/npm/"). # GitLab format gsub(%r{\/projects\/\d+}, "") elsif resolved_url.include?("/#{name}/-/#{name.split('/').last}") # Sonatype Nexus / Artifactory JFrog format resolved_url.split("/#{name}/-/#{name.split('/').last}").first elsif (cred_url = url_for_relevant_cred) then cred_url else T.must(resolved_url.split("/")[0..2]).join("/") end { type: "registry", url: url } end |