Skip to content

cli

get_latest_release(token, owner, repo)

Retrieve the latest release for a repo.

Parameters:

Name Type Description Default
token str

A Github PAT.

required
owner str

The owner of the repo.

required
repo str

The name of the repo.

required

Returns:

Type Description
OneOf[Issue, str]

The latest release.

Source code in m/github/cli.py
def get_latest_release(
    token: str,
    owner: str,
    repo: str,
) -> OneOf[Issue, str]:
    """Retrieve the latest release for a repo.

    Args:
        token: A Github PAT.
        owner: The owner of the repo.
        repo: The name of the repo.

    Returns:
        The latest release.
    """
    query = """query ($owner: String!, $repo: String!) {
      repository(owner:$owner, name:$repo) {
         releases(last: 1, orderBy: {field: CREATED_AT, direction: ASC}) {
            nodes {
                name
                tagName
                publishedAt
            }
        }
      }
    }"""
    variables = {'owner': owner, 'repo': repo}
    return one_of(
        lambda: [
            tag_name
            for res in graphql(token, query, variables)
            for releases in get(res, 'repository.releases.nodes')
            for tag_name in _get_latest_release(releases)
        ],
    )

get_pr_info(token, owner, repo, pr_number, file_count)

Retrieve the information of the given Github PR.

Parameters:

Name Type Description Default
token str

A Github PAT.

required
owner str

The owner of the repo.

required
repo str

The name of the repo.

required
pr_number int

The pull request number in question.

required
file_count int

The maximum number of files in the pr to retrieve.

required

Returns:

Type Description
OneOf[Issue, Any]

The pull request information.

Source code in m/github/cli.py
def get_pr_info(
    token: str,
    owner: str,
    repo: str,
    pr_number: int,
    file_count: int,
) -> OneOf[Issue, Any]:
    """Retrieve the information of the given Github PR.

    Args:
        token: A Github PAT.
        owner: The owner of the repo.
        repo: The name of the repo.
        pr_number: The pull request number in question.
        file_count: The maximum number of files in the pr to retrieve.

    Returns:
        The pull request information.
    """
    query = create_ci_query(
        pr_number,
        include_commit=False,
        include_release=False,
    )
    variables = {
        'owner': owner,
        'repo': repo,
        'pr': pr_number,
        'fc': file_count,
    }
    return one_of(
        lambda: [
            pr_info
            for res in graphql(token, query, variables)
            for pr_info in get(res, 'repository.pullRequest')
        ],
    )