From d968e8b11b51878c067ce8b6d0998ed09d587088 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sat, 16 Nov 2019 09:24:46 +0900 Subject: [PATCH] Add warning and fail gracefully when ref is invalid for base --- dist/src/create-pull-request.py | 6 +++++- src/create-pull-request.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dist/src/create-pull-request.py b/dist/src/create-pull-request.py index f8c2ea5..7957ca5 100755 --- a/dist/src/create-pull-request.py +++ b/dist/src/create-pull-request.py @@ -217,9 +217,13 @@ elif github_ref.startswith('refs/pull/'): "Removing the merge commit by switching to the pull request head branch '%s'" % base) checkout_branch(repo.git, True, base) -else: +elif github_ref.startswith('refs/heads/'): base = github_ref[11:] 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. # This may occur when using a PAT instead of GITHUB_TOKEN because diff --git a/src/create-pull-request.py b/src/create-pull-request.py index f8c2ea5..7957ca5 100755 --- a/src/create-pull-request.py +++ b/src/create-pull-request.py @@ -217,9 +217,13 @@ elif github_ref.startswith('refs/pull/'): "Removing the merge commit by switching to the pull request head branch '%s'" % base) checkout_branch(repo.git, True, base) -else: +elif github_ref.startswith('refs/heads/'): base = github_ref[11:] 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. # This may occur when using a PAT instead of GITHUB_TOKEN because