Class: Homebrew::Cmd::Source Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::Cmd::Source
- Defined in:
- cmd/source.rb,
sorbet/rbi/dsl/homebrew/cmd/source.rbi
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Defined Under Namespace
Classes: Args
Instance Method Summary collapse
- #args ⇒ Homebrew::Cmd::Source::Args private
- #bitbucket_repo_url(url) ⇒ String? private
- #codeberg_repo_url(url) ⇒ String? private
- #github_repo_url(url) ⇒ String? private
- #gitlab_repo_url(url) ⇒ String? private
- #npm_repo_url(url) ⇒ String? private
- #pypi_repo_url(url) ⇒ String? private
- #run ⇒ void private
- #sourcehut_repo_url(url) ⇒ String? private
- #url_to_repo(url) ⇒ String? private
Methods inherited from AbstractCommand
command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
This class inherits a constructor from Homebrew::AbstractCommand
Instance Method Details
#args ⇒ Homebrew::Cmd::Source::Args
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
10 |
# File 'sorbet/rbi/dsl/homebrew/cmd/source.rbi', line 10 def args; end |
#bitbucket_repo_url(url) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'cmd/source.rb', line 90 def bitbucket_repo_url(url) regex = %r{ https?://bitbucket\.org/ (?<user>[\w.-]+)/ (?<repo>[\w.-]+) (?:/.*)? }x match = url.match(regex) return unless match user = match[:user] repo = match[:repo]&.delete_suffix(".git") "https://bitbucket.org/#{user}/#{repo}" end |
#codeberg_repo_url(url) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'cmd/source.rb', line 106 def codeberg_repo_url(url) regex = %r{ https?://codeberg\.org/ (?<user>[\w.-]+)/ (?<repo>[\w.-]+) (?:/.*)? }x match = url.match(regex) return unless match user = match[:user] repo = match[:repo]&.delete_suffix(".git") "https://codeberg.org/#{user}/#{repo}" end |
#github_repo_url(url) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'cmd/source.rb', line 60 def github_repo_url(url) regex = %r{ https?://github\.com/ (?<user>[\w.-]+)/ (?<repo>[\w.-]+) (?:/.*)? }x match = url.match(regex) return unless match user = match[:user] repo = match[:repo]&.delete_suffix(".git") "https://github.com/#{user}/#{repo}" end |
#gitlab_repo_url(url) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'cmd/source.rb', line 76 def gitlab_repo_url(url) regex = %r{ https?://gitlab\.com/ (?<path>(?:[\w.-]+/)*?[\w.-]+) (?:/-/|\.git|/archive/) }x match = url.match(regex) return unless match path = match[:path]&.delete_suffix(".git") "https://gitlab.com/#{path}" end |
#npm_repo_url(url) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'cmd/source.rb', line 168 def npm_repo_url(url) regex = %r{ https?://registry\.npmjs\.org/ (?<package_name>(?:@[\w.-]+/)?[\w.-]+)/ (?:/.*)? }x match = url.match(regex) return unless match package_name = match[:package_name] return unless package_name api_url = "https://registry.npmjs.org/#{URI.encode_uri_component(package_name)}/latest" curl_args = Utils::Curl.curl_args(show_error: false, retries: 2) stdout, _, status = Utils::Curl.curl_output(*curl_args, api_url) return unless status.success? url = JSON.parse(stdout).dig("repository", "url") url&.delete_prefix("git+") rescue JSON::ParserError nil end |
#pypi_repo_url(url) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'cmd/source.rb', line 138 def pypi_repo_url(url) regex = %r{ https?://files\.pythonhosted\.org /packages (?:/[^/]+)+ /(?<package_name>.+)- .*? (?:\.tar\.[a-z0-9]+|\.[a-z0-9]+) }x match = url.match(regex) return unless match package_name = match[:package_name] return unless package_name api_url = "https://pypi.org/pypi/#{package_name.gsub(/%20|_/, "-")}/json" curl_args = Utils::Curl.curl_args(show_error: false, retries: 2) stdout, _, status = Utils::Curl.curl_output(*curl_args, api_url) return unless status.success? project_urls = JSON.parse(stdout).dig("info", "project_urls")&.transform_keys(&:downcase) project_urls["repository"] || project_urls["source"] || url_to_repo(project_urls.fetch("homepage", "")) # Homepages often link to source repositories rescue JSON::ParserError nil end |
#run ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'cmd/source.rb', line 25 def run if args.no_named? exec_browser "https://github.com/Homebrew/brew" return end formulae = args.named.to_formulae repo_urls = formulae.filter_map do |formula| repo_url = extract_repo_url(formula) if repo_url puts "Opening repository for #{formula.name}" repo_url else opoo "Could not determine repository URL for #{formula.name}" nil end end return if repo_urls.empty? exec_browser(*repo_urls) end |
#sourcehut_repo_url(url) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'cmd/source.rb', line 122 def sourcehut_repo_url(url) regex = %r{ https?://(?:git\.)?sr\.ht/ ~(?<user>[\w.-]+)/ (?<repo>[\w.-]+) (?:/.*)? }x match = url.match(regex) return unless match user = match[:user] repo = match[:repo]&.delete_suffix(".git") "https://sr.ht/~#{user}/#{repo}" end |
#url_to_repo(url) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
49 50 51 52 53 54 55 56 57 |
# File 'cmd/source.rb', line 49 def url_to_repo(url) github_repo_url(url) || gitlab_repo_url(url) || bitbucket_repo_url(url) || codeberg_repo_url(url) || sourcehut_repo_url(url) || pypi_repo_url(url) || npm_repo_url(url) end |