Skip to content

Commit

Permalink
Set environment variable and handle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hampus-andersson-op committed Mar 22, 2024
1 parent b212b7c commit 2601ea7
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/secretscanning/SecretScanningService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class SecretScanningService {
typeof octokit.secretScanning.listAlertsForRepo
>;

// https://www.npmjs.com/package/octokit#pagination
const iterator: AsyncIterableIterator<OctokitResponse<SecretAlertsForRepoResponseDataType>> =
octokit.paginate.iterator(octokit.secretScanning.listAlertsForRepo, {
owner: owner,
Expand All @@ -31,6 +32,19 @@ export class SecretScanningService {
for await (const { data: alerts } of iterator) {
numberOfExposedSecrets += alerts.length;
}
} catch (error) {}

console.log('Number of exposed secrets:', numberOfExposedSecrets);

core.exportVariable('numberOfExposedSecrets', numberOfExposedSecrets);
} catch (error) {
console.log('Error status:', error.status);
console.log(error);
if (error.status === 404) {
core.warning('Secret scanning is disabled or repository is public');
} else {
core.warning('Error getting number of exposed secrets');
}
core.exportVariable('numberOfExposedSecrets', 0);
}
}
}

0 comments on commit 2601ea7

Please sign in to comment.