From 55ebf3dba6f80e5e5b672a3256aa16babee79ef1 Mon Sep 17 00:00:00 2001 From: Douglas Date: Mon, 10 Nov 2025 22:57:52 -0800 Subject: [PATCH] Fix comment issues with regression introduced in 2.2.15 (#129) --- pyproject.toml | 2 +- socketsecurity/__init__.py | 2 +- socketsecurity/core/scm/gitlab.py | 22 +++++++++++++--------- uv.lock | 14 +++++++++----- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c1ab9cc..ec50d9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "socketsecurity" -version = "2.2.26" +version = "2.2.27" requires-python = ">= 3.10" license = {"file" = "LICENSE"} dependencies = [ diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index ee41f27..e29a9cc 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,3 +1,3 @@ __author__ = 'socket.dev' -__version__ = '2.2.26' +__version__ = '2.2.27' USER_AGENT = f'SocketPythonCLI/{__version__}' diff --git a/socketsecurity/core/scm/gitlab.py b/socketsecurity/core/scm/gitlab.py index c8aba49..70abf50 100644 --- a/socketsecurity/core/scm/gitlab.py +++ b/socketsecurity/core/scm/gitlab.py @@ -1,8 +1,9 @@ import os import sys from dataclasses import dataclass -from typing import Optional +from typing import Optional, Union +import requests from socketsecurity import USER_AGENT from socketsecurity.core import log from socketsecurity.core.classes import Comment @@ -128,9 +129,9 @@ def _request_with_fallback(self, **kwargs): try: # Try the initial request with the configured headers return self.client.request(**kwargs) - except Exception as e: + except requests.exceptions.HTTPError as e: # Check if this is an authentication error (401) - if hasattr(e, 'response') and e.response and e.response.status_code == 401: + if e.response and e.response.status_code == 401: log.debug(f"Authentication failed with initial headers, trying fallback method") # Determine the fallback headers @@ -144,6 +145,9 @@ def _request_with_fallback(self, **kwargs): # Re-raise the original exception if it's not an auth error or fallback failed raise + except Exception as e: + # Handle other types of exceptions that don't have response attribute + raise def _get_fallback_headers(self, original_headers: dict) -> dict: """ @@ -235,13 +239,13 @@ def add_socket_comments( new_security_comment: bool = True, new_overview_comment: bool = True ) -> None: - existing_overview_comment = comments.get("overview", "") - existing_security_comment = comments.get("security", "") + existing_overview_comment = comments.get("overview") + existing_security_comment = comments.get("security") if new_overview_comment: log.debug("New Dependency Overview comment") if existing_overview_comment is not None: log.debug("Previous version of Dependency Overview, updating") - existing_overview_comment: Comment + # Type narrowing: after None check, mypy knows this is Comment self.update_comment(overview_comment, str(existing_overview_comment.id)) else: log.debug("No previous version of Dependency Overview, posting") @@ -250,15 +254,15 @@ def add_socket_comments( log.debug("New Security Issue Comment") if existing_security_comment is not None: log.debug("Previous version of Security Issue comment, updating") - existing_security_comment: Comment + # Type narrowing: after None check, mypy knows this is Comment self.update_comment(security_comment, str(existing_security_comment.id)) else: log.debug("No Previous version of Security Issue comment, posting") self.post_comment(security_comment) def remove_comment_alerts(self, comments: dict): - security_alert = comments.get("security", "") + security_alert = comments.get("security") if security_alert is not None: - security_alert: Comment + # Type narrowing: after None check, mypy knows this is Comment new_body = Comments.process_security_comment(security_alert, comments) self.update_comment(new_body, str(security_alert.id)) diff --git a/uv.lock b/uv.lock index 0dac6d3..205aec0 100644 --- a/uv.lock +++ b/uv.lock @@ -1052,26 +1052,28 @@ wheels = [ [[package]] name = "socketdev" -version = "3.0.16" +version = "3.0.17" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "requests" }, { name = "typing-extensions" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/02/0d/6da0e0c34b97eef3a926d55470fa4bda2fcbbc42cc9e26ac51a34c6f117d/socketdev-3.0.16.tar.gz", hash = "sha256:5145300945e4e8d2d7f71db9c55cb44cc1449874f9d6416cc1d6ec129c64d638", size = 132505, upload-time = "2025-11-07T03:24:16.231Z" } +sdist = { url = "https://files.pythonhosted.org/packages/47/60/54b56ac179a9c89b2c9f2ab7eb5ba81220de64d11d52cf19249113ff364d/socketdev-3.0.17.tar.gz", hash = "sha256:a4446a84856c637c312d809d5b8deb25dd20ca38ae7d00a4c8104ea5b890c0af", size = 134013, upload-time = "2025-11-07T22:38:34.354Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/a3/91/8486b2a62ba71d62a8f4f2f9ad22c61fcaabb461c5f269bbe0734eae76f9/socketdev-3.0.16-py3-none-any.whl", hash = "sha256:f5e413f5f2f8c0c938d5654da7f0a157c0be02a25e14d94af62c252e9fb3b502", size = 58567, upload-time = "2025-11-07T03:24:14.965Z" }, + { url = "https://files.pythonhosted.org/packages/98/56/34ab0e33b5345ca7ada68cd0a9e9d4adcde16051192eb10f8e2c3e0deaa1/socketdev-3.0.17-py3-none-any.whl", hash = "sha256:0986ee0694d5ce879cadb8e06fcfb75a4ca2dfb6f415414593825701593cf991", size = 59317, upload-time = "2025-11-07T22:38:32.704Z" }, ] [[package]] name = "socketsecurity" -version = "2.2.18" +version = "2.2.26" source = { editable = "." } dependencies = [ { name = "bs4" }, { name = "gitpython" }, + { name = "hatch" }, { name = "mdutils" }, { name = "packaging" }, + { name = "pluggy" }, { name = "prettytable" }, { name = "python-dotenv" }, { name = "requests" }, @@ -1098,9 +1100,11 @@ test = [ requires-dist = [ { name = "bs4", specifier = ">=0.0.2" }, { name = "gitpython" }, + { name = "hatch", specifier = ">=1.14.1" }, { name = "hatch", marker = "extra == 'dev'" }, { name = "mdutils" }, { name = "packaging" }, + { name = "pluggy", specifier = ">=1.6.0" }, { name = "pre-commit", marker = "extra == 'dev'" }, { name = "prettytable" }, { name = "pytest", marker = "extra == 'test'", specifier = ">=7.4.0" }, @@ -1111,7 +1115,7 @@ requires-dist = [ { name = "python-dotenv" }, { name = "requests" }, { name = "ruff", marker = "extra == 'dev'", specifier = ">=0.3.0" }, - { name = "socketdev", specifier = ">=3.0.16,<4.0.0" }, + { name = "socketdev", specifier = ">=3.0.17,<4.0.0" }, { name = "twine", marker = "extra == 'dev'" }, { name = "uv", marker = "extra == 'dev'", specifier = ">=0.1.0" }, ]