Skip to content

tux.wrappers.github

Classes:

Name Description
GithubService

Classes

GithubService()

Methods:

Name Description
get_repo

Get the repository.

create_issue

Create an issue.

create_issue_comment

Create an issue comment.

close_issue

Close an issue.

get_issue

Get an issue.

get_open_issues

Get all open issues.

get_closed_issues

Get all closed issues.

get_open_pulls

Get all open pulls.

get_closed_pulls

Get all closed pulls.

get_pull

Get a pull request.

Source code in tux/wrappers/github.py
Python
def __init__(self) -> None:
    self.github = GitHub(
        AppInstallationAuthStrategy(
            CONFIG.GITHUB_APP_ID,
            CONFIG.GITHUB_PRIVATE_KEY,
            int(CONFIG.GITHUB_INSTALLATION_ID),
            CONFIG.GITHUB_CLIENT_ID,
            CONFIG.GITHUB_CLIENT_SECRET,
        ),
    )

Functions

get_repo() -> FullRepository async

Get the repository.

Returns:

Type Description
FullRepository

The repository.

Source code in tux/wrappers/github.py
Python
async def get_repo(self) -> FullRepository:
    """
    Get the repository.

    Returns
    -------
    FullRepository
        The repository.
    """
    try:
        response: Response[FullRepository] = await self.github.rest.repos.async_get(
            CONFIG.GITHUB_REPO_OWNER,
            CONFIG.GITHUB_REPO,
        )

        repo: FullRepository = response.parsed_data

    except Exception as e:
        logger.error(f"Error fetching repository: {e}")
        raise

    else:
        return repo
create_issue(title: str, body: str) -> Issue async

Create an issue.

Parameters:

Name Type Description Default
title str

The title of the issue.

required
body str

The body of the issue.

required

Returns:

Type Description
Issue

The created issue.

Source code in tux/wrappers/github.py
Python
async def create_issue(self, title: str, body: str) -> Issue:
    """
    Create an issue.

    Parameters
    ----------
    title : str
        The title of the issue.
    body : str
        The body of the issue.

    Returns
    -------
    Issue
        The created issue.
    """
    try:
        response: Response[Issue] = await self.github.rest.issues.async_create(
            CONFIG.GITHUB_REPO_OWNER,
            CONFIG.GITHUB_REPO,
            title=title,
            body=body,
        )

        created_issue = response.parsed_data

    except Exception as e:
        logger.error(f"Error creating issue: {e}")
        raise

    else:
        return created_issue
create_issue_comment(issue_number: int, body: str) -> IssueComment async

Create an issue comment.

Parameters:

Name Type Description Default
issue_number int

The number of the issue.

required
body str

The body of the comment.

required

Returns:

Type Description
IssueComment

The created issue comment.

Source code in tux/wrappers/github.py
Python
async def create_issue_comment(self, issue_number: int, body: str) -> IssueComment:
    """
    Create an issue comment.

    Parameters
    ----------
    issue_number : int
        The number of the issue.
    body : str
        The body of the comment.

    Returns
    -------
    IssueComment
        The created issue comment.
    """
    try:
        response: Response[IssueComment] = await self.github.rest.issues.async_create_comment(
            CONFIG.GITHUB_REPO_OWNER,
            CONFIG.GITHUB_REPO,
            issue_number,
            body=body,
        )

        created_issue_comment = response.parsed_data

    except Exception as e:
        logger.error(f"Error creating comment: {e}")
        raise

    else:
        return created_issue_comment
close_issue(issue_number: int) -> Issue async

Close an issue.

Parameters:

Name Type Description Default
issue_number int

The number of the issue.

required

Returns:

Type Description
Issue

The closed issue.

Source code in tux/wrappers/github.py
Python
async def close_issue(self, issue_number: int) -> Issue:
    """
    Close an issue.

    Parameters
    ----------
    issue_number : int
        The number of the issue.

    Returns
    -------
    Issue
        The closed issue.
    """
    try:
        response: Response[Issue] = await self.github.rest.issues.async_update(
            CONFIG.GITHUB_REPO_OWNER,
            CONFIG.GITHUB_REPO,
            issue_number,
            state="closed",
        )

        closed_issue = response.parsed_data

    except Exception as e:
        logger.error(f"Error closing issue: {e}")
        raise

    else:
        return closed_issue
get_issue(issue_number: int) -> Issue async

Get an issue.

Parameters:

Name Type Description Default
issue_number int

The number of the issue.

required

Returns:

Type Description
Issue

The issue.

Source code in tux/wrappers/github.py
Python
async def get_issue(self, issue_number: int) -> Issue:
    """
    Get an issue.

    Parameters
    ----------
    issue_number : int
        The number of the issue.

    Returns
    -------
    Issue
        The issue.
    """

    try:
        response: Response[Issue] = await self.github.rest.issues.async_get(
            CONFIG.GITHUB_REPO_OWNER,
            CONFIG.GITHUB_REPO,
            issue_number,
        )

        issue = response.parsed_data

    except Exception as e:
        logger.error(f"Error fetching issue: {e}")
        raise

    else:
        return issue
get_open_issues() -> list[Issue] async

Get all open issues.

Returns:

Type Description
list[Issue]

The list of open issues.

Source code in tux/wrappers/github.py
Python
async def get_open_issues(self) -> list[Issue]:
    """
    Get all open issues.

    Returns
    -------
    list[Issue]
        The list of open issues.
    """

    try:
        response: Response[list[Issue]] = await self.github.rest.issues.async_list_for_repo(
            CONFIG.GITHUB_REPO_OWNER,
            CONFIG.GITHUB_REPO,
            state="open",
        )

        open_issues = response.parsed_data

    except Exception as e:
        logger.error(f"Error fetching issues: {e}")
        raise

    else:
        return open_issues
get_closed_issues() -> list[Issue] async

Get all closed issues.

Returns:

Type Description
list[Issue]

The list of closed issues.

Source code in tux/wrappers/github.py
Python
async def get_closed_issues(self) -> list[Issue]:
    """
    Get all closed issues.

    Returns
    -------
    list[Issue]
        The list of closed issues.
    """

    try:
        response: Response[list[Issue]] = await self.github.rest.issues.async_list_for_repo(
            CONFIG.GITHUB_REPO_OWNER,
            CONFIG.GITHUB_REPO,
            state="closed",
        )

        closed_issues = response.parsed_data

    except Exception as e:
        logger.error(f"Error fetching issues: {e}")
        raise

    else:
        return closed_issues
get_open_pulls() -> list[PullRequestSimple] async

Get all open pulls.

Returns:

Type Description
list[PullRequestSimple]

The list of open pulls.

Source code in tux/wrappers/github.py
Python
async def get_open_pulls(self) -> list[PullRequestSimple]:
    """
    Get all open pulls.

    Returns
    -------
    list[PullRequestSimple]
        The list of open pulls.
    """

    try:
        response: Response[list[PullRequestSimple]] = await self.github.rest.pulls.async_list(
            CONFIG.GITHUB_REPO_OWNER,
            CONFIG.GITHUB_REPO,
            state="open",
        )

        open_pulls = response.parsed_data

    except Exception as e:
        logger.error(f"Error fetching PRs: {e}")
        raise

    else:
        return open_pulls
get_closed_pulls() -> list[PullRequestSimple] async

Get all closed pulls.

Returns:

Type Description
list[PullRequestSimple]

The list of closed pulls.

Source code in tux/wrappers/github.py
Python
async def get_closed_pulls(self) -> list[PullRequestSimple]:
    """
    Get all closed pulls.

    Returns
    -------
    list[PullRequestSimple]
        The list of closed pulls.
    """

    try:
        response: Response[list[PullRequestSimple]] = await self.github.rest.pulls.async_list(
            CONFIG.GITHUB_REPO_OWNER,
            CONFIG.GITHUB_REPO,
            state="closed",
        )

        closed_pulls = response.parsed_data

    except Exception as e:
        logger.error(f"Error fetching PRs: {e}")
        raise

    else:
        return closed_pulls
get_pull(pr_number: int) -> PullRequest async

Get a pull request.

Parameters:

Name Type Description Default
pr_number int

The number of the pull request.

required

Returns:

Type Description
PullRequest

The pull request.

Source code in tux/wrappers/github.py
Python
async def get_pull(self, pr_number: int) -> PullRequest:
    """
    Get a pull request.

    Parameters
    ----------
    pr_number : int
        The number of the pull request.

    Returns
    -------
    PullRequest
        The pull request.
    """

    try:
        response: Response[PullRequest] = await self.github.rest.pulls.async_get(
            CONFIG.GITHUB_REPO_OWNER,
            CONFIG.GITHUB_REPO,
            pr_number,
        )

        pull = response.parsed_data

    except Exception as e:
        logger.error(f"Error fetching PR: {e}")
        raise

    else:
        return pull