Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
100 changes: 100 additions & 0 deletions docs/data-flow.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<mxfile host="65bd71144e">
<diagram id="_tJi-GHTvori3WxbMm3z" name="Page-1">
<mxGraphModel dx="923" dy="1051" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="0" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="17" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;fontColor=#333333;strokeColor=#666666;" vertex="1" parent="1">
<mxGeometry x="480" y="40" width="200" height="300" as="geometry"/>
</mxCell>
<mxCell id="18" value="&lt;b&gt;Application Models&lt;/b&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;fontColor=#333333;strokeColor=#666666;" vertex="1" parent="1">
<mxGeometry x="480" y="10" width="200" height="30" as="geometry"/>
</mxCell>
<mxCell id="8" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;fontColor=#333333;strokeColor=#666666;" vertex="1" parent="1">
<mxGeometry x="480" y="390" width="200" height="270" as="geometry"/>
</mxCell>
<mxCell id="2" value="GitHub API" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="210" y="330" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="3" value="CLI start&lt;div&gt;- github list --repos&lt;/div&gt;" style="shape=process;whiteSpace=wrap;html=1;backgroundOutline=1;align=left;" vertex="1" parent="1">
<mxGeometry x="30" y="-40" width="160" height="60" as="geometry"/>
</mxCell>
<mxCell id="4" value="" style="endArrow=classic;html=1;exitX=0.25;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="3" target="10">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="280" y="40" as="sourcePoint"/>
<mxPoint x="110" y="110" as="targetPoint"/>
<Array as="points">
<mxPoint x="105" y="80"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="5" value="Database" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="210" y="220" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="6" value="GitHub_Repository" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="520" y="490" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="7" value="GitHub_Organization" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="520" y="410" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="9" value="&lt;b&gt;GitHub API Models&lt;/b&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;fontColor=#333333;strokeColor=#666666;" vertex="1" parent="1">
<mxGeometry x="480" y="360" width="200" height="30" as="geometry"/>
</mxCell>
<mxCell id="10" value="if (data)&lt;div&gt;- doesn&#39;t exist&lt;/div&gt;&lt;div&gt;OR&lt;/div&gt;&lt;div&gt;- is sufficiently old&lt;/div&gt;" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;" vertex="1" parent="1">
<mxGeometry x="20" y="100" width="170" height="80" as="geometry"/>
</mxCell>
<mxCell id="11" value="" style="endArrow=classic;html=1;entryX=0;entryY=0.5;entryDx=0;entryDy=0;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" edge="1" parent="1" source="10" target="2">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="210" y="230" as="sourcePoint"/>
<mxPoint x="320" y="220" as="targetPoint"/>
<Array as="points">
<mxPoint x="105" y="360"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="12" value="Repository" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="520" y="120" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="13" value="Organization" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="520" y="50" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="14" value="Workflows (?)" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="520" y="190" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="15" value="Actions (?)" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="520" y="260" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="16" value="" style="endArrow=classic;html=1;entryX=0;entryY=0.5;entryDx=0;entryDy=0;exitX=0.75;exitY=1;exitDx=0;exitDy=0;" edge="1" parent="1" source="10" target="5">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="150" y="240" as="sourcePoint"/>
<mxPoint x="310" y="120" as="targetPoint"/>
<Array as="points">
<mxPoint x="148" y="250"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="19" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;fontColor=#333333;strokeColor=#666666;" vertex="1" parent="1">
<mxGeometry x="680" y="10" width="200" height="330" as="geometry"/>
</mxCell>
<mxCell id="21" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;fontColor=#333333;strokeColor=#666666;align=left;" vertex="1" parent="1">
<mxGeometry x="30" y="450" width="250" height="160" as="geometry"/>
</mxCell>
<mxCell id="22" value="&lt;b&gt;Commands&lt;/b&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;fontColor=#333333;strokeColor=#666666;" vertex="1" parent="1">
<mxGeometry x="30" y="420" width="250" height="30" as="geometry"/>
</mxCell>
<mxCell id="27" value="- refresh: delete all data, re-import&lt;div&gt;- import [ organizations | repos | etc. ]&lt;/div&gt;&lt;div&gt;- list [ organizations | repos | etc. ]&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;align=left;spacingLeft=10;" vertex="1" parent="1">
<mxGeometry x="45" y="470" width="225" height="130" as="geometry"/>
</mxCell>
<mxCell id="28" value="These models are used to display data to the user, and provide a resoning model for storing the data.&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Data is pulled from the GitHub API, and transformed into this model structure.&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;align=left;spacingLeft=10;" vertex="1" parent="1">
<mxGeometry x="690" y="20" width="180" height="310" as="geometry"/>
</mxCell>
<mxCell id="29" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;fontColor=#333333;strokeColor=#666666;" vertex="1" parent="1">
<mxGeometry x="680" y="360" width="200" height="300" as="geometry"/>
</mxCell>
<mxCell id="30" value="GitHub API models are only used to have a structured way to reason about data directly from the GitHub API." style="rounded=0;whiteSpace=wrap;html=1;align=left;spacingLeft=10;" vertex="1" parent="1">
<mxGeometry x="690" y="370" width="180" height="280" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
Binary file removed src/github_cli/__pycache__/__init__.cpython-313.pyc
Binary file not shown.
Binary file removed src/github_cli/__pycache__/__main__.cpython-313.pyc
Binary file not shown.
Binary file not shown.
Binary file removed src/github_cli/__pycache__/main.cpython-313.pyc
Binary file not shown.
Binary file removed src/github_cli/__pycache__/repos.cpython-313.pyc
Binary file not shown.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/github_cli/actions/refresh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


def handle_refresh():
"""Handle refresh database"""
print("to be implemented - refresh actions go here")
28 changes: 13 additions & 15 deletions src/github_cli/repos.py → src/github_cli/actions/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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...')
Binary file not shown.
72 changes: 54 additions & 18 deletions src/github_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()
Binary file not shown.
Loading