Module: SharedAudits Private
- Defined in:
- utils/shared_audits.rb
Overview
This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.
Auditing functions for rules common to both casks and formulae.
Constant Summary collapse
- URL_TYPE_HOMEPAGE =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"homepage URL"- SELF_SUBMISSION_THRESHOLD_MULTIPLIER =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
3- GITHUB_NOTABILITY_THRESHOLDS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.let({ forks: 30, watchers: 30, stars: 75 }.freeze, T::Hash[Symbol, Integer])
- GITLAB_NOTABILITY_THRESHOLDS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.let({ forks: 30, stars: 75 }.freeze, T::Hash[Symbol, Integer])
- BITBUCKET_NOTABILITY_THRESHOLDS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.let({ forks: 30, watchers: 75 }.freeze, T::Hash[Symbol, Integer])
- FORGEJO_NOTABILITY_THRESHOLDS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.let({ forks: 30, watchers: 30, stars: 75 }.freeze, T::Hash[Symbol, Integer])
Class Method Summary collapse
- .bitbucket(user, repo, self_submission: false) ⇒ String? private
- .check_deprecate_disable_reason(formula_or_cask) ⇒ String? private
- .eol_data(product, cycle) ⇒ Hash{String => T.untyped}? private
- .forgejo(user, repo, self_submission: false) ⇒ String? private
- .forgejo_release(user, repo, tag, formula: nil, cask: nil) ⇒ String? private
- .forgejo_repo_data(user, repo) ⇒ Hash{String => T.untyped}? private
- .forgejo_tag_from_url(url) ⇒ String? private
- .github(user, repo, self_submission: false) ⇒ String? private
- .github_release(user, repo, tag, formula: nil, cask: nil) ⇒ String? private
- .github_repo_data(user, repo) ⇒ Hash{String => T.untyped}? private
- .github_tag_from_url(url) ⇒ String? private
- .gitlab(user, repo, self_submission: false) ⇒ String? private
- .gitlab_release(user, repo, tag, formula: nil, cask: nil) ⇒ String? private
- .gitlab_repo_data(user, repo) ⇒ Hash{String => T.untyped}? private
- .gitlab_tag_from_url(url) ⇒ String? private
- .no_autobump_new_package_message(message) ⇒ String? private
- .notability_thresholds_for(thresholds, self_submission) ⇒ Hash{Symbol => Integer} private
- .pull_request_author ⇒ String? private
- .self_submission?(submitter, repo_owner) ⇒ Boolean private
- .self_submission_for_repo_owner?(repo_owner) ⇒ Boolean private
Class Method Details
.bitbucket(user, repo, self_submission: false) ⇒ 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.
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'utils/shared_audits.rb', line 274 def self.bitbucket(user, repo, self_submission: false) api_url = "https://api.bitbucket.org/2.0/repositories/#{user}/#{repo}" result = Utils::Curl.curl_output("--request", "GET", api_url) return unless result.status.success? = JSON.parse(result.stdout) return if .nil? return "Uses deprecated Mercurial support in Bitbucket" if ["scm"] == "hg" return "Bitbucket fork (not canonical repository)" unless ["parent"].nil? return "Bitbucket repository too new (<30 days old)" if Date.parse(["created_on"]) >= (Date.today - 30) forks_result = Utils::Curl.curl_output("--request", "GET", "#{api_url}/forks") return unless forks_result.status.success? watcher_result = Utils::Curl.curl_output("--request", "GET", "#{api_url}/watchers") return unless watcher_result.status.success? = JSON.parse(forks_result.stdout) return if .nil? = JSON.parse(watcher_result.stdout) return if .nil? notability_thresholds = notability_thresholds_for(BITBUCKET_NOTABILITY_THRESHOLDS, self_submission) return if ["size"] >= notability_thresholds.fetch(:forks) || ["size"] >= notability_thresholds.fetch(:watchers) notability_prefix = if self_submission "Self-submitted Bitbucket repository not notable enough" else "Bitbucket repository not notable enough" end "#{notability_prefix} (<#{notability_thresholds.fetch(:forks)} forks and " \ "<#{notability_thresholds.fetch(:watchers)} watchers)" end |
.check_deprecate_disable_reason(formula_or_cask) ⇒ 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.
356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'utils/shared_audits.rb', line 356 def self.check_deprecate_disable_reason(formula_or_cask) return if !formula_or_cask.deprecated? && !formula_or_cask.disabled? reason = formula_or_cask.deprecated? ? formula_or_cask.deprecation_reason : formula_or_cask.disable_reason return unless reason.is_a?(Symbol) reasons = if formula_or_cask.is_a?(Formula) DeprecateDisable::FORMULA_DEPRECATE_DISABLE_REASONS else DeprecateDisable::CASK_DEPRECATE_DISABLE_REASONS end "#{reason} is not a valid deprecate! or disable! reason" unless reasons.include?(reason) end |
.eol_data(product, cycle) ⇒ Hash{String => T.untyped}?
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.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'utils/shared_audits.rb', line 61 def self.eol_data(product, cycle) @eol_data ||= T.let({}, T.nilable(T::Hash[String, T.untyped])) key = "#{product}/#{cycle}" return @eol_data[key] if @eol_data.key?(key) result = Utils::Curl.curl_output( "--location", "https://endoflife.date/api/v1/products/#{product}/releases/#{cycle}", ) return unless result.status.success? @eol_data[key] = begin JSON.parse(result.stdout) rescue JSON::ParserError nil end end |
.forgejo(user, repo, self_submission: false) ⇒ 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.
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'utils/shared_audits.rb', line 314 def self.forgejo(user, repo, self_submission: false) = forgejo_repo_data(user, repo) return if .nil? return "Forgejo fork (not canonical repository)" if ["fork"] notability_thresholds = notability_thresholds_for(FORGEJO_NOTABILITY_THRESHOLDS, self_submission) notability_prefix = if self_submission "Self-submitted Forgejo repository not notable enough" else "Forgejo repository not notable enough" end if (["forks_count"] < notability_thresholds.fetch(:forks)) && (["watchers_count"] < notability_thresholds.fetch(:watchers)) && (["stars_count"] < notability_thresholds.fetch(:stars)) return "#{notability_prefix} (<#{notability_thresholds.fetch(:forks)} forks, " \ "<#{notability_thresholds.fetch(:watchers)} watchers and " \ "<#{notability_thresholds.fetch(:stars)} stars)" end return if Date.parse(["created_at"]) <= (Date.today - 30) "Forgejo repository too new (<30 days old)" end |
.forgejo_release(user, repo, tag, formula: nil, cask: nil) ⇒ 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.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'utils/shared_audits.rb', line 206 def self.forgejo_release(user, repo, tag, formula: nil, cask: nil) release = forgejo_release_data(user, repo, tag) return unless release return unless release["prerelease"] exception, version = if formula [formula.tap&.audit_exception(:forgejo_prerelease_allowlist, formula.name), formula.version] elsif cask [cask.tap&.audit_exception(:forgejo_prerelease_allowlist, cask.token), cask.version] end return if [version, "all"].include?(exception) "#{tag} is a Forgejo pre-release." end |
.forgejo_repo_data(user, repo) ⇒ Hash{String => T.untyped}?
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.
143 144 145 146 147 148 149 150 |
# File 'utils/shared_audits.rb', line 143 def self.forgejo_repo_data(user, repo) @forgejo_repo_data ||= T.let({}, T.nilable(T::Hash[String, T.untyped])) @forgejo_repo_data["#{user}/#{repo}"] ||= begin result = Utils::Curl.curl_output("https://codeberg.org/api/v1/repos/#{user}/#{repo}") JSON.parse(result.stdout) if result.status.success? end end |
.forgejo_tag_from_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.
351 352 353 |
# File 'utils/shared_audits.rb', line 351 def self.forgejo_tag_from_url(url) url[%r{^https://codeberg\.org/[\w-]+/[\w.-]+/archive/(.+)\.(tar\.gz|zip)$}, 1] end |
.github(user, repo, self_submission: false) ⇒ 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.
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'utils/shared_audits.rb', line 222 def self.github(user, repo, self_submission: false) = github_repo_data(user, repo) return if .nil? return "GitHub fork (not canonical repository)" if ["fork"] notability_thresholds = notability_thresholds_for(GITHUB_NOTABILITY_THRESHOLDS, self_submission) notability_prefix = if self_submission "Self-submitted GitHub repository not notable enough" else "GitHub repository not notable enough" end if (["forks_count"] < notability_thresholds.fetch(:forks)) && (["subscribers_count"] < notability_thresholds.fetch(:watchers)) && (["stargazers_count"] < notability_thresholds.fetch(:stars)) return "#{notability_prefix} (<#{notability_thresholds.fetch(:forks)} forks, " \ "<#{notability_thresholds.fetch(:watchers)} watchers and " \ "<#{notability_thresholds.fetch(:stars)} stars)" end return if Date.parse(["created_at"]) <= (Date.today - 30) "GitHub repository too new (<30 days old)" end |
.github_release(user, repo, tag, formula: nil, cask: nil) ⇒ 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.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'utils/shared_audits.rb', line 112 def self.github_release(user, repo, tag, formula: nil, cask: nil) release = github_release_data(user, repo, tag) return unless release exception, name, version = if formula [formula.tap&.audit_exception(:github_prerelease_allowlist, formula.name), formula.name, formula.version] elsif cask [cask.tap&.audit_exception(:github_prerelease_allowlist, cask.token), cask.token, cask.version] end return "#{tag} is a GitHub pre-release." if release["prerelease"] && [version, "all", "any"].exclude?(exception) if !release["prerelease"] && exception && [version, "any"].exclude?(exception) return "#{tag} is not a GitHub pre-release but '#{name}' is in the GitHub prerelease allowlist." end "#{tag} is a GitHub draft." if release["draft"] end |
.github_repo_data(user, repo) ⇒ Hash{String => T.untyped}?
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.
80 81 82 83 84 85 86 87 88 89 |
# File 'utils/shared_audits.rb', line 80 def self.github_repo_data(user, repo) @github_repo_data ||= T.let({}, T.nilable(T::Hash[String, T.untyped])) @github_repo_data["#{user}/#{repo}"] ||= GitHub.repository(user, repo) @github_repo_data["#{user}/#{repo}"] rescue GitHub::API::HTTPNotFoundError nil rescue GitHub::API::AuthenticationFailedError => e raise unless e..match?(GitHub::API::GITHUB_IP_ALLOWLIST_ERROR) end |
.github_tag_from_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.
340 341 342 343 |
# File 'utils/shared_audits.rb', line 340 def self.github_tag_from_url(url) tag = url[%r{^https://github\.com/[\w-]+/[\w.-]+/archive/refs/tags/(.+)\.(tar\.gz|zip)$}, 1] tag || url[%r{^https://github\.com/[\w-]+/[\w.-]+/releases/download/([^/]+)/}, 1] end |
.gitlab(user, repo, self_submission: false) ⇒ 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.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'utils/shared_audits.rb', line 249 def self.gitlab(user, repo, self_submission: false) = gitlab_repo_data(user, repo) return if .nil? return "GitLab fork (not canonical repository)" if ["fork"] notability_thresholds = notability_thresholds_for(GITLAB_NOTABILITY_THRESHOLDS, self_submission) notability_prefix = if self_submission "Self-submitted GitLab repository not notable enough" else "GitLab repository not notable enough" end if (["forks_count"] < notability_thresholds.fetch(:forks)) && (["star_count"] < notability_thresholds.fetch(:stars)) return "#{notability_prefix} (<#{notability_thresholds.fetch(:forks)} forks and " \ "<#{notability_thresholds.fetch(:stars)} stars)" end return if Date.parse(["created_at"]) <= (Date.today - 30) "GitLab repository too new (<30 days old)" end |
.gitlab_release(user, repo, tag, formula: nil, cask: nil) ⇒ 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.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'utils/shared_audits.rb', line 171 def self.gitlab_release(user, repo, tag, formula: nil, cask: nil) release = gitlab_release_data(user, repo, tag) return unless release return if DateTime.parse(release["released_at"]) <= DateTime.now exception, version = if formula [formula.tap&.audit_exception(:gitlab_prerelease_allowlist, formula.name), formula.version] elsif cask [cask.tap&.audit_exception(:gitlab_prerelease_allowlist, cask.token), cask.version] end return if [version, "all"].include?(exception) "#{tag} is a GitLab pre-release." end |
.gitlab_repo_data(user, repo) ⇒ Hash{String => T.untyped}?
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.
132 133 134 135 136 137 138 139 140 |
# File 'utils/shared_audits.rb', line 132 def self.gitlab_repo_data(user, repo) @gitlab_repo_data ||= T.let({}, T.nilable(T::Hash[String, T.untyped])) @gitlab_repo_data["#{user}/#{repo}"] ||= begin result = Utils::Curl.curl_output("https://gitlab.com/api/v4/projects/#{user}%2F#{repo}") json = JSON.parse(result.stdout) if result.status.success? json = nil if json&.dig("message")&.include?("404 Project Not Found") json end end |
.gitlab_tag_from_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.
346 347 348 |
# File 'utils/shared_audits.rb', line 346 def self.gitlab_tag_from_url(url) url[%r{^https://gitlab\.com/(?:\w[\w.-]*/){2,}-/archive/([^/]+)/}, 1] end |
.no_autobump_new_package_message(message) ⇒ 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.
372 373 374 375 376 |
# File 'utils/shared_audits.rb', line 372 def self.() return if .is_a?(String) || != :requires_manual_review "`:requires_manual_review` is a temporary reason intended for existing packages, use a different reason instead." end |
.notability_thresholds_for(thresholds, self_submission) ⇒ Hash{Symbol => Integer}
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.
54 55 56 57 58 |
# File 'utils/shared_audits.rb', line 54 def self.notability_thresholds_for(thresholds, self_submission) return thresholds unless self_submission thresholds.transform_values { |value| value * SELF_SUBMISSION_THRESHOLD_MULTIPLIER } end |
.pull_request_author ⇒ 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.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'utils/shared_audits.rb', line 20 def self. return @pull_request_author if @pull_request_author_computed @pull_request_author_computed = true github_event_path = ENV.fetch("GITHUB_EVENT_PATH", nil) return @pull_request_author = nil if github_event_path.blank? @pull_request_author = JSON.parse(File.read(github_event_path)).dig("pull_request", "user", "login") rescue Errno::ENOENT, JSON::ParserError @pull_request_author = nil end |
.self_submission?(submitter, repo_owner) ⇒ Boolean
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.
33 34 35 36 37 38 |
# File 'utils/shared_audits.rb', line 33 def self.self_submission?(submitter, repo_owner) return false if submitter.blank? return false if repo_owner.empty? submitter.casecmp?(repo_owner) end |
.self_submission_for_repo_owner?(repo_owner) ⇒ Boolean
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.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'utils/shared_audits.rb', line 41 def self.self_submission_for_repo_owner?(repo_owner) return false if repo_owner.blank? submitter = return false if submitter.blank? key = repo_owner.downcase return @self_submission_cache.fetch(key) if @self_submission_cache.key?(key) @self_submission_cache[key] = self_submission?(submitter, repo_owner) end |