Skip to content

Instantly share code, notes, and snippets.

@vanessaaleung
Created May 2, 2021 23:08
Show Gist options
  • Save vanessaaleung/d3e42c1fa6b0d72b95c3720aa6ae221a to your computer and use it in GitHub Desktop.
Save vanessaaleung/d3e42c1fa6b0d72b95c3720aa6ae221a to your computer and use it in GitHub Desktop.
GitHub Get File SHA
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