Skip to content

Commit 55ebf3d

Browse files
authored
Fix comment issues with regression introduced in 2.2.15 (#129)
1 parent 2684a9d commit 55ebf3d

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.2.26"
9+
version = "2.2.27"
1010
requires-python = ">= 3.10"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.2.26'
2+
__version__ = '2.2.27'
33
USER_AGENT = f'SocketPythonCLI/{__version__}'

socketsecurity/core/scm/gitlab.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
22
import sys
33
from dataclasses import dataclass
4-
from typing import Optional
4+
from typing import Optional, Union
55

6+
import requests
67
from socketsecurity import USER_AGENT
78
from socketsecurity.core import log
89
from socketsecurity.core.classes import Comment
@@ -128,9 +129,9 @@ def _request_with_fallback(self, **kwargs):
128129
try:
129130
# Try the initial request with the configured headers
130131
return self.client.request(**kwargs)
131-
except Exception as e:
132+
except requests.exceptions.HTTPError as e:
132133
# Check if this is an authentication error (401)
133-
if hasattr(e, 'response') and e.response and e.response.status_code == 401:
134+
if e.response and e.response.status_code == 401:
134135
log.debug(f"Authentication failed with initial headers, trying fallback method")
135136

136137
# Determine the fallback headers
@@ -144,6 +145,9 @@ def _request_with_fallback(self, **kwargs):
144145

145146
# Re-raise the original exception if it's not an auth error or fallback failed
146147
raise
148+
except Exception as e:
149+
# Handle other types of exceptions that don't have response attribute
150+
raise
147151

148152
def _get_fallback_headers(self, original_headers: dict) -> dict:
149153
"""
@@ -235,13 +239,13 @@ def add_socket_comments(
235239
new_security_comment: bool = True,
236240
new_overview_comment: bool = True
237241
) -> None:
238-
existing_overview_comment = comments.get("overview", "")
239-
existing_security_comment = comments.get("security", "")
242+
existing_overview_comment = comments.get("overview")
243+
existing_security_comment = comments.get("security")
240244
if new_overview_comment:
241245
log.debug("New Dependency Overview comment")
242246
if existing_overview_comment is not None:
243247
log.debug("Previous version of Dependency Overview, updating")
244-
existing_overview_comment: Comment
248+
# Type narrowing: after None check, mypy knows this is Comment
245249
self.update_comment(overview_comment, str(existing_overview_comment.id))
246250
else:
247251
log.debug("No previous version of Dependency Overview, posting")
@@ -250,15 +254,15 @@ def add_socket_comments(
250254
log.debug("New Security Issue Comment")
251255
if existing_security_comment is not None:
252256
log.debug("Previous version of Security Issue comment, updating")
253-
existing_security_comment: Comment
257+
# Type narrowing: after None check, mypy knows this is Comment
254258
self.update_comment(security_comment, str(existing_security_comment.id))
255259
else:
256260
log.debug("No Previous version of Security Issue comment, posting")
257261
self.post_comment(security_comment)
258262

259263
def remove_comment_alerts(self, comments: dict):
260-
security_alert = comments.get("security", "")
264+
security_alert = comments.get("security")
261265
if security_alert is not None:
262-
security_alert: Comment
266+
# Type narrowing: after None check, mypy knows this is Comment
263267
new_body = Comments.process_security_comment(security_alert, comments)
264268
self.update_comment(new_body, str(security_alert.id))

uv.lock

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)