Merge pull request #6723 from maxim-belkin/gh-actions/no-fork-prs
bump-formula-pr: enable same-repo (no-fork) Pull Requests
This commit is contained in:
commit
28635a7fe4
@ -38,6 +38,8 @@ module Homebrew
|
|||||||
description: "Run `brew audit --strict` before opening the PR."
|
description: "Run `brew audit --strict` before opening the PR."
|
||||||
switch "--no-browse",
|
switch "--no-browse",
|
||||||
description: "Print the pull request URL instead of opening in a browser."
|
description: "Print the pull request URL instead of opening in a browser."
|
||||||
|
switch "--no-fork",
|
||||||
|
description: "Don't try to fork the repository."
|
||||||
flag "--mirror=",
|
flag "--mirror=",
|
||||||
description: "Use the specified <URL> as a mirror URL."
|
description: "Use the specified <URL> as a mirror URL."
|
||||||
flag "--version=",
|
flag "--version=",
|
||||||
@ -324,7 +326,7 @@ module Homebrew
|
|||||||
changed_files += alias_rename if alias_rename.present?
|
changed_files += alias_rename if alias_rename.present?
|
||||||
|
|
||||||
if args.dry_run?
|
if args.dry_run?
|
||||||
ohai "try to fork repository with GitHub API"
|
ohai "try to fork repository with GitHub API" unless args.no_fork?
|
||||||
ohai "git fetch --unshallow origin" if shallow
|
ohai "git fetch --unshallow origin" if shallow
|
||||||
ohai "git add #{alias_rename.first} #{alias_rename.last}" if alias_rename.present?
|
ohai "git add #{alias_rename.first} #{alias_rename.last}" if alias_rename.present?
|
||||||
ohai "git checkout --no-track -b #{branch} #{origin_branch}"
|
ohai "git checkout --no-track -b #{branch} #{origin_branch}"
|
||||||
@ -335,27 +337,11 @@ module Homebrew
|
|||||||
ohai "create pull request with GitHub API"
|
ohai "create pull request with GitHub API"
|
||||||
else
|
else
|
||||||
|
|
||||||
begin
|
if args.no_fork?
|
||||||
response = GitHub.create_fork(tap_full_name)
|
|
||||||
# GitHub API responds immediately but fork takes a few seconds to be ready.
|
|
||||||
sleep 3
|
|
||||||
|
|
||||||
if system("git", "config", "--get-regexp", "remote\..*\.url", "git@github.com:.*")
|
|
||||||
remote_url = response.fetch("ssh_url")
|
|
||||||
else
|
|
||||||
remote_url = response.fetch("clone_url")
|
|
||||||
end
|
|
||||||
username = response.fetch("owner").fetch("login")
|
|
||||||
rescue GitHub::AuthenticationFailedError => e
|
|
||||||
raise unless e.github_message.match?(/forking is disabled/)
|
|
||||||
|
|
||||||
# If the repository is private, forking might be disabled.
|
|
||||||
# Create branches in the repository itself instead.
|
|
||||||
remote_url = Utils.popen_read("git remote get-url --push origin").chomp
|
remote_url = Utils.popen_read("git remote get-url --push origin").chomp
|
||||||
username = formula.tap.user
|
username = formula.tap.user
|
||||||
rescue *GitHub.api_errors => e
|
else
|
||||||
formula.path.atomic_write(backup_file) unless args.dry_run?
|
remote_url, username = forked_repo_info(tap_full_name)
|
||||||
odie "Unable to fork: #{e.message}!"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
safe_system "git", "fetch", "--unshallow", "origin" if shallow
|
safe_system "git", "fetch", "--unshallow", "origin" if shallow
|
||||||
@ -394,6 +380,23 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def forked_repo_info(tap_full_name)
|
||||||
|
response = GitHub.create_fork(tap_full_name)
|
||||||
|
rescue GitHub::AuthenticationFailedError, *GitHub.api_errors => e
|
||||||
|
formula.path.atomic_write(backup_file)
|
||||||
|
odie "Unable to fork: #{e.message}!"
|
||||||
|
else
|
||||||
|
# GitHub API responds immediately but fork takes a few seconds to be ready.
|
||||||
|
sleep 1 until GitHub.check_fork_exists(tap_full_name)
|
||||||
|
remote_url = if system("git", "config", "--local", "--get-regexp", "remote\..*\.url", "git@github.com:.*")
|
||||||
|
response.fetch("ssh_url")
|
||||||
|
else
|
||||||
|
response.fetch("clone_url")
|
||||||
|
end
|
||||||
|
username = response.fetch("owner").fetch("login")
|
||||||
|
[remote_url, username]
|
||||||
|
end
|
||||||
|
|
||||||
def inreplace_pairs(path, replacement_pairs)
|
def inreplace_pairs(path, replacement_pairs)
|
||||||
if args.dry_run?
|
if args.dry_run?
|
||||||
contents = path.open("r") { |f| Formulary.ensure_utf8_encoding(f).read }
|
contents = path.open("r") { |f| Formulary.ensure_utf8_encoding(f).read }
|
||||||
|
|||||||
@ -340,6 +340,15 @@ module GitHub
|
|||||||
open_api(url, data: data, scopes: scopes)
|
open_api(url, data: data, scopes: scopes)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_fork_exists(repo)
|
||||||
|
_, username = api_credentials
|
||||||
|
_, reponame = repo.split("/")
|
||||||
|
json = open_api(url_to("repos", username, reponame))
|
||||||
|
return false if json["message"] == "Not Found"
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def create_pull_request(repo, title, head, base, body)
|
def create_pull_request(repo, title, head, base, body)
|
||||||
url = "#{API_URL}/repos/#{repo}/pulls"
|
url = "#{API_URL}/repos/#{repo}/pulls"
|
||||||
data = { title: title, head: head, base: base, body: body }
|
data = { title: title, head: head, base: base, body: body }
|
||||||
|
|||||||
@ -762,6 +762,8 @@ uses.
|
|||||||
Run `brew audit --strict` before opening the PR.
|
Run `brew audit --strict` before opening the PR.
|
||||||
* `--no-browse`:
|
* `--no-browse`:
|
||||||
Print the pull request URL instead of opening in a browser.
|
Print the pull request URL instead of opening in a browser.
|
||||||
|
* `--no-fork`:
|
||||||
|
Don't try to fork the repository.
|
||||||
* `--mirror`:
|
* `--mirror`:
|
||||||
Use the specified *`URL`* as a mirror URL.
|
Use the specified *`URL`* as a mirror URL.
|
||||||
* `--version`:
|
* `--version`:
|
||||||
|
|||||||
@ -966,6 +966,10 @@ Run \fBbrew audit \-\-strict\fR before opening the PR\.
|
|||||||
Print the pull request URL instead of opening in a browser\.
|
Print the pull request URL instead of opening in a browser\.
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
|
\fB\-\-no\-fork\fR
|
||||||
|
Don\'t try to fork the repository\.
|
||||||
|
.
|
||||||
|
.TP
|
||||||
\fB\-\-mirror\fR
|
\fB\-\-mirror\fR
|
||||||
Use the specified \fIURL\fR as a mirror URL\.
|
Use the specified \fIURL\fR as a mirror URL\.
|
||||||
.
|
.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user