Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync DependabotAlert class with API spec #3120

Merged
Merged
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
7 changes: 7 additions & 0 deletions github/DependabotAlert.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class DependabotAlert(NonCompletableGithubObject):
"""

def _initAttributes(self) -> None:
self._auto_dismissed_at: Attribute[datetime] = NotSet
self._created_at: Attribute[datetime] = NotSet
self._dependency: Attribute[DependabotAlertDependency] = NotSet
self._dismissed_at: Attribute[datetime | None] = NotSet
Expand All @@ -72,6 +73,10 @@ def _initAttributes(self) -> None:
def __repr__(self) -> str:
return self.get__repr__({"number": self.number, "ghsa_id": self.security_advisory.ghsa_id})

@property
def auto_dismissed_at(self) -> datetime:
return self._auto_dismissed_at.value

@property
def created_at(self) -> datetime:
return self._created_at.value
Expand Down Expand Up @@ -129,6 +134,8 @@ def url(self) -> str:
return self._url.value

def _useAttributes(self, attributes: dict[str, Any]) -> None:
if "auto_dismissed_at" in attributes: # pragma no branch
self._auto_dismissed_at = self._makeDatetimeAttribute(attributes["auto_dismissed_at"])
if "created_at" in attributes:
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "dependency" in attributes:
Expand Down
21 changes: 14 additions & 7 deletions tests/DependabotAlert.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# #
################################################################################

from __future__ import annotations

from datetime import datetime, timezone

import pytest
Expand All @@ -40,7 +42,18 @@ def setUp(self):

def testAttributes(self):
alert = self.repo.get_dependabot_alert(1)
self.assertIsNone(alert.auto_dismissed_at)
self.assertEqual(alert.created_at, datetime(2024, 1, 20, 17, 12, 38, tzinfo=timezone.utc))
self.assertEqual(alert.dependency.package.name, "jinja2")
self.assertEqual(alert.dismissed_at, datetime(2024, 1, 21, 3, 35, 38, tzinfo=timezone.utc))
self.assertEqual(alert.dismissed_by.login, "coopernetes")
self.assertEqual(alert.dismissed_reason, "tolerable_risk")
self.assertEqual(alert.dismissed_comment, "Example comment")
self.assertIsNone(alert.fixed_at)
self.assertEqual(alert.html_url, "https://github.com/coopernetes/PyGithub/security/dependabot/1")
self.assertEqual(alert.number, 1)
self.assertEqual(alert.security_advisory.ghsa_id, "GHSA-h5c8-rqwp-cp95")
self.assertEqual(alert.security_vulnerability.package.name, "jinja2")
self.assertEqual(alert.state, "dismissed")
self.assertEqual(alert.dependency.package.ecosystem, "pip")
self.assertEqual(alert.dependency.package.name, "jinja2")
Expand Down Expand Up @@ -91,15 +104,9 @@ def testAttributes(self):
self.assertEqual(alert.security_vulnerability.vulnerable_version_range, "< 3.1.3")
self.assertEqual(alert.security_vulnerability.severity, "medium")
self.assertEqual(alert.security_vulnerability.first_patched_version["identifier"], "3.1.3")
self.assertEqual(alert.updated_at, datetime(2024, 1, 21, 3, 35, 38, tzinfo=timezone.utc))
self.assertEqual(alert.url, "https://api.github.com/repos/coopernetes/PyGithub/dependabot/alerts/1")
self.assertEqual(alert.html_url, "https://github.com/coopernetes/PyGithub/security/dependabot/1")
self.assertEqual(alert.created_at, datetime(2024, 1, 20, 17, 12, 38, tzinfo=timezone.utc))
self.assertEqual(alert.updated_at, datetime(2024, 1, 21, 3, 35, 38, tzinfo=timezone.utc))
self.assertEqual(alert.dismissed_at, datetime(2024, 1, 21, 3, 35, 38, tzinfo=timezone.utc))
self.assertEqual(alert.dismissed_by.login, "coopernetes")
self.assertEqual(alert.dismissed_reason, "tolerable_risk")
self.assertEqual(alert.dismissed_comment, "Example comment")
self.assertEqual(alert.fixed_at, None)

def testMultipleAlerts(self):
multiple_alerts = self.repo.get_dependabot_alerts()
Expand Down
Loading