Skip to content

github_commits

Fetch and format Github commits.

This module provides functionality to: - Fetch commits from a Github repository for a specific user. - Format commit information into a context string suitable for generating brag documents.

Classes:

Name Description
GithubCommitsSource

A class to fetch Github commits from a repository for a specific user.

GithubCommitsSource dataclass 🔗

Bases: DataSource[FormattedGithubCommit]

A class to fetch Github commits from a repository for a specific user.

Attributes:

Name Type Description
github Github

A Github API client instance.

repo RepoReference

A RepoReference object representing the repository.

author str

The username of the author whose commits are being fetched.

from_date datetime | None

An optional datetime object representing the start date for fetching commits.

to_date datetime | None

An optional datetime object representing the end date for fetching commits.

Source code in src/brag/sources/github_commits.py
@dataclass(frozen=True, slots=True)
class GithubCommitsSource(DataSource[FormattedGithubCommit]):
    """A class to fetch Github commits from a repository for a specific user.

    Attributes:
        github: A Github API client instance.
        repo: A RepoReference object representing the repository.
        author: The username of the author whose commits are being fetched.
        from_date: An optional datetime object representing the start date for fetching commits.
        to_date: An optional datetime object representing the end date for fetching commits.
    """

    github: Github
    repo: RepoReference
    author: str
    from_date: datetime | None = None
    to_date: datetime | None = None

    def __iter__(self) -> Iterator[FormattedGithubCommit]:
        return map(_format_github_commit_as_prompt_context, self._commits)

    def __len__(self) -> int:
        return self._commits.totalCount

    @cached_property
    def _commits(self) -> PaginatedList[GithubCommit]:
        return self.github.get_repo(self.repo.full_name).get_commits(
            author=self.author,
            since=self.from_date or NotSet,
            until=self.to_date or NotSet,
        )