Class: GitHubReleases Private
- Includes:
- Context, Utils::Output::Mixin
- Defined in:
- github_releases.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.
GitHub Releases client.
Constant Summary collapse
- URL_REGEX =
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.
%r{https://github\.com/([\w-]+)/([\w-]+)?/releases/download/(.+)}
Instance Method Summary collapse
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Methods included from Context
current, current=, #debug?, #deferred_environment_expansion?, #quiet?, #verbose?, #with_context
Instance Method Details
#upload_bottles(bottles_hash) ⇒ 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.
16 17 18 19 20 21 22 23 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 |
# File 'github_releases.rb', line 16 def upload_bottles(bottles_hash) bottles_by_release = bottles_hash.values.group_by do |bottle_hash| _, user, repo, tag = *bottle_hash["bottle"]["root_url"].match(URL_REGEX) [user.downcase, repo.downcase, tag] end bottle_count = bottles_by_release.values.sum(&:count) uploaded_count = 0 bottles_by_release.each do |(user, repo, tag), bottles| # Ensure a release is created or reused. Bottles are uploaded to a draft # release which is published afterwards, so that uploads also work on # repositories with immutable releases enabled, where assets cannot be # added to a release after it has been published. release, draft_release = find_or_create_release(user, repo, tag) bottles.each do |bottle_hash| # Upload bottles as release assets. bottle_hash["bottle"]["tags"].each_value do |tag_hash| remote_file = tag_hash["filename"] local_file = tag_hash["local_filename"] if draft_release && (asset = release.fetch("assets", []).find { |a| a["name"] == remote_file }) if !File.file?(local_file) || !File.readable?(local_file) raise GitHub::API::Error, "Cannot replace #{remote_file}: #{local_file} is not a readable file." end # open_rest only sets the HTTP method when a payload is supplied. GitHub::API.open_rest( "#{GitHub::API_URL}/repos/#{user}/#{repo}/releases/assets/#{asset.fetch("id")}", data: {}, request_method: :DELETE, scopes: GitHub::CREATE_ISSUE_FORK_OR_PR_SCOPES, ) end odebug "Uploading #{remote_file}" GitHub.upload_release_asset user, repo, release["id"], local_file:, remote_file: end uploaded_count += 1 next if bottle_count < 3 ohai "Upload progress: #{uploaded_count} formula(e) uploaded, #{bottle_count - uploaded_count} remaining" end # Publish the release (and thereby create its tag) now that all bottle # assets have been uploaded. if draft_release GitHub.create_or_update_release(user, repo, tag, id: release["id"], draft: false) end end end |