From 59077170ee294cac839e01d6c250647951c152e2 Mon Sep 17 00:00:00 2001 From: Darrien Rushing Date: Tue, 15 Jul 2025 19:00:13 -0500 Subject: [PATCH 1/2] setup entry point, dependencies - basic CLI flags work - can pull back list of repos - requirements for future development --- .gitignore | 7 ++++++ .vscode/launch.json | 23 +++++++++++++++++++ github/repos.py | 54 +++++++++++++++++++++++++++++++++++++++++++++ main.py | 46 +++++++++++++++++++++++++++++++++++++- requirements.txt | 11 +++++++++ 5 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json create mode 100644 github/repos.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 8f322f0..ac9a5ed 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,11 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. +*/bin +*/include +*/lib +*pyvenv.cfg + + # dependencies /node_modules /.pnp @@ -33,3 +39,4 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts +.env diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..18e3cdb --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,23 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python Debugger: Current File with Arguments", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "args": "${command:pickArgs}" + }, + { + "name": "Python Debugger: Current File", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/github/repos.py b/github/repos.py new file mode 100644 index 0000000..1f616d5 --- /dev/null +++ b/github/repos.py @@ -0,0 +1,54 @@ +import os +import logging +from typing import Dict, List, Any +import requests + +def __request_repos_for_user(username: str) -> List[Any]: + """Get repos for a GitHub user + GitHub docs: https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repositories-for-a-user + + Args: + username (str): _description_ + """ + token = os.environ.get('GITHUB_TOKEN') + headers = { + 'Authorization': f'token {token}', + 'X-GitHub-Api-Version': '2022-11-28', + 'Accept': 'application/vnd.github+json' + } + timeout = 10 + + params: Dict[str, int] = { 'per_page': 100, 'page': 1 } + repos: List[Any] = [] + try: + continue_paging = True + while continue_paging: + r = requests.get(f'https://api.github.com/users/{username}/repos', + headers = headers, + params = params, + timeout = timeout + ) + result = r.json() + if len(result) == 0: + continue_paging = False + else: + params['page'] = params['page'] + 1 + repos.extend(result) + except Exception as e: + logging.error(f"--- ERROR --- {e}") + print(f"--- ERROR --- {e}") + + return repos + +def user_repos_report(username: str): + """Handle reporting GitHub repos for user + """ + + repos = __request_repos_for_user(username) + print(repos) + +def handle_args(args): + print(f"IN github/repos.py args: {args}") + + if args.report == 'list': + user_repos_report(args.user) \ No newline at end of file diff --git a/main.py b/main.py index 9e54086..35675b9 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,51 @@ +import argparse +import textwrap +import github.repos as gh_repos +from dotenv import load_dotenv + +def start_repl(): + print("Welcome to the REPL") + + while True: + try: + user_input = input(">> ").strip().lower() + if user_input in ('exit', 'quit'): + print('Exiting!...') + break + + args_list = user_input.split() + print(args_list) + except KeyboardInterrupt: + print('Exiting \n') + break def main(): + """Main - entry point, and sets up CLI args handling + """ 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") + + 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('--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 = gh_repos.handle_args) + + args = parser.parse_args() + if hasattr(args, 'func'): + args.func(args) if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1706c66 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,11 @@ +certifi==2025.7.14 +charset-normalizer==3.4.2 +idna==3.10 +markdown-it-py==3.0.0 +mdurl==0.1.2 +Pygments==2.19.2 +python-dotenv==1.1.1 +requests==2.32.4 +rich==14.0.0 +typing_extensions==4.14.1 +urllib3==2.5.0 From e82a4d27c3e6a5681f2fbb98c3c4e61054b0a312 Mon Sep 17 00:00:00 2001 From: Darrien Rushing Date: Tue, 15 Jul 2025 19:01:26 -0500 Subject: [PATCH 2/2] Disabling Jest --- .github/workflows/jest-coverage.yml | 38 +++++++++--------- .github/workflows/jest.yml | 60 ++++++++++++++--------------- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/.github/workflows/jest-coverage.yml b/.github/workflows/jest-coverage.yml index 55bfc12..9f29fd3 100755 --- a/.github/workflows/jest-coverage.yml +++ b/.github/workflows/jest-coverage.yml @@ -1,19 +1,19 @@ -name: 'coverage' -on: - pull_request: - branches: - - master - - main -jobs: - coverage: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: ArtiomTr/jest-coverage-report-action@v2 - id: coverage - with: - output: report-markdown - - uses: peter-evans/create-or-update-comment@v3 - with: - issue-number: ${{ github.event.pull_request.number }} - body: ${{ steps.coverage.outputs.report }} \ No newline at end of file +# name: 'coverage' +# on: +# pull_request: +# branches: +# - master +# - main +# jobs: +# coverage: +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v3 +# - uses: ArtiomTr/jest-coverage-report-action@v2 +# id: coverage +# with: +# output: report-markdown +# - uses: peter-evans/create-or-update-comment@v3 +# with: +# issue-number: ${{ github.event.pull_request.number }} +# body: ${{ steps.coverage.outputs.report }} \ No newline at end of file diff --git a/.github/workflows/jest.yml b/.github/workflows/jest.yml index 07c5b47..a16eead 100755 --- a/.github/workflows/jest.yml +++ b/.github/workflows/jest.yml @@ -1,32 +1,32 @@ -name: Jest -on: push -jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: "16" +# name: Jest +# on: push +# jobs: +# test: +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v3 +# - name: Setup Node.js +# uses: actions/setup-node@v3 +# with: +# node-version: "16" - # Speed up subsequent runs with caching - - name: Cache node modules - uses: actions/cache@v3 - env: - cache-name: cache-node-modules - with: - # npm cache files are stored in `~/.npm` on Linux/macOS - path: ~/.npm - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - # Install required deps for action - - name: Install Dependencies - run: npm install +# # Speed up subsequent runs with caching +# - name: Cache node modules +# uses: actions/cache@v3 +# env: +# cache-name: cache-node-modules +# with: +# # npm cache files are stored in `~/.npm` on Linux/macOS +# path: ~/.npm +# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} +# restore-keys: | +# ${{ runner.os }}-build-${{ env.cache-name }}- +# ${{ runner.os }}-build- +# ${{ runner.os }}- +# # Install required deps for action +# - name: Install Dependencies +# run: npm install - # Finally, run our tests - - name: Run the tests - run: npm test \ No newline at end of file +# # Finally, run our tests +# - name: Run the tests +# run: npm test \ No newline at end of file