Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/psrt_ghsa_bot/_sentry_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def init_sentry() -> None:
)


def capture_checkin(monitor_slug, status, duration=None, check_in_id=None):
def capture_checkin(monitor_slug, status, duration=None, check_in_id=None) -> None | str:
"""Capture a Sentry cron check-in."""
if not os.environ.get("SENTRY_DSN"):
return None
Expand All @@ -40,3 +40,10 @@ def capture_checkin(monitor_slug, status, duration=None, check_in_id=None):
)
except ImportError, AttributeError:
return None


def capture_exception() -> None:
"""Capture an exception if Sentry is active."""
if not os.environ.get("SENTRY_DSN"):
return
sentry_sdk.capture_exception()
21 changes: 14 additions & 7 deletions src/psrt_ghsa_bot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
STATUS_IN_PROGRESS,
STATUS_OK,
capture_checkin,
capture_exception,
init_sentry,
)

Expand Down Expand Up @@ -89,7 +90,9 @@ def get_repository_advisories(
# 404 means no advisories or no access - that's okay
if e.response.status_code == 404:
return
raise
# Capture the original exception in Sentry (private)
# and emit a sanitized public exception.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        # and emit a sanitized public exception.

I think you forgot that bit ;-)

capture_exception()


def github_client_request(client: typing.Any, method: str, url: str, params: dict[str, str | int]) -> typing.Any:
Expand Down Expand Up @@ -161,9 +164,11 @@ def apply_to_repo(github: GitHub, owner: str, repo: str, cve_api: CveApi) -> Non
repo=repo,
ghsa_id=ghsa_id,
)
except RequestFailed as e:
print(f" ⚠️ Error creating private fork: {e.response.json()}")
raise e
except RequestFailed:
# Capture the original exception in Sentry (private)
# and emit a sanitized public exception.
capture_exception()
raise RuntimeError("Request to create a private fork failed") from None

# Advisories that are in the 'draft' state without a CVE ID
# should have one allocated by the PSF CVE Numbering Authority.
Expand All @@ -187,9 +192,11 @@ def apply_to_repo(github: GitHub, owner: str, repo: str, cve_api: CveApi) -> Non
ghsa_id=ghsa_id,
data=patch_data,
)
except RequestFailed as e:
print(f" ⚠️ Error updating advisory: {e.response.json()}")
raise e
except RequestFailed:
# Capture the original exception in Sentry (private)
# and emit a sanitized public exception.
capture_exception()
raise RuntimeError("Request to update advisory failed") from None
print(" 💾 Updated advisory")
else:
print(" ⏭️ No updates needed")
Expand Down