from typing import Optional
import yaml


def get_repo_version(filename: str, repo: str) -> Optional[str]:
    """Return the version (i.e., rev) of a repo

    Args:
        filename (str): .pre-commit-config.yaml
        repo (str): repo URL

    Returns:
        Optional[str]: the version of the repo
    """

    with open(filename, "r") as stream:
        pre_commit_data = yaml.safe_load(stream)

    pre_config_repo = next(
        (item for item in pre_commit_data["repos"] if item["repo"] == repo), None
    )

    if pre_config_repo:
        return pre_config_repo["rev"]

    return None