bump-formula-pr: add --fork-org flag
This commit is contained in:
parent
1a04490a2a
commit
63be66408e
@ -53,6 +53,8 @@ module Homebrew
|
|||||||
comma_array "--mirror",
|
comma_array "--mirror",
|
||||||
description: "Use the specified <URL> as a mirror URL. If <URL> is a comma-separated list "\
|
description: "Use the specified <URL> as a mirror URL. If <URL> is a comma-separated list "\
|
||||||
"of URLs, multiple mirrors will be added."
|
"of URLs, multiple mirrors will be added."
|
||||||
|
flag "--fork-org=",
|
||||||
|
description: "Use the specified GitHub organization for forking."
|
||||||
flag "--version=",
|
flag "--version=",
|
||||||
description: "Use the specified <version> to override the value parsed from the URL or tag. Note "\
|
description: "Use the specified <version> to override the value parsed from the URL or tag. Note "\
|
||||||
"that `--version=0` can be used to delete an existing version override from a "\
|
"that `--version=0` can be used to delete an existing version override from a "\
|
||||||
|
|||||||
@ -115,17 +115,18 @@ module GitHub
|
|||||||
puts "No pull requests found for #{query.inspect}" if open_prs.blank? && closed_prs.blank?
|
puts "No pull requests found for #{query.inspect}" if open_prs.blank? && closed_prs.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_fork(repo)
|
def create_fork(repo, org: nil)
|
||||||
url = "#{API_URL}/repos/#{repo}/forks"
|
url = "#{API_URL}/repos/#{repo}/forks"
|
||||||
data = {}
|
data = {}
|
||||||
|
data[:organization] = org if org
|
||||||
scopes = CREATE_ISSUE_FORK_OR_PR_SCOPES
|
scopes = CREATE_ISSUE_FORK_OR_PR_SCOPES
|
||||||
API.open_rest(url, data: data, scopes: scopes)
|
API.open_rest(url, data: data, scopes: scopes)
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_fork_exists(repo)
|
def check_fork_exists(repo, org: nil)
|
||||||
_, reponame = repo.split("/")
|
_, reponame = repo.split("/")
|
||||||
|
|
||||||
username = API.open_rest(url_to("user")) { |json| json["login"] }
|
username = org || API.open_rest(url_to("user")) { |json| json["login"] }
|
||||||
json = API.open_rest(url_to("repos", username, reponame))
|
json = API.open_rest(url_to("repos", username, reponame))
|
||||||
|
|
||||||
return false if json["message"] == "Not Found"
|
return false if json["message"] == "Not Found"
|
||||||
@ -450,10 +451,10 @@ module GitHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def forked_repo_info!(tap_remote_repo)
|
def forked_repo_info!(tap_remote_repo, org: nil)
|
||||||
response = create_fork(tap_remote_repo)
|
response = create_fork(tap_remote_repo, org: org)
|
||||||
# GitHub API responds immediately but fork takes a few seconds to be ready.
|
# GitHub API responds immediately but fork takes a few seconds to be ready.
|
||||||
sleep 1 until check_fork_exists(tap_remote_repo)
|
sleep 1 until check_fork_exists(tap_remote_repo, org: org)
|
||||||
remote_url = if system("git", "config", "--local", "--get-regexp", "remote\..*\.url", "git@github.com:.*")
|
remote_url = if system("git", "config", "--local", "--get-regexp", "remote\..*\.url", "git@github.com:.*")
|
||||||
response.fetch("ssh_url")
|
response.fetch("ssh_url")
|
||||||
else
|
else
|
||||||
@ -487,7 +488,11 @@ module GitHub
|
|||||||
changed_files += additional_files if additional_files.present?
|
changed_files += additional_files if additional_files.present?
|
||||||
|
|
||||||
if args.dry_run? || (args.write? && !args.commit?)
|
if args.dry_run? || (args.write? && !args.commit?)
|
||||||
ohai "try to fork repository with GitHub API" unless args.no_fork?
|
unless args.no_fork?
|
||||||
|
fork_message = "try to fork repository with GitHub API" \
|
||||||
|
"#{" into `#{args.fork_org}` organization" if args.fork_org}"
|
||||||
|
ohai fork_message
|
||||||
|
end
|
||||||
ohai "git fetch --unshallow origin" if shallow
|
ohai "git fetch --unshallow origin" if shallow
|
||||||
ohai "git add #{changed_files.join(" ")}"
|
ohai "git add #{changed_files.join(" ")}"
|
||||||
ohai "git checkout --no-track -b #{branch} #{remote}/#{remote_branch}"
|
ohai "git checkout --no-track -b #{branch} #{remote}/#{remote_branch}"
|
||||||
@ -504,7 +509,7 @@ module GitHub
|
|||||||
username = tap.user
|
username = tap.user
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
remote_url, username = forked_repo_info!(tap_remote_repo)
|
remote_url, username = forked_repo_info!(tap_remote_repo, org: args.fork_org)
|
||||||
rescue *API::ERRORS => e
|
rescue *API::ERRORS => e
|
||||||
sourcefile_path.atomic_write(old_contents)
|
sourcefile_path.atomic_write(old_contents)
|
||||||
odie "Unable to fork: #{e.message}!"
|
odie "Unable to fork: #{e.message}!"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user