Skip to content

gitea.cli.issue.list

list

List issues command.

--issue-ids narrows the listing to a known set of issues. Gitea's listing takes no such filter, so the set is applied here, over the listing the other filters select: its pages are walked until every requested issue has been seen or the listing ends, and the issues are emitted in the order they were asked for. An issue of the set that the other filters exclude - a closed one under the default --state open, say - is simply not listed, which is what makes "which of these are open" one call; metadata.not_listed names each such issue, so it can be told apart from one that was listed. issue get is the command that fails on an issue that does not exist.

Functions:

gitea.cli.issue.list.list_command

list_command(
    ctx: Context,
    owner: Annotated[
        str,
        Option("--owner", help="Owner of the repository."),
    ],
    repository: Annotated[
        str | None,
        Option(
            "--repository", help=REPOSITORY_REQUIRED_HELP
        ),
    ] = None,
    state: Annotated[
        Literal["closed", "open", "all"] | None,
        Option("--state", help="Filter issues by state."),
    ] = None,
    labels: Annotated[
        list[str] | None,
        Option("--labels", help="Filter issues by labels."),
    ] = None,
    search_string: Annotated[
        str | None,
        Option(
            "--search-string",
            help="Filter issues by search string.",
        ),
    ] = None,
    issue_type: Annotated[
        Literal["issues", "pulls"] | None,
        Option(
            "--issue-type", help="Filter by issue type."
        ),
    ] = None,
    milestones: Annotated[
        list[str] | None,
        Option(
            "--milestones",
            help="Filter issues by milestones.",
        ),
    ] = None,
    since: Annotated[
        datetime | None,
        Option(
            "--since",
            help="Filter issues updated since this time.",
        ),
    ] = None,
    before: Annotated[
        datetime | None,
        Option(
            "--before",
            help="Filter issues updated before this time.",
        ),
    ] = None,
    created_by: Annotated[
        str | None,
        Option(
            "--created-by",
            help="Filter issues created by this user.",
        ),
    ] = None,
    assigned_by: Annotated[
        str | None,
        Option(
            "--assigned-by",
            help="Filter issues assigned to this user.",
        ),
    ] = None,
    mentioned_by: Annotated[
        str | None,
        Option(
            "--mentioned-by",
            help="Filter issues mentioning this user.",
        ),
    ] = None,
    issue_ids: Annotated[
        str | None,
        Option("--issue-ids", help=ISSUE_IDS_FILTER_HELP),
    ] = None,
    page: Annotated[
        int | None,
        Option(
            "--page", help="The page number for pagination."
        ),
    ] = None,
    limit: Annotated[
        int | None,
        Option(
            "--limit", help="The number of issues per page."
        ),
    ] = None,
    account_name: Annotated[
        str | None,
        Option(
            "--account-name",
            help="Name of the account to use for authentication.",
        ),
    ] = None,
    token: Annotated[
        str | None,
        Option(
            "--token",
            help="Token for authentication. If not provided, the token from the specified account will be used.",
        ),
    ] = None,
    base_url: Annotated[
        str | None,
        Option(
            "--base-url",
            help="Base URL of the Gitea platform. If not provided, the base URL from the specified account will be used.",
        ),
    ] = None,
) -> None

List issues in a repository.

Parameters:

Name Type Description Default
ctx Context

The Typer context.

required
owner Annotated[str, Option('--owner', help='Owner of the repository.')]

The owner of the repository.

required
repository Annotated[str | None, Option('--repository', help=REPOSITORY_REQUIRED_HELP)]

The name of the repository, which this command requires.

None
state Annotated[Literal['closed', 'open', 'all'] | None, Option('--state', help='Filter issues by state.')]

Filter issues by state.

None
labels Annotated[list[str] | None, Option('--labels', help='Filter issues by labels.')]

Filter issues by labels.

None
search_string Annotated[str | None, Option('--search-string', help='Filter issues by search string.')]

Filter issues by search string.

None
issue_type Annotated[Literal['issues', 'pulls'] | None, Option('--issue-type', help='Filter by issue type.')]

Filter by issue type.

None
milestones Annotated[list[str] | None, Option('--milestones', help='Filter issues by milestones.')]

Filter issues by milestones.

None
since Annotated[datetime | None, Option('--since', help='Filter issues updated since this time.')]

Filter issues updated since this time.

None
before Annotated[datetime | None, Option('--before', help='Filter issues updated before this time.')]

Filter issues updated before this time.

None
created_by Annotated[str | None, Option('--created-by', help='Filter issues created by this user.')]

Filter issues created by this user.

None
assigned_by Annotated[str | None, Option('--assigned-by', help='Filter issues assigned to this user.')]

Filter issues assigned to this user.

None
mentioned_by Annotated[str | None, Option('--mentioned-by', help='Filter issues mentioning this user.')]

Filter issues mentioning this user.

None
issue_ids Annotated[str | None, Option('--issue-ids', help=ISSUE_IDS_FILTER_HELP)]

List only these issues, given as comma-separated numbers.

None
page Annotated[int | None, Option('--page', help='The page number for pagination.')]

The page number for pagination.

None
limit Annotated[int | None, Option('--limit', help='The number of issues per page.')]

The number of issues per page.

None
account_name Annotated[str | None, Option('--account-name', help='Name of the account to use for authentication.')]

Name of the account to use for authentication.

None
token Annotated[str | None, Option('--token', help='Token for authentication. If not provided, the token from the specified account will be used.')]

Token for authentication. If not provided, the token from the specified account will be used.

None
base_url Annotated[str | None, Option('--base-url', help='Base URL of the Gitea platform. If not provided, the base URL from the specified account will be used.')]

Base URL of the Gitea platform. If not provided, the base URL from the specified account will be used.

None
Source code in src/gitea/cli/issue/list.py
def list_command(
    ctx: typer.Context,
    owner: Annotated[str, typer.Option("--owner", help="Owner of the repository.")],
    repository: Annotated[str | None, typer.Option("--repository", help=REPOSITORY_REQUIRED_HELP)] = None,
    state: Annotated[
        Literal["closed", "open", "all"] | None, typer.Option("--state", help="Filter issues by state.")
    ] = None,
    labels: Annotated[
        list[str] | None,
        typer.Option("--labels", help="Filter issues by labels."),
    ] = None,
    search_string: Annotated[
        str | None,
        typer.Option("--search-string", help="Filter issues by search string."),
    ] = None,
    issue_type: Annotated[
        Literal["issues", "pulls"] | None,
        typer.Option("--issue-type", help="Filter by issue type."),
    ] = None,
    milestones: Annotated[
        list[str] | None,
        typer.Option("--milestones", help="Filter issues by milestones."),
    ] = None,
    since: Annotated[
        datetime | None,
        typer.Option("--since", help="Filter issues updated since this time."),
    ] = None,
    before: Annotated[
        datetime | None,
        typer.Option("--before", help="Filter issues updated before this time."),
    ] = None,
    created_by: Annotated[
        str | None,
        typer.Option("--created-by", help="Filter issues created by this user."),
    ] = None,
    assigned_by: Annotated[
        str | None,
        typer.Option("--assigned-by", help="Filter issues assigned to this user."),
    ] = None,
    mentioned_by: Annotated[
        str | None,
        typer.Option("--mentioned-by", help="Filter issues mentioning this user."),
    ] = None,
    issue_ids: Annotated[
        str | None,
        typer.Option("--issue-ids", help=ISSUE_IDS_FILTER_HELP),
    ] = None,
    page: Annotated[
        int | None,
        typer.Option("--page", help="The page number for pagination."),
    ] = None,
    limit: Annotated[
        int | None,
        typer.Option("--limit", help="The number of issues per page."),
    ] = None,
    account_name: Annotated[
        str | None,
        typer.Option(
            "--account-name",
            help="Name of the account to use for authentication.",
        ),
    ] = None,
    token: Annotated[
        str | None,
        typer.Option(
            "--token",
            help="Token for authentication. If not provided, the token from the specified account will be used.",
        ),
    ] = None,
    base_url: Annotated[
        str | None,
        typer.Option(
            "--base-url",
            help="Base URL of the Gitea platform. If not provided, the base URL from the specified account will be used.",
        ),
    ] = None,
) -> None:
    """List issues in a repository.

    Args:
        ctx: The Typer context.
        owner: The owner of the repository.
        repository: The name of the repository, which this command requires.
        state: Filter issues by state.
        labels: Filter issues by labels.
        search_string: Filter issues by search string.
        issue_type: Filter by issue type.
        milestones: Filter issues by milestones.
        since: Filter issues updated since this time.
        before: Filter issues updated before this time.
        created_by: Filter issues created by this user.
        assigned_by: Filter issues assigned to this user.
        mentioned_by: Filter issues mentioning this user.
        issue_ids: List only these issues, given as comma-separated numbers.
        page: The page number for pagination.
        limit: The number of issues per page.
        account_name: Name of the account to use for authentication.
        token: Token for authentication. If not provided, the token from the specified account will be used.
        base_url: Base URL of the Gitea platform. If not provided, the base URL from the specified account will be used.

    """
    from gitea.cli.utils.api import execute_api_command  # noqa: PLC0415
    from gitea.cli.utils.auth import get_auth_params  # noqa: PLC0415
    from gitea.cli.utils.convert import list_str_to_list_int_or_none  # noqa: PLC0415
    from gitea.cli.utils.options import require_repository  # noqa: PLC0415
    from gitea.client.gitea import Gitea  # noqa: PLC0415
    from gitea.utils.pagination import PAGE_SIZE  # noqa: PLC0415

    command = "gitea-cli issue list"
    token, base_url = get_auth_params(
        config_path=ctx.obj.get("config_path"),
        account_name=account_name,
        token=token,
        base_url=base_url,
    )

    milestones_values = list_str_to_list_int_or_none(milestones)

    def api_call() -> tuple[dict[str, Any] | list[dict[str, Any]], dict[str, Any]]:
        """List issues in a repository.

        Returns:
            The issue information as a dictionary.

        """
        target_repository = require_repository(repository, command=command)
        requested = _requested_issues(issue_ids, page, command=command)

        with Gitea(token=token, base_url=base_url) as client:

            def fetch(page_number: int | None, page_size: int | None) -> tuple[list[dict[str, Any]], dict[str, Any]]:
                return client.issue.list_issues(
                    owner=owner,
                    repository=target_repository,
                    state=state,
                    labels=labels,
                    search_string=search_string,
                    issue_type=issue_type,
                    milestones=milestones_values,
                    since=since,
                    before=before,
                    created_by=created_by,
                    assigned_by=assigned_by,
                    mentioned_by=mentioned_by,
                    page=page_number,
                    limit=page_size,
                )

            if requested is None:
                return fetch(page, limit)
            return _list_requested(requested, lambda number: fetch(number, limit or PAGE_SIZE))

    execute_api_command(api_call=api_call, base_url=base_url, command_name=command)