Skip to content

Commit

Permalink
feat: Add Dependabot Alerts PR API
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekMasher committed Aug 15, 2024
1 parent d4e5795 commit 076145d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/ghastoolkit/octokit/dependabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,34 @@ def getAlerts(
docs="https://docs.github.com/en/rest/dependabot/alerts",
)

def getAlertsInPR(self) -> list[DependencyAlert]:
"""Get All Dependabot alerts from REST API in Pull Request."""
logger.debug("Dependabot Alerts from Pull Request using DependencyGraph API")

from ghastoolkit import DependencyGraph

depgraph = DependencyGraph(repository=self.repository)

pr_info = self.repository.getPullRequestInfo()
pr_base = pr_info.get("base", {}).get("ref", "")
pr_head = pr_info.get("head", {}).get("ref", "")

if pr_base == "" or pr_head == "":
raise GHASToolkitError(
"Failed to get base and head branch of pull request",
permissions=[
'"Contents" repository permissions (read)',
'"Pull requests" permissions (read)',
],
docs="https://docs.github.com/en/rest/reference/repos#get-a-repository",
)

dependencies = depgraph.getDependenciesInPR(pr_base, pr_head)
alerts = []
for dep in dependencies:
alerts.extend(dep.alerts)
return alerts

def getAlertsGraphQL(self) -> list[DependencyAlert]:
"""Get All Dependabot alerts from GraphQL API using the `GetDependencyAlerts` query."""
results = []
Expand Down

0 comments on commit 076145d

Please sign in to comment.