import requests


def get_sha_from_commit(repo, commit):
    """
    given a GIT repo and a commit ID, return the SHA for that commit
    """
    if not commit.startswith("refs/"):
        commit = "refs/heads/" + commit
    response = requests.get(
        "https://api.github.com/repos/{}/git/{}".format(repo, commit)
    )
    if response.status_code == 200:
        return response.json()["object"]["sha"]
    elif response.status_code == 404:
        raise Exception("ERROR : Commit {} not found in repo {}".format(commit, repo))
    else:
        raise Exception(
            "unexpected result looking for commit {} in repo {} status = {} response = {}".format(
                commit, repo, response.status_code, response.json()
            )
        )