Last active
May 2, 2021 23:09
-
-
Save vanessaaleung/3a5504624b7f86096d2cff96bfb0421e 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 update_file_contents(owner: str, repo: str, token: str, new_branch: str, sha: str, path: str) -> None: | |
"""Update the file content and add a commit""" | |
url = "https://api.github.com/repos/{}/{}/contents/{}".format(owner, repo, path) | |
headers = { | |
"Authorization": "token {}".format(token), | |
"Content-Type": "application/json" | |
} | |
with open(os.path.join(os.path.dirname(__file__), "../..", path),'rb') as content: | |
b64_content = base64.b64encode(content.read()) | |
payload = { | |
"message": "comment out files not in locations.data-ops.json", | |
"branch": new_branch, | |
"sha": sha, | |
"content": b64_content.decode("utf-8") | |
} | |
try: | |
requests.put(url, headers=headers, json=payload) | |
except Exception as e: | |
logging.error(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment