Skip to content

repository

Defines a data structure for representing a repository.

Classes:

Name Description
InvalidGitHubRepoURL

Raised when a GitHub repository URL is invalid.

InvalidRepoFullName

Raised when a repository full name is invalid.

RepoReference

A reference to a repository on a code hosting platform.

InvalidGitHubRepoURL 🔗

Bases: ValueError

Raised when a GitHub repository URL is invalid.

Source code in src/brag/repository.py
class InvalidGitHubRepoURL(ValueError):
    """Raised when a GitHub repository URL is invalid."""

    def __init__(self, github_repo_url: str):
        self.github_repo_url = github_repo_url
        self.expected_format = REPO_URL_PATTERN
        self.message = f"Invalid GitHub repository URL: {github_repo_url!r}. Must match the pattern: {self.expected_format!r}"
        super().__init__(self.message)

InvalidRepoFullName 🔗

Bases: ValueError

Raised when a repository full name is invalid.

Source code in src/brag/repository.py
class InvalidRepoFullName(ValueError):
    """Raised when a repository full name is invalid."""

    def __init__(self, repo_full_name: str):
        self.repo_full_name = repo_full_name
        self.expected_format = REPO_FULL_NAME_PATTERN
        self.message = f"Invalid repository full name: {repo_full_name!r}. Must match the pattern: {self.expected_format!r}"
        super().__init__(self.message)

RepoReference 🔗

Bases: BaseModel

A reference to a repository on a code hosting platform.

Attributes:

Name Type Description
owner str

The owner of the repository (e.g., a user or organization).

name str

The name of the repository.

Methods:

Name Description
from_github_repo_url

Create a RepoReference object from a GitHub repository URL.

from_repo_full_name

Create a RepoReference object from a RepoFullName object.

Source code in src/brag/repository.py
class RepoReference(BaseModel):
    """A reference to a repository on a code hosting platform.

    Attributes:
        owner: The owner of the repository (e.g., a user or organization).
        name: The name of the repository.
    """

    owner: str
    name: str

    @property
    def full_name(self) -> str:
        """Returns the full name of the repository in the format 'owner/name'."""
        return f"{self.owner}/{self.name}"

    @classmethod
    def from_repo_full_name(cls, repo_full_name: RepoFullName) -> Self:
        """Create a RepoReference object from a RepoFullName object.

        Args:
            repo_full_name: A repository full name in the format 'owner/name'.

        Returns:
            A RepoReference object.
        """
        m = re.match(REPO_FULL_NAME_PATTERN, repo_full_name)
        if not m:
            raise InvalidRepoFullName(repo_full_name)
        owner = m.group("owner")
        name = m.group("name")
        return cls(owner=owner, name=name)

    @classmethod
    def from_github_repo_url(cls, github_repo_url: GitHubRepoURL) -> Self:
        """Create a RepoReference object from a GitHub repository URL.

        Args:
            github_repo_url: A GitHub repository URL in the format 'https://github.com/owner/name'.
                The URL can be HTTP or HTTPS.
                The URL can end with or without a trailing '.git' suffix.

        Returns:
            A RepoReference object.
        """
        m = re.match(REPO_URL_PATTERN, github_repo_url)
        if not m:
            raise InvalidGitHubRepoURL(github_repo_url)
        owner = m.group("owner")
        name = m.group("name")
        return cls(owner=owner, name=name)

full_name property 🔗

full_name: str

Returns the full name of the repository in the format 'owner/name'.

from_github_repo_url classmethod 🔗

from_github_repo_url(github_repo_url: GitHubRepoURL) -> Self

Create a RepoReference object from a GitHub repository URL.

Parameters:

Name Type Description Default

github_repo_url 🔗

GitHubRepoURL

A GitHub repository URL in the format 'https://github.com/owner/name'. The URL can be HTTP or HTTPS. The URL can end with or without a trailing '.git' suffix.

required

Returns:

Type Description
Self

A RepoReference object.

Source code in src/brag/repository.py
@classmethod
def from_github_repo_url(cls, github_repo_url: GitHubRepoURL) -> Self:
    """Create a RepoReference object from a GitHub repository URL.

    Args:
        github_repo_url: A GitHub repository URL in the format 'https://github.com/owner/name'.
            The URL can be HTTP or HTTPS.
            The URL can end with or without a trailing '.git' suffix.

    Returns:
        A RepoReference object.
    """
    m = re.match(REPO_URL_PATTERN, github_repo_url)
    if not m:
        raise InvalidGitHubRepoURL(github_repo_url)
    owner = m.group("owner")
    name = m.group("name")
    return cls(owner=owner, name=name)

from_repo_full_name classmethod 🔗

from_repo_full_name(repo_full_name: RepoFullName) -> Self

Create a RepoReference object from a RepoFullName object.

Parameters:

Name Type Description Default

repo_full_name 🔗

RepoFullName

A repository full name in the format 'owner/name'.

required

Returns:

Type Description
Self

A RepoReference object.

Source code in src/brag/repository.py
@classmethod
def from_repo_full_name(cls, repo_full_name: RepoFullName) -> Self:
    """Create a RepoReference object from a RepoFullName object.

    Args:
        repo_full_name: A repository full name in the format 'owner/name'.

    Returns:
        A RepoReference object.
    """
    m = re.match(REPO_FULL_NAME_PATTERN, repo_full_name)
    if not m:
        raise InvalidRepoFullName(repo_full_name)
    owner = m.group("owner")
    name = m.group("name")
    return cls(owner=owner, name=name)