Skip to content

ci_dataclasses

AssociatedPullRequest

Bases: BaseModel

Information for commits that are associated with a pull request.

Attributes:

Name Type Description
author Author

...

merged bool

...

pr_number int

...

target_branch str

...

target_sha str

...

pr_branch str

...

pr_sha str

...

title str

...

body str

...

Source code in m/github/ci_dataclasses.py
class AssociatedPullRequest(BaseModel):
    """Information for commits that are associated with a pull request."""

    # pylint: disable=too-many-instance-attributes
    author: Author
    merged: bool
    pr_number: int
    target_branch: str
    target_sha: str
    pr_branch: str
    pr_sha: str
    title: str
    body: str

Author

Bases: CamelModel

An object representing a committer.

Attributes:

Name Type Description
login str

...

avatar_url str | None

...

email str | None

...

Source code in m/github/ci_dataclasses.py
class Author(CamelModel):
    """An object representing a committer."""

    login: str
    avatar_url: str | None = None
    email: str | None = None

Commit

Bases: BaseModel

The git commit info.

Attributes:

Name Type Description
author_login str

...

short_sha str

...

sha str

...

message str

...

url str

...

associated_pull_request Optional[AssociatedPullRequest]

...

Source code in m/github/ci_dataclasses.py
class Commit(BaseModel):
    """The git commit info."""

    author_login: str
    short_sha: str
    sha: str
    message: str
    url: str
    associated_pull_request: Optional[AssociatedPullRequest] = None

    def get_pr_branch(self) -> str:
        """Find the git branch if commit has an associated pr.

        Returns:
            The pr branch if the commit has an associated pr or empty
            string.
        """
        if not self.associated_pull_request:
            return ''
        return self.associated_pull_request.pr_branch

    def is_release(self, release_prefix: str | None) -> bool:
        """Determine if the current commit should create a release.

        Args:
            release_prefix: The prefix used to flag a release.

        Returns:
            True if we are dealing with a release branch.
        """
        if not release_prefix:
            return False
        return self.get_pr_branch().startswith(f'{release_prefix}/')

get_pr_branch()

Find the git branch if commit has an associated pr.

Returns:

Type Description
str

The pr branch if the commit has an associated pr or empty

str

string.

Source code in m/github/ci_dataclasses.py
def get_pr_branch(self) -> str:
    """Find the git branch if commit has an associated pr.

    Returns:
        The pr branch if the commit has an associated pr or empty
        string.
    """
    if not self.associated_pull_request:
        return ''
    return self.associated_pull_request.pr_branch

is_release(release_prefix)

Determine if the current commit should create a release.

Parameters:

Name Type Description Default
release_prefix str | None

The prefix used to flag a release.

required

Returns:

Type Description
bool

True if we are dealing with a release branch.

Source code in m/github/ci_dataclasses.py
def is_release(self, release_prefix: str | None) -> bool:
    """Determine if the current commit should create a release.

    Args:
        release_prefix: The prefix used to flag a release.

    Returns:
        True if we are dealing with a release branch.
    """
    if not release_prefix:
        return False
    return self.get_pr_branch().startswith(f'{release_prefix}/')

CommitInfo

Bases: BaseModel

A commit can be tracked with the following properties.

Attributes:

Name Type Description
owner str

...

repo str

...

sha str

...

Source code in m/github/ci_dataclasses.py
class CommitInfo(BaseModel):
    """A commit can be tracked with the following properties."""

    owner: str
    repo: str
    sha: str

GithubCiRunInfo

Bases: BaseModel

The main information we need for a ci run.

Attributes:

Name Type Description
commit Commit

...

pull_request Optional[PullRequest]

...

release Optional[Release]

...

Source code in m/github/ci_dataclasses.py
class GithubCiRunInfo(BaseModel):
    """The main information we need for a ci run."""

    commit: Commit
    pull_request: Optional[PullRequest] = None
    release: Optional[Release] = None

PullRequest

Bases: BaseModel

Pull request information.

Attributes:

Name Type Description
author Author

...

pr_number int

...

pr_branch str

...

target_branch str

...

target_sha str

...

url str

...

title str

...

body str

...

file_count int

...

files List[str]

...

is_draft bool

...

Source code in m/github/ci_dataclasses.py
class PullRequest(BaseModel):
    """Pull request information."""

    author: Author
    pr_number: int
    pr_branch: str
    target_branch: str
    target_sha: str
    url: str
    title: str
    body: str
    file_count: int
    files: List[str]
    is_draft: bool

    def changelog_updated(self) -> bool:
        """Determine if the changelog was updated in the pull request.

        Returns:
            True if the changelog was updated.
        """
        return 'CHANGELOG.md' in self.files

    def is_release_pr(self, release_prefix: str | None) -> bool:
        """Determine if the pull request is a release pull request.

        Args:
            release_prefix: The prefix used to flag a release.

        Returns:
            True if we are dealing with a release branch.
        """
        if not release_prefix:
            return False
        return self.pr_branch.startswith(f'{release_prefix}/')

changelog_updated()

Determine if the changelog was updated in the pull request.

Returns:

Type Description
bool

True if the changelog was updated.

Source code in m/github/ci_dataclasses.py
def changelog_updated(self) -> bool:
    """Determine if the changelog was updated in the pull request.

    Returns:
        True if the changelog was updated.
    """
    return 'CHANGELOG.md' in self.files

is_release_pr(release_prefix)

Determine if the pull request is a release pull request.

Parameters:

Name Type Description Default
release_prefix str | None

The prefix used to flag a release.

required

Returns:

Type Description
bool

True if we are dealing with a release branch.

Source code in m/github/ci_dataclasses.py
def is_release_pr(self, release_prefix: str | None) -> bool:
    """Determine if the pull request is a release pull request.

    Args:
        release_prefix: The prefix used to flag a release.

    Returns:
        True if we are dealing with a release branch.
    """
    if not release_prefix:
        return False
    return self.pr_branch.startswith(f'{release_prefix}/')

Release

Bases: BaseModel

Github release <==> Git tag.

Attributes:

Name Type Description
name str

...

tag_name str

...

published_at str

...

Source code in m/github/ci_dataclasses.py
class Release(BaseModel):
    """Github release <==> Git tag."""

    name: str
    tag_name: str
    published_at: str