Created
May 2, 2021 23:08
-
-
Save vanessaaleung/d3e42c1fa6b0d72b95c3720aa6ae221a to your computer and use it in GitHub Desktop.
GitHub Get File SHA
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 get_file_sha(owner: str, repo: str, token: str, path: str) -> str: | |
"""Return the file's SHA for updating the file""" | |
url = "https://api.github.com/repos/{}/{}/contents/{}".format(owner, repo, path) | |
headers = { | |
"Authorization": "token {}".format(token), | |
"Content-Type": "application/json" | |
} | |
try: | |
response = requests.get(url, headers=headers) | |
sha = json.loads(response.content)["sha"] | |
except Exception as e: | |
logging.error(e) | |
sys.exit(1) | |
return sha |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment