Skip to content

Owner

Base classes

Name Children Inherits
BaseOwner
githarbor.core.base
Base class for repository owners.

⋔ Inheritance diagram

graph TD
  1720926832["user_proxy.Owner"]
  697273899["base.BaseOwner"]
  2751680898["builtins.object"]
  697273899 --> 1720926832
  2751680898 --> 697273899

🛈 DocStrings

Bases: BaseOwner

Proxy class that forwards all method calls to an owner instance.

Source code in src/githarbor/core/user_proxy.py
class Owner(BaseOwner):
    """Proxy class that forwards all method calls to an owner instance."""

    def __init__(self, owner: BaseOwner) -> None:
        """Initialize proxy with owner instance.

        Args:
            owner: Owner instance to forward calls to.
        """
        self._owner = owner
        self.owner_type = type(owner).__name__.removesuffix("Owner")

    def __repr__(self) -> str:
        return f"<{self.owner_type} {self.owner.name}>"

    @property
    def owner(self) -> BaseOwner:
        """Return wrapped owner instance."""
        return self._owner

    def list_repositories(self) -> list[BaseRepository]:
        """List repositories owned by this user.

        Returns:
            List of repositories.
        """
        if self._owner.is_async:
            return asyncio.run(self._owner.list_repositories_async())
        return self._owner.list_repositories()

    def create_repository(
        self,
        name: str,
        description: str = "",
        private: bool = False,
    ) -> BaseRepository:
        """Create a new repository.

        Args:
            name: Repository name
            description: Repository description
            private: Whether to create a private repository

        Returns:
            Newly created repository.
        """
        if self._owner.is_async:
            return asyncio.run(self._owner.create_repository_async(name, description, private))
        return self._owner.create_repository(name, description, private)

    def get_user(self) -> User:
        """Get user information.

        Returns:
            User information.
        """
        if self._owner.is_async:
            return asyncio.run(self._owner.get_user_async())
        return self._owner.get_user()

    def delete_repository(self, name: str) -> None:
        """Delete a repository.

        Args:
            name: Name of repository to delete
        """
        if self._owner.is_async:
            return asyncio.run(self._owner.delete_repository_async(name))
        return self._owner.delete_repository(name)

    async def list_repositories_async(self) -> list[BaseRepository]:
        """List repositories asynchronously."""
        if self._owner.is_async:
            return await self._owner.list_repositories_async()
        return await asyncio.to_thread(self._owner.list_repositories)

    async def create_repository_async(
        self,
        name: str,
        description: str = "",
        private: bool = False,
    ) -> BaseRepository:
        """Create repository asynchronously."""
        if self._owner.is_async:
            return await self._owner.create_repository_async(
                name,
                description,
                private,
            )
        return await asyncio.to_thread(
            self._owner.create_repository,
            name,
            description,
            private,
        )

    async def get_user_async(self) -> User:
        """Get user information asynchronously."""
        if self._owner.is_async:
            return await self._owner.get_user_async()
        return await asyncio.to_thread(self._owner.get_user)

    async def delete_repository_async(self, name: str) -> None:
        """Delete repository asynchronously."""
        if self._owner.is_async:
            await self._owner.delete_repository_async(name)
        await asyncio.to_thread(self._owner.delete_repository, name)

    def get_sync_methods(self) -> list[Callable]:
        """Return list of all synchronous methods."""
        return [
            self.list_repositories,
            self.create_repository,
            self.get_user,
            self.delete_repository,
        ]

    def get_async_methods(self) -> list[Callable]:
        """Return list of all asynchronous methods."""
        return [
            self.list_repositories_async,
            self.create_repository_async,
            self.get_user_async,
            self.delete_repository_async,
        ]

owner property

owner: BaseOwner

Return wrapped owner instance.

__init__

__init__(owner: BaseOwner) -> None

Initialize proxy with owner instance.

Parameters:

Name Type Description Default
owner BaseOwner

Owner instance to forward calls to.

required
Source code in src/githarbor/core/user_proxy.py
def __init__(self, owner: BaseOwner) -> None:
    """Initialize proxy with owner instance.

    Args:
        owner: Owner instance to forward calls to.
    """
    self._owner = owner
    self.owner_type = type(owner).__name__.removesuffix("Owner")

create_repository

create_repository(name: str, description: str = '', private: bool = False) -> BaseRepository

Create a new repository.

Parameters:

Name Type Description Default
name str

Repository name

required
description str

Repository description

''
private bool

Whether to create a private repository

False

Returns:

Type Description
BaseRepository

Newly created repository.

Source code in src/githarbor/core/user_proxy.py
def create_repository(
    self,
    name: str,
    description: str = "",
    private: bool = False,
) -> BaseRepository:
    """Create a new repository.

    Args:
        name: Repository name
        description: Repository description
        private: Whether to create a private repository

    Returns:
        Newly created repository.
    """
    if self._owner.is_async:
        return asyncio.run(self._owner.create_repository_async(name, description, private))
    return self._owner.create_repository(name, description, private)

create_repository_async async

create_repository_async(name: str, description: str = '', private: bool = False) -> BaseRepository

Create repository asynchronously.

Source code in src/githarbor/core/user_proxy.py
async def create_repository_async(
    self,
    name: str,
    description: str = "",
    private: bool = False,
) -> BaseRepository:
    """Create repository asynchronously."""
    if self._owner.is_async:
        return await self._owner.create_repository_async(
            name,
            description,
            private,
        )
    return await asyncio.to_thread(
        self._owner.create_repository,
        name,
        description,
        private,
    )

delete_repository

delete_repository(name: str) -> None

Delete a repository.

Parameters:

Name Type Description Default
name str

Name of repository to delete

required
Source code in src/githarbor/core/user_proxy.py
def delete_repository(self, name: str) -> None:
    """Delete a repository.

    Args:
        name: Name of repository to delete
    """
    if self._owner.is_async:
        return asyncio.run(self._owner.delete_repository_async(name))
    return self._owner.delete_repository(name)

delete_repository_async async

delete_repository_async(name: str) -> None

Delete repository asynchronously.

Source code in src/githarbor/core/user_proxy.py
async def delete_repository_async(self, name: str) -> None:
    """Delete repository asynchronously."""
    if self._owner.is_async:
        await self._owner.delete_repository_async(name)
    await asyncio.to_thread(self._owner.delete_repository, name)

get_async_methods

get_async_methods() -> list[Callable]

Return list of all asynchronous methods.

Source code in src/githarbor/core/user_proxy.py
def get_async_methods(self) -> list[Callable]:
    """Return list of all asynchronous methods."""
    return [
        self.list_repositories_async,
        self.create_repository_async,
        self.get_user_async,
        self.delete_repository_async,
    ]

get_sync_methods

get_sync_methods() -> list[Callable]

Return list of all synchronous methods.

Source code in src/githarbor/core/user_proxy.py
def get_sync_methods(self) -> list[Callable]:
    """Return list of all synchronous methods."""
    return [
        self.list_repositories,
        self.create_repository,
        self.get_user,
        self.delete_repository,
    ]

get_user

get_user() -> User

Get user information.

Returns:

Type Description
User

User information.

Source code in src/githarbor/core/user_proxy.py
def get_user(self) -> User:
    """Get user information.

    Returns:
        User information.
    """
    if self._owner.is_async:
        return asyncio.run(self._owner.get_user_async())
    return self._owner.get_user()

get_user_async async

get_user_async() -> User

Get user information asynchronously.

Source code in src/githarbor/core/user_proxy.py
async def get_user_async(self) -> User:
    """Get user information asynchronously."""
    if self._owner.is_async:
        return await self._owner.get_user_async()
    return await asyncio.to_thread(self._owner.get_user)

list_repositories

list_repositories() -> list[BaseRepository]

List repositories owned by this user.

Returns:

Type Description
list[BaseRepository]

List of repositories.

Source code in src/githarbor/core/user_proxy.py
def list_repositories(self) -> list[BaseRepository]:
    """List repositories owned by this user.

    Returns:
        List of repositories.
    """
    if self._owner.is_async:
        return asyncio.run(self._owner.list_repositories_async())
    return self._owner.list_repositories()

list_repositories_async async

list_repositories_async() -> list[BaseRepository]

List repositories asynchronously.

Source code in src/githarbor/core/user_proxy.py
async def list_repositories_async(self) -> list[BaseRepository]:
    """List repositories asynchronously."""
    if self._owner.is_async:
        return await self._owner.list_repositories_async()
    return await asyncio.to_thread(self._owner.list_repositories)

:fa-brands-github: Show source on GitHub