Skip to content

Commit

Permalink
Change: Use rich.table to display members and repos of an org
Browse files Browse the repository at this point in the history
Extend git scripts to render a CLI table to display members and repos of
a GitHub organization.
  • Loading branch information
bjoernricks committed Dec 5, 2022
1 parent 999a9e6 commit 635624f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
14 changes: 12 additions & 2 deletions scripts/github/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
from argparse import ArgumentParser, Namespace
from typing import Union

from rich.console import Console
from rich.table import Table

from pontos.github.api import GitHubAsyncRESTApi
from pontos.github.api.organizations import MemberFilter, MemberRole

Expand Down Expand Up @@ -62,12 +65,19 @@ def add_script_arguments(parser: ArgumentParser) -> None:


async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> int:
table = Table()
table.add_column("Name")
table.add_column("URL")

member_count = 0
async for member in api.organizations.members(
async for user in api.organizations.members(
args.organization, member_filter=args.filter, role=args.role
):
print(member, "\n")
table.add_row(user.login, user.html_url)
member_count += 1

console = Console()
console.print(table)

print(f"{member_count} members.")
return 0
17 changes: 16 additions & 1 deletion scripts/github/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
from argparse import ArgumentParser, Namespace
from typing import Union

from rich.console import Console
from rich.table import Table

from pontos.github.api import GitHubAsyncRESTApi
from pontos.github.api.helper import RepositoryType

Expand All @@ -47,12 +50,24 @@ def add_script_arguments(parser: ArgumentParser) -> None:


async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> int:
table = Table()
table.add_column("Name")
table.add_column("Description")
table.add_column("URL")
table.add_column("Visibility")

repo_count = 0
async for repo in api.organizations.get_repositories(
args.organization, repository_type=args.type
):
print(repo, "\n")
table.add_row(
repo.name, repo.description, repo.html_url, repo.visibility
)

repo_count += 1

console = Console()
console.print(table)

print(f"{repo_count} repositories.")
return 0

0 comments on commit 635624f

Please sign in to comment.