Skip to content

Commit 4810b5e

Browse files
authored
Merge pull request #181 from GeekMasher/depbot-enabled
Update how isEnabled works for Dependabot
2 parents 3fe7c1f + a176a29 commit 4810b5e

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ 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-
return True
31+
return (
32+
data.get("data", {})
33+
.get("repository", {})
34+
.get("hasVulnerabilityAlertsEnabled", False)
35+
)
3236
except:
3337
logger.debug(f"Failed to get alert count")
3438
return False

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)