import re


def get_pull_no(ref):
    """
    Get pull request from a git given ref
    >>> get_pull_no('refs/pull/12345/head')
    12345
    >>> get_pull_no('refs/pull/6789/merge')
    6789
    """
    match = re.search('refs/pull/([0-9]+)/', ref)
    if match:
        return int(match[1])
    raise ValueError("Unable to get pull request number from ref {}"
                     .format(ref))