Skip to content

Instantly share code, notes, and snippets.

@vanessaaleung
Created May 2, 2021 23:10
Show Gist options
  • Save vanessaaleung/6583bc5b178a8b04d468d54ccabe3be3 to your computer and use it in GitHub Desktop.
Save vanessaaleung/6583bc5b178a8b04d468d54ccabe3be3 to your computer and use it in GitHub Desktop.
Create Github PR
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