Created
May 2, 2021 23:10
-
-
Save vanessaaleung/6583bc5b178a8b04d468d54ccabe3be3 to your computer and use it in GitHub Desktop.
Create Github PR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_pull_request(owner: str, repo: str, token: str, branch_name: str, new_branch: str, base: str) -> str: | |
"""Create a PR for the new branch, return the PR number""" | |
url = "https://api.github.com/repos/{}/{}/pulls".format(owner, repo) | |
headers = { | |
"Authorization": "token {}".format(token), | |
"Content-Type": "application/json" | |
} | |
payload = { | |
"head": new_branch, | |
"base": base, | |
"title": branch_name, | |
"body": "Commented out files not found in locations.data-ops.json that\n1. may due to a naming convention change\n2. someone forgot to remove them from the table" | |
} | |
try: | |
response = requests.post(url, headers=headers, json=payload) | |
pr_url = json.loads(response.content)["html_url"] | |
logging.info("Pull request created: {}".format(pr_url)) | |
except Exception as e: | |
logging.error(e) | |
return pr_url.split("/")[-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment