Skip to content

Commit 31a525c

Browse files
committed
feat(depbot): Update how isEnabled works for Dependabot
- Use hasVulnerabilityAlertsEnabled from API - Update GraphQL query - Update examples
1 parent 3fe7c1f commit 31a525c

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

examples/dependabot.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
os.environ.get("GITHUB_REPOSITORY", "GeekMasher/ghastoolkit"),
77
)
88

9-
depgraph = Dependabot()
9+
dependabot = Dependabot()
1010

11-
alerts = depgraph.getAlerts()
11+
if not dependabot.isEnabled():
12+
print("Dependabot is not enabled")
13+
exit(1)
14+
15+
alerts = dependabot.getAlerts()
1216
print(f"Total Alerts :: {len(alerts)}")
1317

1418
for alert in alerts:

src/ghastoolkit/octokit/dependabot.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ def __init__(self, repository: Optional[Repository] = None) -> None:
2424
def isEnabled(self) -> bool:
2525
"""Is Dependabot enabled."""
2626
try:
27-
self.graphql.query(
27+
data = self.graphql.query(
2828
"GetDependencyStatus",
2929
options={"owner": self.repository.owner, "repo": self.repository.repo},
3030
)
31+
if not data.get("hasVulnerabilityAlertsEnabled", False):
32+
return False
3133
return True
3234
except:
3335
logger.debug(f"Failed to get alert count")

src/ghastoolkit/octokit/graphql/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
DEPENDENCY_GRAPH_STATUS = """\
22
{
33
repository(owner: "$owner", name: "$repo") {
4-
vulnerabilityAlerts(first: 100, states: [OPEN], $cursor) {
5-
totalCount
6-
}
4+
hasVulnerabilityAlertsEnabled
75
}
86
}
97
"""

0 commit comments

Comments
 (0)