From 484de7fc89afbab850ffaba1c8cc44a81ed6bfa8 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sat, 28 Dec 2019 18:34:32 +0900 Subject: [PATCH] Delete the branch if there is no diff with the base --- dist/src/create_pull_request.py | 7 +++++++ src/create_pull_request.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/dist/src/create_pull_request.py b/dist/src/create_pull_request.py index b0723e9..59fd890 100755 --- a/dist/src/create_pull_request.py +++ b/dist/src/create_pull_request.py @@ -170,6 +170,13 @@ if result["action"] in ["created", "updated"]: # Set the base. It would have been 'None' if not specified as an input base = result["base"] + # If there is no longer a diff with the base delete the branch and exit + if not result["diff"]: + print(f"Branch '{branch}' no longer differs from base branch '{base}'") + print(f"Closing pull request and deleting branch '{branch}'") + repo.git.push("--delete", "--force", repo_url, f"refs/heads/{branch}") + sys.exit() + # TODO Figure out what to do when there is no diff with the base anymore # if not result["diff"]: diff --git a/src/create_pull_request.py b/src/create_pull_request.py index b0723e9..59fd890 100755 --- a/src/create_pull_request.py +++ b/src/create_pull_request.py @@ -170,6 +170,13 @@ if result["action"] in ["created", "updated"]: # Set the base. It would have been 'None' if not specified as an input base = result["base"] + # If there is no longer a diff with the base delete the branch and exit + if not result["diff"]: + print(f"Branch '{branch}' no longer differs from base branch '{base}'") + print(f"Closing pull request and deleting branch '{branch}'") + repo.git.push("--delete", "--force", repo_url, f"refs/heads/{branch}") + sys.exit() + # TODO Figure out what to do when there is no diff with the base anymore # if not result["diff"]: