From ea9f3fa8d7580516eb43bee19f1c20e2ebb5aa36 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 28 May 2025 12:02:31 +0200 Subject: [PATCH 1/9] feat: add --version argparser command and update to 1.0.1 --- pyproject.toml | 2 +- src/github_rest_cli/__init__.py | 1 - src/github_rest_cli/main.py | 27 ++++++++++++++++++++------- uv.lock | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bb4c369..6edc882 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "github-rest-cli" -version = "1.0.0" +version = "1.0.1" description = "GitHub REST API cli" authors = [ { name = "lbrealdev", email = "lbrealdeveloper@gmail.com" } diff --git a/src/github_rest_cli/__init__.py b/src/github_rest_cli/__init__.py index 3dc1f76..e69de29 100644 --- a/src/github_rest_cli/__init__.py +++ b/src/github_rest_cli/__init__.py @@ -1 +0,0 @@ -__version__ = "0.1.0" diff --git a/src/github_rest_cli/main.py b/src/github_rest_cli/main.py index f9da400..975b4df 100644 --- a/src/github_rest_cli/main.py +++ b/src/github_rest_cli/main.py @@ -8,6 +8,10 @@ dependabot_security, deployment_environment, ) +from importlib.metadata import version + + +__version__ = version("github-rest-cli") def cli(): @@ -15,15 +19,24 @@ def cli(): Create parsers and subparsers for CLI arguments """ global_parser = argparse.ArgumentParser( - description="Python CLI to GitHub REST API", + description="Python CLI for GitHub REST API", + ) + + # Project version + global_parser.add_argument( + "-v", + "--version", + action="version", + version=f"%(prog)s {__version__}" ) + subparsers = global_parser.add_subparsers( - help="Python GitHub REST API commands", dest="command" + help="GitHub REST API commands", dest="command" ) # Subparser for "get-repository" function get_repo_parser = subparsers.add_parser( - "get-repo", help="Get repository information" + "get-repo", help="Get a repository's details" ) get_repo_parser.add_argument( "-n", @@ -39,7 +52,7 @@ def cli(): # Subparser for "list-repository" function list_repo_parser = subparsers.add_parser( "list-repo", - help="List repositories for authenticated user", + help="List your repositories", ) list_repo_parser.add_argument( "-r", @@ -97,7 +110,7 @@ def cli(): # Subparser for "delete-repository" function delete_repo_parser = subparsers.add_parser( "delete-repo", - help="Delete a repository", + help="Delete an existing repository", ) delete_repo_parser.add_argument( "-n", @@ -117,7 +130,7 @@ def cli(): # Subparser for "dependabot" function dependabot_parser = subparsers.add_parser( "dependabot", - help="Github Dependabot security updates", + help="Manage Dependabot settings", ) dependabot_parser.add_argument( "-n", @@ -150,7 +163,7 @@ def cli(): # Subparser for "deployment-environments" function deploy_env_parser = subparsers.add_parser( "environment", - help="Github Deployment environments", + help="Manage deployment environments", ) deploy_env_parser.add_argument( "-n", diff --git a/uv.lock b/uv.lock index 8f5ffae..6eebc94 100644 --- a/uv.lock +++ b/uv.lock @@ -61,7 +61,7 @@ wheels = [ [[package]] name = "github-rest-cli" -version = "0.1.0" +version = "1.0.0" source = { editable = "." } dependencies = [ { name = "dynaconf" }, From 88fc4c58a96b496378b3d01add5791a37bf647c0 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 28 May 2025 12:05:36 +0200 Subject: [PATCH 2/9] style(ruff): fmt --- src/github_rest_cli/main.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/github_rest_cli/main.py b/src/github_rest_cli/main.py index 975b4df..8e2c7a7 100644 --- a/src/github_rest_cli/main.py +++ b/src/github_rest_cli/main.py @@ -24,10 +24,7 @@ def cli(): # Project version global_parser.add_argument( - "-v", - "--version", - action="version", - version=f"%(prog)s {__version__}" + "-v", "--version", action="version", version=f"%(prog)s {__version__}" ) subparsers = global_parser.add_subparsers( From 13a56996b4450fd0bf741afa837c10055f592f06 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 28 May 2025 13:00:51 +0200 Subject: [PATCH 3/9] feat(dynaconf): update validators --- README.md | 2 +- src/github_rest_cli/api.py | 4 +++- src/github_rest_cli/config.py | 13 ------------- src/github_rest_cli/globals.py | 15 +++++++++------ src/github_rest_cli/main.py | 7 +++---- src/github_rest_cli/utils.py | 19 +++++++++++++++++++ 6 files changed, 35 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 2f35182..b59463d 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ export GITHUB_AUTH_TOKEN="" Run cli: ```shell -github-rest-cli -h +github-rest-cli -v ``` ### Dynaconf diff --git a/src/github_rest_cli/api.py b/src/github_rest_cli/api.py index 50a289f..adcb1a6 100644 --- a/src/github_rest_cli/api.py +++ b/src/github_rest_cli/api.py @@ -1,7 +1,9 @@ import requests -from github_rest_cli.globals import GITHUB_URL, HEADERS +from github_rest_cli.globals import GITHUB_URL, get_headers from github_rest_cli.utils import rich_output, rprint +HEADERS = get_headers() + def request_with_handling( method, url, success_msg: str = None, error_msg: str = None, **kwargs diff --git a/src/github_rest_cli/config.py b/src/github_rest_cli/config.py index 6ba58f1..0591405 100644 --- a/src/github_rest_cli/config.py +++ b/src/github_rest_cli/config.py @@ -1,23 +1,10 @@ from dynaconf import Dynaconf, Validator settings = Dynaconf( - # Default environment variables prefix. envvar_prefix="GITHUB", - # Source configuration files. settings_files=["../../settings.toml", "../../.secrets.toml"], environments=["development", "testing", "production"], env_switcher="SET_ENV", - # The script will not work if the variables - # defined in the Validator class are not defined. - validators=[ - Validator( - "AUTH_TOKEN", - must_exist=True, - messages={ - "must_exist_true": "Environment variable GITHUB_AUTH_TOKEN is not set. Please set it and try again." - }, - ), - ], ) # `envvar_prefix` = export envvars with `export DYNACONF_FOO=bar`. diff --git a/src/github_rest_cli/globals.py b/src/github_rest_cli/globals.py index bcda475..92678bf 100644 --- a/src/github_rest_cli/globals.py +++ b/src/github_rest_cli/globals.py @@ -1,10 +1,13 @@ from github_rest_cli.config import settings +from github_rest_cli.utils import validate_github_token GITHUB_URL = "https://api.github.com" -GITHUB_TOKEN = f"{settings.AUTH_TOKEN}" -HEADERS = { - "Accept": "application/vnd.github+json", - "X-GitHub-Api-Version": "2022-11-28", - "Authorization": f"token {GITHUB_TOKEN}", -} + +def get_headers(): + validate_github_token() + return { + "Accept": "application/vnd.github+json", + "X-GitHub-Api-Version": "2022-11-28", + "Authorization": f"token {settings.AUTH_TOKEN}", + } diff --git a/src/github_rest_cli/main.py b/src/github_rest_cli/main.py index 8e2c7a7..2f9a285 100644 --- a/src/github_rest_cli/main.py +++ b/src/github_rest_cli/main.py @@ -18,16 +18,15 @@ def cli(): """ Create parsers and subparsers for CLI arguments """ - global_parser = argparse.ArgumentParser( + parser = argparse.ArgumentParser( description="Python CLI for GitHub REST API", ) - # Project version - global_parser.add_argument( + parser.add_argument( "-v", "--version", action="version", version=f"%(prog)s {__version__}" ) - subparsers = global_parser.add_subparsers( + subparsers = parser.add_subparsers( help="GitHub REST API commands", dest="command" ) diff --git a/src/github_rest_cli/utils.py b/src/github_rest_cli/utils.py index fc23643..2fd063b 100644 --- a/src/github_rest_cli/utils.py +++ b/src/github_rest_cli/utils.py @@ -1,5 +1,24 @@ from rich import print as rprint +from dynaconf import settings +from dynaconf.validator import Validator +from dynaconf.base import ValidationError def rich_output(message: str, format_str: str = "bold green"): rprint(f"[{format_str}]{message}[/{format_str}]") + + +def validate_github_token(): + validator = Validator( + "AUTH_TOKEN", + must_exist=True, + messages={ + "must_exist_true": "Error: Environment variable GITHUB_AUTH_TOKEN is not set. Please set it and try again." + } + ) + + try: + validator.validate(settings) + except ValidationError as e: + print(e) + raise SystemExit(1) From 1a8c72e237483e76712d38d8f0c4a89589af2307 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 28 May 2025 14:04:02 +0200 Subject: [PATCH 4/9] feat: api functions --- src/github_rest_cli/api.py | 30 +++++++++++++--------- src/github_rest_cli/config.py | 13 ++++++++++ src/github_rest_cli/globals.py | 13 +++++++--- src/github_rest_cli/main.py | 46 ++++++++++++++++++---------------- src/github_rest_cli/utils.py | 19 -------------- 5 files changed, 66 insertions(+), 55 deletions(-) diff --git a/src/github_rest_cli/api.py b/src/github_rest_cli/api.py index adcb1a6..f2dbd0a 100644 --- a/src/github_rest_cli/api.py +++ b/src/github_rest_cli/api.py @@ -2,8 +2,6 @@ from github_rest_cli.globals import GITHUB_URL, get_headers from github_rest_cli.utils import rich_output, rprint -HEADERS = get_headers() - def request_with_handling( method, url, success_msg: str = None, error_msg: str = None, **kwargs @@ -42,18 +40,21 @@ def build_url(*segments: str) -> str: return f"{base}/{path}" -def fetch_user(): +def fetch_user() -> str: + headers = get_headers() url = build_url("user") - response = request_with_handling("GET", url, headers=HEADERS) + response = request_with_handling("GET", url, headers=headers) if response: data = response.json() return data.get("login") return None -def get_repository(owner: str, name: str, org: str = None): +def get_repository(name: str, org: str = None): + owner = fetch_user() + headers = get_headers() url = build_url("repos", org or owner, name) - response = request_with_handling("GET", url, headers=HEADERS) + response = request_with_handling("GET", url, headers=headers) if response: data = response.json() rprint(data) @@ -69,12 +70,13 @@ def create_repository(owner: str, name: str, visibility: str, org: str = None): if visibility == "private": data["private"] = True + headers = get_headers() url = build_url("orgs", org, "repos") if org else build_url("user", "repos") return request_with_handling( "POST", url, - headers=HEADERS, + headers=headers, json=data, success_msg=f"Repository successfully created in {owner or org }/{name}", error_msg={ @@ -85,12 +87,13 @@ def create_repository(owner: str, name: str, visibility: str, org: str = None): def delete_repository(owner: str, name: str, org: str = None): + headers = get_headers() url = build_url("repos", org, name) if org else build_url("repos", owner, name) return request_with_handling( "DELETE", url, - headers=HEADERS, + headers=headers, success_msg=f"Repository sucessfully deleted in {owner or org}/{name}", error_msg={ 403: "The authenticated user does not have sufficient permissions to delete this repository.", @@ -100,6 +103,7 @@ def delete_repository(owner: str, name: str, org: str = None): def list_repositories(page: int, property: str, role: str): + headers = get_headers() url = build_url("user", "repos") params = {"per_page": page, "sort": property, "type": role} @@ -108,7 +112,7 @@ def list_repositories(page: int, property: str, role: str): "GET", url, params=params, - headers=HEADERS, + headers=headers, error_msg={401: "Unauthorized access. Please check your token or credentials."}, ) @@ -123,6 +127,7 @@ def list_repositories(page: int, property: str, role: str): def dependabot_security(owner: str, name: str, enabled: bool, org: str = None): is_enabled = bool(enabled) + headers = get_headers() url = build_url("repos", org, name) if org else build_url("repos", owner, name) security_urls = ["vulnerability-alerts", "automated-security-fixes"] @@ -132,7 +137,7 @@ def dependabot_security(owner: str, name: str, enabled: bool, org: str = None): request_with_handling( "PUT", url=full_url, - headers=HEADERS, + headers=headers, success_msg=f"Enabled {endpoint}", error_msg={ 401: "Unauthorized. Please check your credentials.", @@ -143,13 +148,14 @@ def dependabot_security(owner: str, name: str, enabled: bool, org: str = None): request_with_handling( "DELETE", url=full_url, - headers=HEADERS, + headers=headers, success_msg=f"Dependabot has been disabled on repository {owner or org}/{name}.", error_msg={401: "Unauthorized. Please check your credentials."}, ) def deployment_environment(owner: str, name: str, env: str, org: str = None): + headers = get_headers() url = ( build_url("repos", org, name, "environments", env) if org @@ -159,7 +165,7 @@ def deployment_environment(owner: str, name: str, env: str, org: str = None): return request_with_handling( "PUT", url, - headers=HEADERS, + headers=headers, success_msg=f"Environment {env} has been created successfully in {owner or org}/{name}.", error_msg={ 422: f"Failed to create repository enviroment {owner or org}/{name}" diff --git a/src/github_rest_cli/config.py b/src/github_rest_cli/config.py index 0591405..6ba58f1 100644 --- a/src/github_rest_cli/config.py +++ b/src/github_rest_cli/config.py @@ -1,10 +1,23 @@ from dynaconf import Dynaconf, Validator settings = Dynaconf( + # Default environment variables prefix. envvar_prefix="GITHUB", + # Source configuration files. settings_files=["../../settings.toml", "../../.secrets.toml"], environments=["development", "testing", "production"], env_switcher="SET_ENV", + # The script will not work if the variables + # defined in the Validator class are not defined. + validators=[ + Validator( + "AUTH_TOKEN", + must_exist=True, + messages={ + "must_exist_true": "Environment variable GITHUB_AUTH_TOKEN is not set. Please set it and try again." + }, + ), + ], ) # `envvar_prefix` = export envvars with `export DYNACONF_FOO=bar`. diff --git a/src/github_rest_cli/globals.py b/src/github_rest_cli/globals.py index 92678bf..00010d6 100644 --- a/src/github_rest_cli/globals.py +++ b/src/github_rest_cli/globals.py @@ -1,13 +1,20 @@ from github_rest_cli.config import settings -from github_rest_cli.utils import validate_github_token +from rich import print as rprint + GITHUB_URL = "https://api.github.com" def get_headers(): - validate_github_token() + token = settings.get("AUTH_TOKEN") + if not token: + rprint( + "[bold red]Error: Environment variable GITHUB_AUTH_TOKEN is not set. Please set it and try again.[/bold red]" + ) + raise SystemError(1) + return { "Accept": "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28", - "Authorization": f"token {settings.AUTH_TOKEN}", + "Authorization": f"token {token}", } diff --git a/src/github_rest_cli/main.py b/src/github_rest_cli/main.py index 2f9a285..119cdf4 100644 --- a/src/github_rest_cli/main.py +++ b/src/github_rest_cli/main.py @@ -1,6 +1,5 @@ import argparse from github_rest_cli.api import ( - fetch_user, get_repository, create_repository, delete_repository, @@ -26,9 +25,7 @@ def cli(): "-v", "--version", action="version", version=f"%(prog)s {__version__}" ) - subparsers = parser.add_subparsers( - help="GitHub REST API commands", dest="command" - ) + subparsers = parser.add_subparsers(help="GitHub REST API commands", dest="command") # Subparser for "get-repository" function get_repo_parser = subparsers.add_parser( @@ -44,6 +41,7 @@ def cli(): get_repo_parser.add_argument( "-o", "--org", help="The organization name", required=False, dest="org" ) + get_repo_parser.set_defaults(func=get_repository) # Subparser for "list-repository" function list_repo_parser = subparsers.add_parser( @@ -74,6 +72,7 @@ def cli(): dest="sort", help="List repositories sorted by", ) + list_repo_parser.set_defaults(func=list_repositories) # Subparser for "create-repository" function create_repo_parser = subparsers.add_parser( @@ -102,6 +101,7 @@ def cli(): dest="org", help="The organization name", ) + create_repo_parser.set_defaults(func=create_repository) # Subparser for "delete-repository" function delete_repo_parser = subparsers.add_parser( @@ -122,6 +122,7 @@ def cli(): dest="org", help="The organization name", ) + delete_repo_parser.set_defaults(func=delete_repository) # Subparser for "dependabot" function dependabot_parser = subparsers.add_parser( @@ -155,6 +156,7 @@ def cli(): dest="control", help="Disable dependabot security updates", ) + dependabot_parser.set_defaults(func=dependabot_security) # Subparser for "deployment-environments" function deploy_env_parser = subparsers.add_parser( @@ -182,26 +184,28 @@ def cli(): dest="org", help="The organization name", ) + deploy_env_parser.set_defaults(func=deployment_environment) - # guard clause pattern - args = global_parser.parse_args() + args = parser.parse_args() command = args.command - owner = fetch_user() - - if command == "get-repo": - return get_repository(owner, args.name, args.org) - if command == "list-repo": - return list_repositories(args.page, args.sort, args.role) - if command == "create-repo": - return create_repository(owner, args.name, args.visibility, args.org) - if command == "delete-repo": - return delete_repository(owner, args.name, args.org) - if command == "dependabot": - return dependabot_security(owner, args.name, args.control, args.org) - if command == "environment": - return deployment_environment(owner, args.name, args.env, args.org) - return False + if hasattr(args, "func"): + if command == "get-repo": + args.func(args.name, args.org) + elif command == "list-repo": + args.func(args.page, args.sort, args.role) + elif command == "create-repo": + args.func(args.name, args.visibility, args.org) + elif command == "delete-repo": + args.func(args.name, args.org) + elif command == "dependabot": + args.func(args.name, args.control, args.org) + elif command == "environment": + args.func(args.name, args.env, args.org) + else: + return False + else: + parser.print_help() if __name__ == "__main__": diff --git a/src/github_rest_cli/utils.py b/src/github_rest_cli/utils.py index 2fd063b..fc23643 100644 --- a/src/github_rest_cli/utils.py +++ b/src/github_rest_cli/utils.py @@ -1,24 +1,5 @@ from rich import print as rprint -from dynaconf import settings -from dynaconf.validator import Validator -from dynaconf.base import ValidationError def rich_output(message: str, format_str: str = "bold green"): rprint(f"[{format_str}]{message}[/{format_str}]") - - -def validate_github_token(): - validator = Validator( - "AUTH_TOKEN", - must_exist=True, - messages={ - "must_exist_true": "Error: Environment variable GITHUB_AUTH_TOKEN is not set. Please set it and try again." - } - ) - - try: - validator.validate(settings) - except ValidationError as e: - print(e) - raise SystemExit(1) From ce8f526de23da0129c46adc381759ac93b9cf717 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 28 May 2025 14:07:43 +0200 Subject: [PATCH 5/9] feat(actions): add new step activate virtualenv --- .github/workflows/python-ci.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index c4bec3b..436b185 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -41,9 +41,8 @@ jobs: - name: uv sync run: uv sync - - name: Debug CLI - run: | - source .venv/bin/activate - github-rest-cli -h - env: - GITHUB_AUTH_TOKEN: f@k3-t0k3n + - name: Activate virtualenv + run: source .venv/bin/activate + + - name: Get CLI version + run: github-rest-cli --version From b732b899c0de9bb6e426b948ab9e8ae72eeb8dc0 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 28 May 2025 14:09:29 +0200 Subject: [PATCH 6/9] fix(actions): get cli version step --- .github/workflows/python-ci.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 436b185..1848591 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -41,8 +41,7 @@ jobs: - name: uv sync run: uv sync - - name: Activate virtualenv - run: source .venv/bin/activate - - name: Get CLI version - run: github-rest-cli --version + run: | + source .venv/bin/activate + github-rest-cli --version From e615b02fcfe4616a45f186e226b6d53c8d28ecf1 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 28 May 2025 14:44:54 +0200 Subject: [PATCH 7/9] fix(api): get_repository function --- src/github_rest_cli/api.py | 14 ++++++++++++-- uv.lock | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/github_rest_cli/api.py b/src/github_rest_cli/api.py index f2dbd0a..e17515d 100644 --- a/src/github_rest_cli/api.py +++ b/src/github_rest_cli/api.py @@ -54,10 +54,20 @@ def get_repository(name: str, org: str = None): owner = fetch_user() headers = get_headers() url = build_url("repos", org or owner, name) - response = request_with_handling("GET", url, headers=headers) + response = request_with_handling( + "GET", + url, + headers=headers, + error_msg={ + 401: "Unauthorized access. Please check your token or credentials.", + 404: "The requested repository does not exist.", + }, + ) + if response: data = response.json() rprint(data) + return None def create_repository(owner: str, name: str, visibility: str, org: str = None): @@ -97,7 +107,7 @@ def delete_repository(owner: str, name: str, org: str = None): success_msg=f"Repository sucessfully deleted in {owner or org}/{name}", error_msg={ 403: "The authenticated user does not have sufficient permissions to delete this repository.", - 404: "The requested repository was not found.", + 404: "The requested repository does not exist.", }, ) diff --git a/uv.lock b/uv.lock index 6eebc94..cdcd1cf 100644 --- a/uv.lock +++ b/uv.lock @@ -61,7 +61,7 @@ wheels = [ [[package]] name = "github-rest-cli" -version = "1.0.0" +version = "1.0.1" source = { editable = "." } dependencies = [ { name = "dynaconf" }, From 0533978d816e87b1c9c3d50ca90e0a2e81e4e18c Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 28 May 2025 15:08:45 +0200 Subject: [PATCH 8/9] fix(ruff): print T201 --- src/github_rest_cli/config.py | 23 ++++++++++------------- src/github_rest_cli/globals.py | 19 ++++++++++--------- src/github_rest_cli/main.py | 2 ++ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/github_rest_cli/config.py b/src/github_rest_cli/config.py index 6ba58f1..77d0b6d 100644 --- a/src/github_rest_cli/config.py +++ b/src/github_rest_cli/config.py @@ -1,23 +1,20 @@ from dynaconf import Dynaconf, Validator settings = Dynaconf( - # Default environment variables prefix. envvar_prefix="GITHUB", - # Source configuration files. settings_files=["../../settings.toml", "../../.secrets.toml"], environments=["development", "testing", "production"], env_switcher="SET_ENV", - # The script will not work if the variables - # defined in the Validator class are not defined. - validators=[ - Validator( - "AUTH_TOKEN", - must_exist=True, - messages={ - "must_exist_true": "Environment variable GITHUB_AUTH_TOKEN is not set. Please set it and try again." - }, - ), - ], +) + +# The CLI will not work if the variable +# defined in the Validator class are not defined. +AUTH_TOKEN_VALIDATOR = Validator( + "AUTH_TOKEN", + must_exist=True, + messages={ + "must_exist_true": "Environment variable GITHUB_AUTH_TOKEN is not set. Please set it and try again." + }, ) # `envvar_prefix` = export envvars with `export DYNACONF_FOO=bar`. diff --git a/src/github_rest_cli/globals.py b/src/github_rest_cli/globals.py index 00010d6..798ba79 100644 --- a/src/github_rest_cli/globals.py +++ b/src/github_rest_cli/globals.py @@ -1,20 +1,21 @@ -from github_rest_cli.config import settings -from rich import print as rprint +from github_rest_cli.config import settings, AUTH_TOKEN_VALIDATOR +from dynaconf.base import ValidationError +import logging GITHUB_URL = "https://api.github.com" +logger = logging.getLogger(__name__) def get_headers(): - token = settings.get("AUTH_TOKEN") - if not token: - rprint( - "[bold red]Error: Environment variable GITHUB_AUTH_TOKEN is not set. Please set it and try again.[/bold red]" - ) - raise SystemError(1) + try: + AUTH_TOKEN_VALIDATOR.validate(settings) + except ValidationError as e: + logger.error(str(e)) + raise SystemExit(1) return { "Accept": "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28", - "Authorization": f"token {token}", + "Authorization": f"token {settings.AUTH_TOKEN}", } diff --git a/src/github_rest_cli/main.py b/src/github_rest_cli/main.py index 119cdf4..8feea5b 100644 --- a/src/github_rest_cli/main.py +++ b/src/github_rest_cli/main.py @@ -8,9 +8,11 @@ deployment_environment, ) from importlib.metadata import version +import logging __version__ = version("github-rest-cli") +logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") def cli(): From 258d47289fca77ae4f23e23ce5808f0eb5939050 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 28 May 2025 15:12:57 +0200 Subject: [PATCH 9/9] docs: update README.md --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b59463d..5cddf0d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,18 @@ # GitHub REST API -### Usage +## Installation + +Install using `pip`: +```shell +pip install github-rest-cli +``` + +Install using `uv`: +```shell +uv pip install github-rest-cli +``` + +## Usage Set up python package dependencies in `pyproject.toml`: ```shell