Module: Homebrew::Bump
- Extended by:
- SystemCommand::Mixin, Utils::Output::Mixin
- Defined in:
- bump.rb
This module is part of an internal API. This module may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this module if possible, as it may be removed or changed without warning.
Defined Under Namespace
Class Method Summary collapse
- .create_pr(info, dry_run: false, no_fork: false, fork_org: nil, commit: false) ⇒ String? private
- .pr_message(command, user_message:) ⇒ String private
Methods included from SystemCommand::Mixin
system_command, system_command!
Methods included from Utils::Output::Mixin
odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, pretty_deprecated, pretty_disabled, pretty_duration, pretty_installed, pretty_outdated, pretty_uninstalled
Class Method Details
.create_pr(info, dry_run: false, no_fork: false, fork_org: nil, commit: 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.
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'bump.rb', line 48 def self.create_pr(info, dry_run: false, no_fork: false, fork_org: nil, commit: false) tap = info.package_tap branch = info.branch_name = info. pr_title = info.pr_title commits = info.commits tap_remote_repo = tap.remote_repository raise ArgumentError, "The tap #{tap.name} does not have a remote repository!" unless tap_remote_repo remote_branch = tap.git_repository.origin_branch_name raise "The tap #{tap.name} does not have a default branch!" if remote_branch.blank? remote_url = T.let(nil, T.nilable(String)) username = T.let(nil, T.nilable(String)) tap.path.cd do if no_fork remote_url = Utils.popen_read("git", "remote", "get-url", "--push", "origin").chomp username = tap.user add_auth_token_to_url!(remote_url) else begin remote_url, username = forked_repo_info!(tap_remote_repo, org: fork_org) rescue *GitHub::API::ERRORS => e commits.each do |commit| commit.sourcefile_path.atomic_write(commit.old_contents) end odie "Unable to fork: #{e.}!" end end next if dry_run git_dir = Utils.popen_read("git", "rev-parse", "--git-dir").chomp shallow = !git_dir.empty? && File.exist?("#{git_dir}/shallow") safe_system "git", "fetch", "--unshallow", "origin" if !commit && shallow safe_system "git", "checkout", "--no-track", "-b", branch, "origin/#{remote_branch}" unless commit Utils::Git.set_name_email! end commits.each do |commit| sourcefile_path = commit.sourcefile_path = commit. additional_files = commit.additional_files sourcefile_path.parent.cd do git_dir = Utils.popen_read("git", "rev-parse", "--git-dir").chomp shallow = !git_dir.empty? && File.exist?("#{git_dir}/shallow") changed_files = [sourcefile_path] changed_files += additional_files if additional_files.present? if dry_run ohai "git checkout --no-track -b #{branch} origin/#{remote_branch}" ohai "git fetch --unshallow origin" if shallow ohai "git add #{changed_files.join(" ")}" ohai "git commit --no-edit --verbose --message='#{}' " \ "-- #{changed_files.join(" ")}" ohai "git push --set-upstream #{remote_url} #{branch}:#{branch}" ohai "git checkout --quiet -" ohai "create pull request with GitHub API (base branch: #{remote_branch})" else safe_system "git", "add", *changed_files Utils::Git.set_name_email! safe_system "git", "commit", "--no-edit", "--verbose", "--message=#{}", "--", *changed_files end end end return if commit || dry_run return unless remote_url tap.path.cd do system_command!("git", args: ["push", "--set-upstream", remote_url, "#{branch}:#{branch}"], print_stdout: true) safe_system "git", "checkout", "--quiet", "-" begin return GitHub.create_pull_request(tap_remote_repo, pr_title, "#{username}:#{branch}", remote_branch, )["html_url"] rescue *GitHub::API::ERRORS => e commits.each do |commit| commit.sourcefile_path.atomic_write(commit.old_contents) end odie "Unable to open pull request for #{tap_remote_repo}: #{e.}!" end end end |
.pr_message(command, user_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.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'bump.rb', line 33 def self.(command, user_message:) = "" if .present? += <<~EOS #{} --- EOS end += "Created with `brew #{command}`." end |