import requests


def get_sha_url_and_ref_from_prid(repo, prid):
    """
    given a GIT repo and a pull request ID, return the SHA, clone_url, and ref for that pull request
    """
    response = requests.get(
        "https://api.github.com/repos/{}/pulls/{}".format(repo, prid)
    )
    if response.status_code == 200:
        sha = response.json()["head"]["sha"]
        url = response.json()["head"]["repo"]["clone_url"]
        ref = response.json()["head"]["ref"]
        return (sha, url, ref)
    elif response.status_code == 405:
        raise Exception("ERROR : prid {} not found in repo {}".format(prid, repo))
    else:
        raise Exception(
            "unexpected result looking for prid {} in repo {} status = {} response = {}".format(
                prid, repo, response.status_code, response.json()
            )
        )