Skip to content

Commit

Permalink
Add alert URLs to output
Browse files Browse the repository at this point in the history
  • Loading branch information
seanh committed Oct 29, 2023
1 parent 16778a8 commit 2bcd311
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/dependabot_alerts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def cli(argv=None):
)
for alert in alerts:
print(
f"- <{alert.repo_html_url}/security/dependabot/|{alert.repo_full_name}>, `{alert.ghsa_id}` ({len(alert.duplicates) + 1}) alerts): `{alert.package}` {alert.summary}"
f"- <{alert.html_url}|{alert.repo_full_name} {alert.ghsa_id}>, ({len(alert.duplicates) + 1} alerts): `{alert.package}` {alert.summary}"
)
print(
"\nMessage generated by the `alerts.yml` workflow <https://github.com/hypothesis/dependabot-alerts/blob/main/.github/workflows/alert.yml|in dependabot-alerts>"
)
elif alerts:
for alert in alerts:
print(
f"{alert.repo_full_name}, {alert.ghsa_id} ({len(alert.duplicates) + 1} alerts): {alert.package} {alert.summary}"
f"{alert.repo_full_name}, {alert.ghsa_id} ({len(alert.duplicates) + 1} alerts): {alert.package} {alert.summary} {alert.html_url}"
)
4 changes: 2 additions & 2 deletions src/dependabot_alerts/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
@dataclass(frozen=True)
class Alert:
repo_full_name: str | None
repo_html_url: str | None = field(compare=False, repr=False)
ghsa_id: str | None
html_url: str | None = field(compare=False)
package: str | None = field(compare=False)
manifest_path: str | None = field(compare=False)
summary: str | None = field(compare=False)
Expand All @@ -19,8 +19,8 @@ class Alert:
def make(cls, alert_dict):
return cls(
repo_full_name=alert_dict["repository"]["full_name"],
repo_html_url=alert_dict["repository"]["html_url"],
ghsa_id=alert_dict["security_advisory"]["ghsa_id"],
html_url=alert_dict["html_url"],
package=alert_dict["dependency"]["package"]["name"],
manifest_path=alert_dict["dependency"]["manifest_path"],
summary=alert_dict["security_advisory"]["summary"],
Expand Down
9 changes: 4 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class Meta:
organization = factory.Sequence(lambda n: f"organization-{n}")
repo = factory.Sequence(lambda n: f"repo-{n}")
repo_full_name = factory.LazyAttribute(lambda o: f"{o.organization}/{o.repo}")
repo_html_url = factory.LazyAttribute(
lambda o: f"https://github.com/hypothesis/{o.organization}/{o.repo}"
)
ghsa_id = factory.Sequence(lambda n: f"GHSA-{n}")
html_url = factory.LazyAttributeSequence(
lambda o, n: f"https://github.com/{o.organization}/{o.repo}/security/dependabot/{n}"
)
package = factory.Sequence(lambda n: f"package-{n}")
manifest_path = factory.Sequence(lambda n: f"manifest_path-{n}")
summary = factory.Sequence(lambda n: f"summary-{n}")
Expand All @@ -37,15 +37,14 @@ def post(obj, *_args, **_kwargs): # pylint:disable=no-self-argument
"""Transform the generated dict into the format returned by the GitHub API."""
# pylint:disable=no-member
repo_full_name = obj.pop("repo_full_name")
repo_html_url = obj.pop("repo_html_url")
ghsa_id = obj.pop("ghsa_id")
package = obj.pop("package")
manifest_path = obj.pop("manifest_path")
summary = obj.pop("summary")
del obj["duplicates"]

# Serialise a dict in the format returned by the GitHub API.
obj["repository"] = {"full_name": repo_full_name, "html_url": repo_html_url}
obj["repository"] = {"full_name": repo_full_name}
obj["dependency"] = {
"package": {
"name": package,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/dependabot_alerts/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_it(GitHub, github, subprocess, capsys):
assert captured.out == "\n".join(
[
*[
f"{alert.repo_full_name}, {alert.ghsa_id} ({len(alert.duplicates) + 1} alerts): {alert.package} {alert.summary}"
f"{alert.repo_full_name}, {alert.ghsa_id} ({len(alert.duplicates) + 1} alerts): {alert.package} {alert.summary} {alert.html_url}"
for alert in github.alerts.return_value
],
"",
Expand Down

0 comments on commit 2bcd311

Please sign in to comment.