Skip to content

Commit 0fe3754

Browse files
committed
pushing back up to get started again
1 parent a0eaee2 commit 0fe3754

9 files changed

Lines changed: 168 additions & 24 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/postgres-data
2+
/pgadmin-data
3+
14
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
25
__pycache__/
36

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
A better way to manage your GitHub.
44

5+
## Tech Stack
6+
7+
- Python CLI
8+
- Postgres
9+
510
## Useful Tools for this repo
611

712
- Draw.io Integration (VSCode extension)

docker-compose.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: "3.9"
2+
3+
services:
4+
postgres:
5+
image: postgres:16-alpine
6+
container_name: github-inventory-postgres
7+
ports:
8+
- "5432:5432"
9+
environment:
10+
POSTGRES_USER: meddlin
11+
POSTGRES_PASSWORD: jailbreak
12+
POSTGRES_DB: github_inventory
13+
volumes:
14+
- ./postgres-data:/var/lib/postgresql/data # persistent data stored locally
15+
healthcheck:
16+
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-meddlin} -d ${POSTGRES_DB:-github_inventory}"]
17+
interval: 10s
18+
timeout: 5s
19+
retries: 5
20+
restart: unless-stopped
21+
pgadmin:
22+
image: dpage/pgadmin4
23+
container_name: github-inventory-pgadmin
24+
restart: always
25+
ports:
26+
- "8080:80"
27+
environment:
28+
PGADMIN_DEFAULT_EMAIL: drushing.dev@gmail.com
29+
PGADMIN_DEFAULT_PASSWORD: jailbreak
30+
volumes:
31+
- ./pgadmin-data:/var/lib/pgadmin

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ Pygments==2.19.2
77
python-dotenv==1.1.1
88
requests==2.32.4
99
rich==14.0.0
10+
termcolor==3.2.0
1011
typing_extensions==4.14.1
1112
urllib3==2.5.0
13+
yaspin==3.3.0

src/github_cli/actions/refresh.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
1+
from github_cli.actions.repos import handle_repo_import
12

3+
from yaspin import yaspin
4+
from yaspin.spinners import Spinners
25

3-
def handle_refresh():
6+
from github_cli.utilities import file_utils
7+
8+
def handle_refresh(is_tty: bool = True):
49
"""Handle refresh database"""
5-
print("to be implemented - refresh actions go here")
10+
print('Refreshing...')
11+
12+
# if nuclear option
13+
# issue: docker-compose down
14+
# remove ./postgres-data directory
15+
# remove ./pgadmin-data directory
16+
# restart docker-compose up -d
17+
18+
# Basic refresh
19+
# drop database
20+
#
21+
22+
__tmp_dir__ = "./tmp"
23+
__db_path__ = "./inventory.db"
24+
25+
# Configure spinner based on TTY detection
26+
if is_tty:
27+
spinner_config = {"color": "green"}
28+
else:
29+
# No color configuration to avoid warnings
30+
spinner_config = {}
31+
32+
with yaspin(**spinner_config) as sp:
33+
sp.spinner = Spinners.arc
34+
35+
# print("Deleting cve.db...")
36+
# file_utils.remove_file(__db_path__)
37+
38+
# print("Deleting temp dir: /tmp ...")
39+
# file_utils.clean_directory(dir_to_be_deleted=__tmp_dir__)
40+
41+
print("Ingesting GitHub data...")
42+
handle_repo_import()

src/github_cli/actions/repos.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def user_repos_report(username: str):
9191
# Render table
9292
console.print(table)
9393

94-
def handle_repos(username: str):
94+
def handle_list_repos(username: str):
9595
repo_data = __request_repos_for_user(username=username)
9696
for repo in repo_data:
9797
gh_repo = GitHubRepository(
@@ -102,3 +102,18 @@ def handle_repos(username: str):
102102
)
103103
print(gh_repo.url)
104104
print('all repos processed...')
105+
106+
def handle_repo_import(username: str = "meddlin"):
107+
"""Handle repo import"""
108+
109+
repo_data = __request_repos_for_user(username=username)
110+
for repo in repo_data:
111+
gh_repo = GitHubRepository(
112+
id=repo['id'],
113+
name=repo['name'],
114+
node_id=repo['node_id'],
115+
url=repo['url'],
116+
language=repo['language']
117+
)
118+
print(gh_repo.name)
119+
# insert_repo(gh_repo)

src/github_cli/main.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,7 @@ def main():
6464
refresh_actions.handle_refresh()
6565
elif args.command == "list":
6666
if args.repos:
67-
repo_actions.handle_repos(username="meddlin")
68-
# repo_data = repos.__request_repos_for_user(username="meddlin")
69-
# print(repo_data)
70-
71-
# parser.add_argument('--repl', action = argparse.BooleanOptionalAction, help = "Start REPL-mode")
72-
73-
# subparsers = parser.add_subparsers(dest = 'service', required = True)
74-
# gh_parser = subparsers.add_parser('github', help = 'GitHub related commands')
75-
# gh_subparser = gh_parser.add_subparsers(dest = 'command')
76-
77-
# repo_parser = gh_subparser.add_parser('repo', help = 'GitHub repo commands')
78-
# repo_parser.add_argument('--name', type = str, help = 'Name of repository')
79-
# repo_parser.add_argument('--owner', type = str, help = 'Owner of repository')
80-
# repo_parser.add_argument('--report', type = str, help = 'Type of report to execute')
81-
# repo_parser.add_argument('--user', type = str, help = 'GitHub username')
82-
# repo_parser.add_argument('--csv', action = argparse.BooleanOptionalAction)
83-
# repo_parser.set_defaults(func = repos.handle_args)
84-
85-
# args = parser.parse_args()
86-
# if hasattr(args, 'func'):
87-
# args.func(args)
67+
repo_actions.handle_list_repos(username="meddlin")
8868

8969
if __name__ == "__main__":
9070
main()

src/github_cli/storage/db.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
3+
DB_DSN = "postgresql://meddlin:jailbreak@localhost:5432/github_inventory" # update me
4+
5+
SCHEMA_STATEMENTS = [
6+
"""
7+
-- Enable one extension for UUID generation (pick one):
8+
CREATE EXTENSION IF NOT EXISTS pgcrypto; -- then use gen_random_uuid()
9+
-- or
10+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; -- then use uuid_generate_v4()
11+
12+
CREATE TABLE IF NOT EXISTS repositories (
13+
_id UUID PRIMARY KEY DEFAULT uuid_generate_v4()
14+
_created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
15+
16+
id integer NULL,
17+
name TEXT NOT NULL,
18+
full_name TEXT,
19+
name TEXT NULL,
20+
private boolean NULL,
21+
owner TEXT NULL,
22+
html_url TEXT NULL,
23+
description TEXT NULL,
24+
fork boolean NULL,
25+
url text,
26+
);
27+
""",
28+
]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import shutil
3+
4+
def remove_file(file_name_for_delete: str) -> None:
5+
"""Remove the specified file.
6+
7+
Args:
8+
file_name_for_delete (str): Path to file to be deleted.
9+
10+
Raises:
11+
ValueError: If an empty string is passed in.
12+
"""
13+
14+
# Check if the file name is a string and not empty
15+
if not isinstance(file_name_for_delete, str) or not file_name_for_delete:
16+
raise ValueError("File name must be a non-empty string")
17+
18+
try:
19+
# Check if the path exists and is a regular file
20+
if os.path.exists(file_name_for_delete) and os.path.isfile(file_name_for_delete):
21+
os.remove(file_name_for_delete)
22+
else:
23+
print(f"The specified path {file_name_for_delete} does not exist or is not a file.")
24+
except PermissionError:
25+
print(f"You do not have permission to delete the file {file_name_for_delete}.")
26+
except OSError as e:
27+
print(f"Error deleting file {file_name_for_delete}: {e}")
28+
29+
def clean_directory(dir_to_be_deleted: str) -> None:
30+
"""Delete the directory and all of its contents.
31+
32+
Args:
33+
dir_to_be_deleted (str): Points to path to be deleted.
34+
"""
35+
# Check if dir_to_be_deleted is None or not a string.
36+
if isinstance(dir_to_be_deleted, str) and dir_to_be_deleted:
37+
38+
try:
39+
# Check if the directory exists before attempting to delete it
40+
if os.path.exists(dir_to_be_deleted) and os.path.isdir(dir_to_be_deleted):
41+
shutil.rmtree(dir_to_be_deleted)
42+
except OSError as e:
43+
print(f"Error deleting directory {dir_to_be_deleted}: {e}")

0 commit comments

Comments
 (0)