diff --git a/.gitignore b/.gitignore index 42ffb51..7395f3a 100755 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,11 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. +__pycache__/ # virtual environment venv/* venv +*.pyc +*.cpython # Ignore sqlite database files *.db diff --git a/docs/data-flow.drawio b/docs/data-flow.drawio new file mode 100644 index 0000000..bfba3a1 --- /dev/null +++ b/docs/data-flow.drawio @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/github_cli/__pycache__/__init__.cpython-313.pyc b/src/github_cli/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index dce9c87..0000000 Binary files a/src/github_cli/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/src/github_cli/__pycache__/__main__.cpython-313.pyc b/src/github_cli/__pycache__/__main__.cpython-313.pyc deleted file mode 100644 index 596ee0d..0000000 Binary files a/src/github_cli/__pycache__/__main__.cpython-313.pyc and /dev/null differ diff --git a/src/github_cli/__pycache__/gh_actions.cpython-313.pyc b/src/github_cli/__pycache__/gh_actions.cpython-313.pyc deleted file mode 100644 index aab97d9..0000000 Binary files a/src/github_cli/__pycache__/gh_actions.cpython-313.pyc and /dev/null differ diff --git a/src/github_cli/__pycache__/main.cpython-313.pyc b/src/github_cli/__pycache__/main.cpython-313.pyc deleted file mode 100644 index 0ae3abc..0000000 Binary files a/src/github_cli/__pycache__/main.cpython-313.pyc and /dev/null differ diff --git a/src/github_cli/__pycache__/repos.cpython-313.pyc b/src/github_cli/__pycache__/repos.cpython-313.pyc deleted file mode 100644 index 9a2b70d..0000000 Binary files a/src/github_cli/__pycache__/repos.cpython-313.pyc and /dev/null differ diff --git a/src/github_cli/gh_actions.py b/src/github_cli/actions/gh_actions.py similarity index 100% rename from src/github_cli/gh_actions.py rename to src/github_cli/actions/gh_actions.py diff --git a/src/github_cli/actions/refresh.py b/src/github_cli/actions/refresh.py new file mode 100644 index 0000000..081b285 --- /dev/null +++ b/src/github_cli/actions/refresh.py @@ -0,0 +1,5 @@ + + +def handle_refresh(): + """Handle refresh database""" + print("to be implemented - refresh actions go here") diff --git a/src/github_cli/repos.py b/src/github_cli/actions/repos.py similarity index 84% rename from src/github_cli/repos.py rename to src/github_cli/actions/repos.py index 2c8758b..1914cac 100644 --- a/src/github_cli/repos.py +++ b/src/github_cli/actions/repos.py @@ -8,8 +8,9 @@ import requests from rich.console import Console from rich.table import Table -from github_cli.gh_actions import __request_repo_workflows +from github_cli.actions.gh_actions import __request_repo_workflows from github_cli.models.workflow import GitHubWorkflow +from github_cli.models.repository import GitHubRepository from github_cli.database.manager import DatabaseManager def __request_repos_for_user(username: str) -> List[Any]: @@ -90,17 +91,14 @@ def user_repos_report(username: str): # Render table console.print(table) -def handle_args(args): - """Handle args for repo commands - - Args: - args (_type_): _description_ - """ - if args.report == 'list': - user_repos_report(args.user) - - if args.report == 'workflows': - wfs = __request_repo_workflows(owner = 'meddlin', repo = 'github-inventory') - for w in wfs: - workflow = GitHubWorkflow.from_dict(w) - print(workflow.name) +def handle_repos(username: str): + repo_data = __request_repos_for_user(username=username) + for repo in repo_data: + gh_repo = GitHubRepository( + id=repo['id'], + node_id=repo['node_id'], + url=repo['url'], + language=repo['language'] + ) + print(gh_repo.url) + print('all repos processed...') diff --git a/src/github_cli/database/__pycache__/manager.cpython-313.pyc b/src/github_cli/database/__pycache__/manager.cpython-313.pyc deleted file mode 100644 index 804b16a..0000000 Binary files a/src/github_cli/database/__pycache__/manager.cpython-313.pyc and /dev/null differ diff --git a/src/github_cli/main.py b/src/github_cli/main.py index d64f13d..abb7634 100644 --- a/src/github_cli/main.py +++ b/src/github_cli/main.py @@ -4,7 +4,8 @@ import argparse import textwrap from dotenv import load_dotenv -from github_cli import repos +from github_cli.actions import repos as repo_actions +from github_cli.actions import refresh as refresh_actions def start_repl(): print("Welcome to the REPL") @@ -28,27 +29,62 @@ def main(): print("Welcome to GitHub Inventory!") load_dotenv() - parser = argparse.ArgumentParser(prog = 'github-inventory', - formatter_class = argparse.RawDescriptionHelpFormatter, - epilog = textwrap.dedent('Examples: main.py --option') - ) - parser.add_argument('--repl', action = argparse.BooleanOptionalAction, help = "Start REPL-mode") + parser = argparse.ArgumentParser( + prog = 'github-inventory', + formatter_class = argparse.RawDescriptionHelpFormatter, + epilog = textwrap.dedent('Examples: main.py --option') + ) + subparsers = parser.add_subparsers(dest="command") - subparsers = parser.add_subparsers(dest = 'service', required = True) - gh_parser = subparsers.add_parser('github', help = 'GitHub related commands') - gh_subparser = gh_parser.add_subparsers(dest = 'command') + refresh_parser = subparsers.add_parser("refresh", help="Refresh the database") - repo_parser = gh_subparser.add_parser('repo', help = 'GitHub repo commands') - repo_parser.add_argument('--name', type = str, help = 'Name of repository') - repo_parser.add_argument('--owner', type = str, help = 'Owner of repository') - repo_parser.add_argument('--report', type = str, help = 'Type of report to execute') - repo_parser.add_argument('--user', type = str, help = 'GitHub username') - repo_parser.add_argument('--csv', action = argparse.BooleanOptionalAction) - repo_parser.set_defaults(func = repos.handle_args) + import_parser = subparsers.add_parser("import", help="Import data to the database") + import_parser.add_argument( + "--repos", + action="store_true", + help="Import all repos" + ) + import_parser.add_argument( + "--orgs", + action="store_true", + help="Import all orgs" + ) + + list_parser = subparsers.add_parser("list", help="List items in the database") + list_parser.add_argument( + "--repos", + action="store_true", + help="List all repos.", + ) args = parser.parse_args() - if hasattr(args, 'func'): - args.func(args) + + if args.command == "refresh": + # TODO: Implement refresh action + refresh_actions.handle_refresh() + elif args.command == "list": + if args.repos: + repo_actions.handle_repos(username="meddlin") + # repo_data = repos.__request_repos_for_user(username="meddlin") + # print(repo_data) + + # parser.add_argument('--repl', action = argparse.BooleanOptionalAction, help = "Start REPL-mode") + + # subparsers = parser.add_subparsers(dest = 'service', required = True) + # gh_parser = subparsers.add_parser('github', help = 'GitHub related commands') + # gh_subparser = gh_parser.add_subparsers(dest = 'command') + + # repo_parser = gh_subparser.add_parser('repo', help = 'GitHub repo commands') + # repo_parser.add_argument('--name', type = str, help = 'Name of repository') + # repo_parser.add_argument('--owner', type = str, help = 'Owner of repository') + # repo_parser.add_argument('--report', type = str, help = 'Type of report to execute') + # repo_parser.add_argument('--user', type = str, help = 'GitHub username') + # repo_parser.add_argument('--csv', action = argparse.BooleanOptionalAction) + # repo_parser.set_defaults(func = repos.handle_args) + + # args = parser.parse_args() + # if hasattr(args, 'func'): + # args.func(args) if __name__ == "__main__": main() diff --git a/src/github_cli/models/__pycache__/workflow.cpython-313.pyc b/src/github_cli/models/__pycache__/workflow.cpython-313.pyc deleted file mode 100644 index 76bead4..0000000 Binary files a/src/github_cli/models/__pycache__/workflow.cpython-313.pyc and /dev/null differ diff --git a/src/github_cli/models/repository.py b/src/github_cli/models/repository.py index 28a5552..8264e41 100644 --- a/src/github_cli/models/repository.py +++ b/src/github_cli/models/repository.py @@ -4,82 +4,159 @@ class GitHubRepository: def __init__( self, - id: int, - node_id: str, - name: str, - full_name: str, - private: bool, - owner: GitHubOwner, - html_url: str, - description: str, - fork: bool, - url: str, - forks_url: str, - keys_url: str, - collaborators_url: str, - teams_url: str, - hooks_url: str, - issue_events_url: str, - events_url: str, - assignees_url: str, - branches_url: str, - tags_url: str, - blobs_url: str, - git_tags_url: str, - git_refs_url: str, - trees_url: str, - statuses_url: str, - languages_url: str, - stargazers_url: str, - contributors_url: str, - cubscribers_url: str, - subscription_url: str, - commits_url: str, - issue_comment_url: str, - contents_url: str, - compare_url: str, - merges_url: str, - archive_url: str, - downloads_url: str, - issues_url: str, - pulls_url: str, - milestones_url: str, - notifications_url: str, - labels_url: str, - releases_url: str, - deployments_url: str, - created_at: str, - updated_at: str, - pushed_at: str, - git_url: str, - ssh_url: str, - clone_url: str, - svn_url: str, - homepage: Any, - size: int, - stargazers_count: int, - watchers_count: int, - language: str, - has_issues: bool, - has_projects: bool, - has_downloads: bool, - has_wiki: bool, - has_pages: bool, - has_discussions: bool, - forks_count: int, - mirror_url: str, - archived: bool, - disabled: bool, - open_issues_count: int, - license: str, - allow_forking: bool, - is_template: bool, - web_commit_signoff_required: bool, - topics: List[Any], - visibility: str, - forks: int, - open_issues: int, - watchers: int, - default_branch: str, - permissions: GitHubRepoPermissions - ) + id: int | None = None, + node_id: str = "", + name: str = "", + full_name: str = "", + private: bool | None = None, + owner: GitHubOwner | None = None, + html_url: str = "", + description: str = "", + fork: bool | None = None, + url: str = "", + forks_url: str = "", + keys_url: str = "", + collaborators_url: str = "", + teams_url: str = "", + hooks_url: str = "", + issue_events_url: str = "", + events_url: str = "", + assignees_url: str = "", + branches_url: str = "", + tags_url: str = "", + blobs_url: str = "", + git_tags_url: str = "", + git_refs_url: str = "", + trees_url: str = "", + statuses_url: str = "", + languages_url: str = "", + stargazers_url: str = "", + contributors_url: str = "", + cubscribers_url: str = "", + subscription_url: str = "", + commits_url: str = "", + issue_comment_url: str = "", + contents_url: str = "", + compare_url: str = "", + merges_url: str = "", + archive_url: str = "", + downloads_url: str = "", + issues_url: str = "", + pulls_url: str = "", + milestones_url: str = "", + notifications_url: str = "", + labels_url: str = "", + releases_url: str = "", + deployments_url: str = "", + created_at: str = "", + updated_at: str = "", + pushed_at: str = "", + git_url: str = "", + ssh_url: str = "", + clone_url: str = "", + svn_url: str = "", + homepage: Any = None, + size: int | None = None, + stargazers_count: int | None = None, + watchers_count: int | None = None, + language: str = "", + has_issues: bool | None = None, + has_projects: bool | None = None, + has_downloads: bool | None = None, + has_wiki: bool | None = None, + has_pages: bool | None = None, + has_discussions: bool | None = None, + forks_count: int | None = None, + mirror_url: str = "", + archived: bool | None = None, + disabled: bool | None = None, + open_issues_count: int | None = None, + license: str = "", + allow_forking: bool | None = None, + is_template: bool | None = None, + web_commit_signoff_required: bool | None = None, + topics: List[Any] | None = None, + visibility: str = "", + forks: int | None = None, + open_issues: int| None = None, + watchers: int | None = None, + default_branch: str = "", + # permissions: GitHubRepoPermissions + ): + self.id = id + self.node_id = node_id + self.name = name + self.full_name = full_name + self.private = private + self.owner = owner + self.html_url = html_url + self.description = description + self.fork = fork + self.url = url + self.forks_url = forks_url + self.keys_url = keys_url + self.collaborators_url = collaborators_url + self.teams_url = teams_url + self.hooks_url = hooks_url + self.issue_events_url = issue_events_url + self.events_url = events_url + self.assignees_url = assignees_url + self.branches_url = branches_url + self.tags_url = tags_url + self.blobs_url = blobs_url + self.git_tags_url = git_tags_url + self.git_refs_url = git_refs_url + self.trees_url = trees_url + self.statuses_url = statuses_url + self.languages_url = languages_url + self.stargazers_url = stargazers_url + self.contributors_url = contributors_url + self.cubscribers_url = cubscribers_url + self.subscription_url = subscription_url + self.commits_url = commits_url + self.issue_comment_url = issue_comment_url + self.contents_url = contents_url + self.compare_url = compare_url + self.merges_url = merges_url + self.archive_url = archive_url + self.downloads_url = downloads_url + self.issues_url = issues_url + self.pulls_url = pulls_url + self.milestones_url = milestones_url + self.notifications_url = notifications_url + self.labels_url = labels_url + self.releases_url = releases_url + self.deployments_url = deployments_url + self.created_at = created_at + self.updated_at = updated_at + self.pushed_at = pushed_at + self.git_url = git_url + self.ssh_url = ssh_url + self.clone_url = clone_url + self.svn_url = svn_url + self.homepage = homepage + self.size = size + self.stargazers_count = stargazers_count + self.watchers_count = watchers_count + self.language = language + self.has_issues = has_issues + self.has_projects = has_projects + self.has_downloads = has_downloads + self.has_wiki = has_wiki + self.has_pages = has_pages + self.has_discussions = has_discussions + self.forks_count = forks_count + self.mirror_url = mirror_url + self.archived = archived + self.disabled = disabled + self.open_issues_count = open_issues_count + self.license = license + self.allow_forking = allow_forking + self.is_template = is_template + self.web_commit_signoff_required = web_commit_signoff_required + self.topics = topics + self.visibility = visibility + self.forks = forks + self.open_issues = open_issues + self.watchers = watchers + self.default_branch = default_branch \ No newline at end of file