Skip to content

Commit

Permalink
feat: add more ruff rules and add HTTPError request exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
seyLu committed Oct 23, 2023
1 parent 284c8bb commit f1e8e40
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion src/ghlabel/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/ghlabel/utils/dump_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 13 additions & 15 deletions src/ghlabel/utils/setup_github_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")

Expand Down Expand Up @@ -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.")
Expand Down

0 comments on commit f1e8e40

Please sign in to comment.