Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
salemxd committed Mar 12, 2024
1 parent df86ab3 commit 79f53f4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
45 changes: 38 additions & 7 deletions src/scatools/DependabotService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ export class DependabotService {

const { owner, repo }: { owner: string; repo: string } = github.context.repo;
const token: string = core.getInput('PAT-token');

const octokit: InstanceType<typeof GitHub> = github.getOctokit(token);
type dependabotAlertType = Endpoints['GET /repos/{owner}/{repo}/dependabot/alerts']['response'];

const alerts: any = await octokit.paginate(
"GET /repos/{owner}/{repo}/dependabot/alerts",
{
Expand Down Expand Up @@ -41,14 +40,46 @@ export class DependabotService {
}
}

console.log('\n scaNumberOfSeverity1: ' + scaNumberOfSeverity1);
console.log('\n scaNumberOfSeverity2: ' + scaNumberOfSeverity2);
console.log('\n scaNumberOfSeverity3: ' + scaNumberOfSeverity3);
console.log('\n scaNumberOfSeverity4: ' + scaNumberOfSeverity4);

core.exportVariable('scaNumberOfSeverity1', scaNumberOfSeverity1);
core.exportVariable('scaNumberOfSeverity2', scaNumberOfSeverity2);
core.exportVariable('scaNumberOfSeverity3', scaNumberOfSeverity3);
core.exportVariable('scaNumberOfSeverity4', scaNumberOfSeverity4);
}

public static async setDependabotFindings2(): Promise<void> {

const { owner, repo }: { owner: string; repo: string } = github.context.repo;
const token: string = core.getInput('PAT-token');

const octokit: InstanceType<typeof GitHub> = github.getOctokit(token);
type dependabotAlertType = Endpoints['GET /repos/{owner}/{repo}/dependabot/alerts']['response'];

const alerts: Array<dependabotAlertType> = await octokit.paginate(
"GET /repos/{owner}/{repo}/dependabot/alerts",
{
owner: owner,
repo: repo,
per_page: 100,
});

const severeties = alerts.flatMap((alert) => DependabotService.GetSeverity(alert));

const lowSeverityCount = DependabotService.severityCountForGivenSeverity(severeties, "low");
const mediumSeverityCount = DependabotService.severityCountForGivenSeverity(severeties, "medium");
const highwSeverityCount = DependabotService.severityCountForGivenSeverity(severeties, "high");
const criticalSeverityCount = DependabotService.severityCountForGivenSeverity(severeties, "critical");

core.exportVariable('scaNumberOfSeverity1', lowSeverityCount);
core.exportVariable('scaNumberOfSeverity2', mediumSeverityCount);
core.exportVariable('scaNumberOfSeverity3', highwSeverityCount);
core.exportVariable('scaNumberOfSeverity4', criticalSeverityCount);
}

private static severityCountForGivenSeverity(severeties: ("low" | "medium" | "high" | "critical")[], severity: string) {
return severeties.filter((allert) => allert === severity).length;
}

private static GetSeverity(alert): "low" | "medium" | "high" | "critical" | readonly ("low" | "medium" | "high" | "critical")[] {
return alert.data.flatMap((data) => data.security_vulnerability.severity);
}
}
3 changes: 0 additions & 3 deletions src/scatools/ScaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ export class ScaService {
return;
}

console.log(`lite test:`);
console.log(`test: ${process.env}`);

if(scaTool.nameOfTool === "dependabot"){
DependabotService.setDependabotFindings()
}
Expand Down

0 comments on commit 79f53f4

Please sign in to comment.