Add environment variable to pass if PR exists (#53)

* adding PASS_IF_EXISTS

Signed-off-by: vsoch <vsochat@stanford.edu>

* PASS_IF_EXISTS option, to not error out when a matching PR already is open (#52)

* Pass filters to request for PRs, and move PASS_IF_EXISTS exit in different spot
* Changed a printout to say the params used for a req
* break when looping through branches and find the matching one
Co-authored-by: Vanessasaurus <vsochat@gmail.com>

Co-authored-by: tscizzlebg <54290732+tscizzlebg@users.noreply.github.com>
This commit is contained in:
Vanessasaurus
2020-10-20 12:15:41 -06:00
committed by GitHub
parent 0d662a3b50
commit c39853dfde
2 changed files with 15 additions and 6 deletions

View File

@@ -73,13 +73,14 @@ def create_pull_request(
):
# Check if the branch already has a pull request open
params = {"base": target, "head": source, "state": "open"}
data = {"base": target, "head": source, "body": body}
print("Data for checking if pull request exists: %s" % data)
response = requests.get(PULLS_URL, json=data)
print("Params for checking if pull request exists: %s" % params)
response = requests.get(PULLS_URL, params=params)
# Case 1: 404 might warrant needing a token
if response.status_code == 404:
response = requests.get(PULLS_URL, json=data, headers=HEADERS)
response = requests.get(PULLS_URL, params=params, headers=HEADERS)
if response.status_code != 200:
abort_if_fail(
"Unable to retrieve information about pull requests: %s: %s"
@@ -96,9 +97,15 @@ def create_pull_request(
print("Pull request from %s to %s is already open!" % (source, target))
is_open = True
# Does the user want to pass if the pull request exists?
if os.environ.get("PASS_IF_EXISTS"):
print("PASS_IF_EXISTS is set, exiting with success status.")
sys.exit(0)
break
# Option 2: Open a new pull request
if not is_open:
print("%s does not have a pull request open, continuing!" % source)
print("No pull request from %s to %s is open, continuing!" % (source, target))
# Post the pull request
data = {