Skip to content

Commit

Permalink
signer: When pushing to a fork, use unique branch name
Browse files Browse the repository at this point in the history
This should avoid the issue where fork branch already exists
and is not fast-forwardable: Now each tuf-on-ci-sign execution
will create a new branch instead of reusing a potentially
existing one.

Use "--quiet" during push: This prevents the mass of output from git
with now confusing message of "Create pull request by visiting <URL>".
  • Loading branch information
jku committed Mar 4, 2024
1 parent acf2ac6 commit ef9c7af
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions signer/tuf_on_ci_sign/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,28 +160,34 @@ def application_update_reminder() -> None:

def push_changes(user: User, event_name: str, title: str) -> None:
"""Push the event branch to users push remote"""
branch = f"{user.push_remote}/{event_name}"
msg = f"Press enter to push changes to {branch}"
click.prompt(bold(msg), default=True, show_default=False)
git_echo(
[
"push",
user.push_remote,
f"HEAD:refs/heads/{event_name}",
]
)
if user.push_remote != user.push_remote:
# Create PR from fork (push remote) to upstream (pull remote)
upstream = get_repo_name({user.pull_remote})
fork = get_repo_name({user.push_remote}).replace("/", ":")

if user.pull_remote == user.push_remote:
# push directly to signing event
msg = "Press enter to push changes directly to signing event"
click.prompt(bold(msg), default=True, show_default=False)

git_echo(["push", "--quiet", user.push_remote, f"HEAD:refs/heads/{event_name}"])
else:
# push to fork: use unique branch name to avoid conflicts
msg = "Press enter to push changes to your fork"
click.prompt(bold(msg), default=True, show_default=False)

sha = git_expect(["rev-parse", "HEAD"])
fork_branch = f"{event_name}-{sha[:7]}"
ref_spec = f"HEAD:refs/heads/{fork_branch}"
git_echo(["push", "--quiet", user.push_remote, ref_spec])

# Create PR from fork to upstream
upstream = get_repo_name(user.pull_remote)
fork = get_repo_name(user.push_remote).replace("/", ":")
query = parse.urlencode(
{
"quick_pull": 1,
"title": title,
"template": "signing_event.md",
}
)
pr_url = f"https://github.com/{upstream}/compare/{event_name}...{fork}:{event_name}?{query}"
pr_url = f"https://github.com/{upstream}/compare/{event_name}...{fork}:{fork_branch}?{query}"
if webbrowser.open(pr_url):
click.echo(bold("Please open the pull request in your browser"))
else:
Expand Down

0 comments on commit ef9c7af

Please sign in to comment.