Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Actions: get username if we don't have it #6776

Merged
merged 3 commits into from Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions Library/Homebrew/dev-cmd/bump-formula-pr.rb
Expand Up @@ -381,14 +381,13 @@ def bump_formula_pr
end

def forked_repo_info(formula, tap_full_name, backup_file)
begin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't begin needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not any more; shiny new Ruby syntax.

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
Expand Down
9 changes: 8 additions & 1 deletion Library/Homebrew/utils/github.rb
Expand Up @@ -341,9 +341,16 @@ def create_fork(repo)
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
Expand Down