diff --git a/pyproject.toml b/pyproject.toml index 06ceb56..7e00e16 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,12 +44,14 @@ path = "src/ghlabel/__about__.py" [tool.ruff] select = [ - "E", # Pyflakes - "F", # Pycodestyle "A", # flake8-builtins "B", # flake8-bugbear "S", # flake8-bandit - "I" # isort + "E", # Pyflakes + "F", # Pycodestyle + "I", # Isort + "PL", # Pylint + "RUF", # Ruff-specific rules ] ignore = ["E501"] diff --git a/src/ghlabel/cli.py b/src/ghlabel/cli.py index 9ac2129..2df6883 100644 --- a/src/ghlabel/cli.py +++ b/src/ghlabel/cli.py @@ -71,7 +71,7 @@ class RemoveAllChoices(str, Enum): @app.command("setup", help="Add/Remove Github labels from config files.") # type: ignore[misc] -def setup_labels( +def setup_labels( # noqa: PLR0913 token: Annotated[ Optional[str], typer.Argument( diff --git a/src/ghlabel/utils/dump_label.py b/src/ghlabel/utils/dump_label.py index 75e84ea..eb207c0 100644 --- a/src/ghlabel/utils/dump_label.py +++ b/src/ghlabel/utils/dump_label.py @@ -219,7 +219,8 @@ class Labels: @dataclass(frozen=True) class GameDevLabels(Labels): - AFFECTS: tuple[dict[str, str], ...] = Labels.AFFECTS + ( + AFFECTS: tuple[dict[str, str], ...] = ( + *Labels.AFFECTS, { "name": "Affects: Game Assets", "color": "#fbbc9d", diff --git a/src/ghlabel/utils/setup_github_label.py b/src/ghlabel/utils/setup_github_label.py index c0b3123..960198f 100644 --- a/src/ghlabel/utils/setup_github_label.py +++ b/src/ghlabel/utils/setup_github_label.py @@ -23,7 +23,7 @@ import requests import yaml from dotenv import load_dotenv -from requests.exceptions import Timeout +from requests.exceptions import HTTPError, Timeout from requests.models import Response load_dotenv() @@ -142,15 +142,15 @@ def _fetch_github_labels(self, github_config: GithubConfig) -> list[dict[str, st params=params, timeout=10, ) + res.raise_for_status() except Timeout: logging.error( "The site can't be reached, `github.com` took to long to respond. Try checking the connection." ) sys.exit() - - if res.status_code != 200: + except HTTPError: logging.error( - f"Status {res.status_code}. Failed to fetch list of github labels. Check if token has permission to access `{github_config.REPO_OWNER}/{github_config.REPO_NAME}`." + f"Failed to fetch list of github labels. Check if token has permission to access `{github_config.REPO_OWNER}/{github_config.REPO_NAME}`." ) sys.exit() @@ -293,15 +293,15 @@ def _update_label(self, label: dict[str, str]) -> None: json=label, timeout=10, ) + res.raise_for_status() except Timeout: logging.error( "The site can't be reached, `github.com` took to long to respond. Try checking the connection." ) sys.exit() - - if res.status_code != 200: + except HTTPError: logging.error( - f"Status {res.status_code}. Failed to update label `{label['new_name']}`." + f"Failed to update label `{label['new_name']}`. Check the label format." ) else: logging.info(f"Label `{label['new_name']}` updated successfully.") @@ -346,16 +346,14 @@ def remove_labels( headers=self.headers, timeout=10, ) + res.raise_for_status() except Timeout: logging.error( "The site can't be reached, `github.com` took to long to respond. Try checking the connection." ) sys.exit() - - if res.status_code != 204: - logging.error( - f"Status {res.status_code}. Failed to delete label `{remove_label}`." - ) + except HTTPError: + logging.error(f"Failed to delete label `{remove_label}`.") else: logging.info(f"Label `{remove_label}` deleted successfully.") @@ -397,15 +395,15 @@ def add_labels(self, labels: list[dict[str, str]] | None = None) -> None: json=label, timeout=10, ) + res.raise_for_status() except Timeout: logging.error( "The site can't be reached, `github.com` took to long to respond. Try checking the connection." ) sys.exit() - - if res.status_code != 201: + except HTTPError: logging.error( - f"Status {res.status_code}. Failed to add label `{label['name']}`." + f"Failed to add label `{label['name']}`. Check the label format." ) else: logging.info(f"Label `{label['name']}` added successfully.")