Merge pull request #6776 from maxim-belkin/dawid66++

GitHub Actions: get username if we don't have it
This commit is contained in:
Mike McQuaid 2019-11-27 12:21:07 +00:00 committed by GitHub
commit 2e382cdbdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 9 deletions

View File

@ -381,14 +381,13 @@ module Homebrew
end
def forked_repo_info(formula, tap_full_name, backup_file)
begin
response = GitHub.create_fork(tap_full_name)
# GitHub API responds immediately but fork takes a few seconds to be ready.
sleep 3
rescue GitHub::AuthenticationFailedError, *GitHub.api_errors => e
formula.path.atomic_write(backup_file)
odie "Unable to fork: #{e.message}!"
end
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

View File

@ -341,9 +341,16 @@ module GitHub
end
def check_fork_exists(repo)
_, username = api_credentials
_, reponame = repo.split("/")
case api_credentials_type
when :keychain
_, username = api_credentials
when :environment
username = open_api(url_to("user")) { |json| json["login"] }
end
json = open_api(url_to("repos", username, reponame))
return false if json["message"] == "Not Found"
true