Add warning and fail gracefully when ref is invalid for base

This commit is contained in:
Peter Evans 2019-11-16 09:24:46 +09:00
parent 6c73093f9b
commit d968e8b11b
2 changed files with 10 additions and 2 deletions

View File

@ -217,9 +217,13 @@ elif github_ref.startswith('refs/pull/'):
"Removing the merge commit by switching to the pull request head branch '%s'" % "Removing the merge commit by switching to the pull request head branch '%s'" %
base) base)
checkout_branch(repo.git, True, base) checkout_branch(repo.git, True, base)
else: elif github_ref.startswith('refs/heads/'):
base = github_ref[11:] base = github_ref[11:]
print("Currently checked out base assumed to be branch '%s'" % base) print("Currently checked out base assumed to be branch '%s'" % base)
else:
print(f"::warning::Currently checked out ref '{github_ref}' is not a valid base for a pull request. " +
"Unable to continue. Exiting.")
sys.exit()
# Skip if the current branch is a PR branch created by this action. # Skip if the current branch is a PR branch created by this action.
# This may occur when using a PAT instead of GITHUB_TOKEN because # This may occur when using a PAT instead of GITHUB_TOKEN because

View File

@ -217,9 +217,13 @@ elif github_ref.startswith('refs/pull/'):
"Removing the merge commit by switching to the pull request head branch '%s'" % "Removing the merge commit by switching to the pull request head branch '%s'" %
base) base)
checkout_branch(repo.git, True, base) checkout_branch(repo.git, True, base)
else: elif github_ref.startswith('refs/heads/'):
base = github_ref[11:] base = github_ref[11:]
print("Currently checked out base assumed to be branch '%s'" % base) print("Currently checked out base assumed to be branch '%s'" % base)
else:
print(f"::warning::Currently checked out ref '{github_ref}' is not a valid base for a pull request. " +
"Unable to continue. Exiting.")
sys.exit()
# Skip if the current branch is a PR branch created by this action. # Skip if the current branch is a PR branch created by this action.
# This may occur when using a PAT instead of GITHUB_TOKEN because # This may occur when using a PAT instead of GITHUB_TOKEN because