Class: GitHub::PatchInclusion Private
- Includes:
- Utils::Output::Mixin
- Defined in:
- utils/github/patch_inclusion.rb
Overview
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.
Checks whether an upstream commit patch is included in an explicitly identified release. Ancestry does not guarantee that the commit's changes have not subsequently been reverted.
Instance Method Summary collapse
- #initialize ⇒ void constructor private
-
#removal_reason(patch_url, source_url:, tag: nil, revision: nil) ⇒ String?
private
Returns PR-ready evidence, or nil when inclusion cannot be established.
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_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
#initialize ⇒ 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.
13 14 15 16 17 |
# File 'utils/github/patch_inclusion.rb', line 13 def initialize @commits = T.let({}, T::Hash[String, T.nilable(String)]) @comparisons = T.let({}, T::Hash[String, T::Boolean]) @unavailable = T.let(false, T::Boolean) end |
Instance Method Details
#removal_reason(patch_url, source_url:, tag: nil, revision: 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.
Returns PR-ready evidence, or nil when inclusion cannot be established.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'utils/github/patch_inclusion.rb', line 24 def removal_reason(patch_url, source_url:, tag: nil, revision: nil) return if @unavailable || Homebrew::EnvConfig.no_github_api? patch = patch_url.match(%r{\Ahttps://github\.com/(?<repository>[\w.-]+/[\w.-]+)/commit/(?<sha>[a-fA-F0-9]{40})\.(?:patch|diff)(?:\?full_index=1)?\z}) return unless patch source = source_url.match(%r{\Ahttps://github\.com/(?<repository>[\w.-]+/[\w.-]+?)(?:\.git)?(?:/(?<path>.*))?\z}) return unless source return unless source[:repository]&.casecmp?(patch[:repository].to_s) repository = patch[:repository].to_s patch_sha = patch[:sha].to_s.downcase path = source[:path].to_s if path.empty? return if revision.blank? && tag.blank? return if revision.present? && !revision.match?(/\A[a-fA-F0-9]{40}\z/) ref = revision.presence || "refs/tags/#{tag}" label = tag.presence || revision.to_s else release_tag = path[%r{\Aarchive/(?:refs/tags/)?(?<tag>.+)\.(?:tar\.gz|tar\.bz2|tar\.xz|tgz|zip)\z}, :tag] || path[%r{\Areleases/download/(?<tag>[^/]+)/[^/]+\z}, :tag] return if release_tag.blank? || release_tag.start_with?("refs/") label = URI::DEFAULT_PARSER.unescape(release_tag) ref = "refs/tags/#{label}" end commit_url = "#{API_URL}/repos/#{repository}/commits/#{URI.encode_www_form_component(ref)}" unless @commits.key?(commit_url) @commits[commit_url] = nil @commits[commit_url] = API.open_rest(commit_url).fetch("sha").downcase end release_sha = @commits[commit_url] return unless release_sha comparison = "#{repository}/compare/#{patch_sha}...#{release_sha}" unless @comparisons.key?(comparison) @comparisons[comparison] = false @comparisons[comparison] = %w[ahead identical].include?(API.open_rest("#{API_URL}/repos/#{comparison}")["status"]) end return unless @comparisons[comparison] "Removed patch [`#{patch_sha}`](https://github.com/#{repository}/commit/#{patch_sha}): " \ "the commit is included in `#{label.delete("`")}` (`#{release_sha}`). " \ "[Compare commits](https://github.com/#{comparison})." rescue API::Error, ErrorDuringExecution => e @unavailable = e.is_a?(API::RateLimitExceededError) || e.is_a?(API::AuthenticationFailedError) || e.is_a?(API::MissingAuthenticationError) opoo "Retaining patch because GitHub inclusion could not be checked:\n#{patch_url}\n#{e.}" nil end |