Skip to content

Commit 63b0053

Browse files
[dev] [tofikwest] tofik/fix-dependabot-check-status (#2205)
* fix(github): improve dependabot status check and handling * fix(github): update dependabot status handling to include paused state --------- Co-authored-by: Tofik Hasanov <annexcies@gmail.com>
1 parent 5e6a5ca commit 63b0053

1 file changed

Lines changed: 57 additions & 11 deletions

File tree

  • packages/integration-platform/src/manifests/github/checks

packages/integration-platform/src/manifests/github/checks/dependabot.ts

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,41 @@ export const dependabotCheck: IntegrationCheck = {
173173
};
174174

175175
for (const repo of repos) {
176-
const dependabotStatus = repo.security_and_analysis?.dependabot_security_updates?.status;
176+
// Use the dedicated endpoint to check Dependabot security updates status.
177+
// The security_and_analysis field on the repo object does not include
178+
// dependabot_security_updates — the correct endpoint is /automated-security-fixes.
179+
// status: 'enabled' | 'paused' | 'disabled' | 'unknown'
180+
let dependabotStatus: 'enabled' | 'paused' | 'disabled' | 'unknown' = 'unknown';
181+
try {
182+
const securityFixes = await ctx.fetch<{ enabled: boolean; paused: boolean }>(
183+
`/repos/${repo.full_name}/automated-security-fixes`,
184+
);
185+
if (securityFixes.enabled && securityFixes.paused) {
186+
dependabotStatus = 'paused';
187+
} else if (securityFixes.enabled) {
188+
dependabotStatus = 'enabled';
189+
} else {
190+
dependabotStatus = 'disabled';
191+
}
192+
} catch (error) {
193+
const errorStr = String(error);
194+
if (errorStr.includes('404')) {
195+
// 404 means Dependabot security updates are not enabled for this repo
196+
dependabotStatus = 'disabled';
197+
} else {
198+
// 403 or other errors mean we couldn't determine the status
199+
ctx.log(
200+
`Could not check Dependabot status for ${repo.full_name} (may lack admin access)`,
201+
);
202+
}
203+
}
177204

178205
// Fetch alert counts regardless of Dependabot status
179206
const alertCounts = await fetchAlertCounts(repo.full_name);
180207

181208
// Build hierarchical evidence: { "owner/repo": { data } }
182209
const repoEvidence: Record<string, unknown> = {
183-
security_and_analysis: repo.security_and_analysis,
210+
dependabot_security_updates: { status: dependabotStatus },
184211
...(alertCounts && {
185212
alerts: {
186213
open: alertCounts.open,
@@ -193,11 +220,11 @@ export const dependabotCheck: IntegrationCheck = {
193220
checked_at: new Date().toISOString(),
194221
};
195222

196-
if (dependabotStatus === 'enabled') {
197-
const alertSummary = alertCounts
198-
? `\n\nAlert Summary: ${formatAlertSummary(alertCounts)}`
199-
: '';
223+
const alertSummary = alertCounts
224+
? `\n\nAlert Summary: ${formatAlertSummary(alertCounts)}`
225+
: '';
200226

227+
if (dependabotStatus === 'enabled') {
201228
ctx.pass({
202229
title: `Dependabot enabled on ${repo.name}`,
203230
description: `Dependabot security updates are enabled and will automatically create pull requests to fix vulnerable dependencies.${alertSummary}`,
@@ -207,11 +234,17 @@ export const dependabotCheck: IntegrationCheck = {
207234
[repo.full_name]: repoEvidence,
208235
},
209236
});
210-
} else {
211-
const alertSummary = alertCounts
212-
? `\n\nAlert Summary: ${formatAlertSummary(alertCounts)}`
213-
: '';
214-
237+
} else if (dependabotStatus === 'paused') {
238+
ctx.pass({
239+
title: `Dependabot enabled on ${repo.name} (paused)`,
240+
description: `Dependabot security updates are enabled but currently paused due to inactivity. Dependabot will resume automatically when new alerts are detected.${alertSummary}`,
241+
resourceType: 'repository',
242+
resourceId: repo.full_name,
243+
evidence: {
244+
[repo.full_name]: repoEvidence,
245+
},
246+
});
247+
} else if (dependabotStatus === 'disabled') {
215248
ctx.fail({
216249
title: `Dependabot not enabled on ${repo.name}`,
217250
description: `Dependabot security updates are not enabled, leaving the repository vulnerable to known dependency exploits.${alertSummary}`,
@@ -223,6 +256,19 @@ export const dependabotCheck: IntegrationCheck = {
223256
[repo.full_name]: repoEvidence,
224257
},
225258
});
259+
} else {
260+
// Could not determine status (e.g., insufficient permissions)
261+
ctx.fail({
262+
title: `Unable to check Dependabot status on ${repo.name}`,
263+
description: `Could not determine whether Dependabot security updates are enabled. The GitHub integration may lack admin access to this repository.${alertSummary}`,
264+
resourceType: 'repository',
265+
resourceId: repo.full_name,
266+
severity: 'medium',
267+
remediation: `1. Ensure the GitHub integration has admin access to ${repo.full_name}\n2. Or manually verify at ${repo.html_url}/settings/security_analysis`,
268+
evidence: {
269+
[repo.full_name]: repoEvidence,
270+
},
271+
});
226272
}
227273
}
228274
},

0 commit comments

Comments
 (0)