Skip to content
Snippets Groups Projects
Unverified Commit dd71f388 authored by Dawid Dziurla's avatar Dawid Dziurla Committed by GitHub
Browse files

Merge pull request #8368 from SeekingMeaning/github/forked_repo_info

utils/github: add `forked_repo_info!`
parents 778bd543 ffcf0686
No related branches found
No related tags found
No related merge requests found
......@@ -362,7 +362,12 @@ module Homebrew
remote_url = Utils.popen_read("git remote get-url --push origin").chomp
username = formula.tap.user
else
remote_url, username = forked_repo_info(formula, tap_full_name, old_contents)
begin
remote_url, username = GitHub.forked_repo_info!(tap_full_name)
rescue *GitHub.api_errors => e
formula.path.atomic_write(old_contents)
odie "Unable to fork: #{e.message}!"
end
end
safe_system "git", "fetch", "--unshallow", "origin" if shallow
......@@ -445,27 +450,6 @@ module Homebrew
[resource.fetch, forced_version]
end
def forked_repo_info(formula, tap_full_name, old_contents)
response = GitHub.create_fork(tap_full_name)
rescue GitHub::AuthenticationFailedError, *GitHub.api_errors => e
formula.path.atomic_write(old_contents)
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
url = response.fetch("clone_url")
if (api_token = Homebrew::EnvConfig.github_api_token)
url.gsub!(%r{^https://github\.com/}, "https://#{api_token}@github.com/")
end
url
end
username = response.fetch("owner").fetch("login")
[remote_url, username]
end
def formula_version(formula, spec, contents = nil)
name = formula.name
path = formula.path
......
......@@ -603,4 +603,21 @@ module GitHub
EOS
end
end
def forked_repo_info!(tap_full_name)
response = GitHub.create_fork(tap_full_name)
# 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
url = response.fetch("clone_url")
if (api_token = Homebrew::EnvConfig.github_api_token)
url.gsub!(%r{^https://github\.com/}, "https://#{api_token}@github.com/")
end
url
end
username = response.fetch("owner").fetch("login")
[remote_url, username]
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment