Skip to content

Commit

Permalink
made code prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
salemxd committed Mar 12, 2024
1 parent 778f97c commit 5c61b28
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function run(): Promise<void> {

await PentestService.getStateOfPentest(cydigConfig.pentest);
await ThreatModelingService.getStateOfThreatModeling(cydigConfig.threatModeling);

await AzureDevOpsBoardService.getStateOfAzureDevOpsBoards(cydigConfig);
} catch (error) {
// Fail the workflow run if an error occurs
Expand Down
114 changes: 54 additions & 60 deletions src/scatools/DependabotService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,62 @@ import * as github from '@actions/github';
import { Octokit } from '@octokit/rest';

export class DependabotService {
public static async setDependabotFindings(): Promise<void> {
try{
const { owner, repo }: { owner: string; repo: string } = github.context.repo;
const token: string = core.getInput('PAT-token');
public static async setDependabotFindings(): Promise<void> {
try {
const { owner, repo }: { owner: string; repo: string } = github.context.repo;
const token: string = core.getInput('PAT-token');

const octokit = new Octokit({
auth: token
});
const octokit = new Octokit({
auth: token,
});

// https://www.npmjs.com/package/octokit#pagination
const iterator = octokit.paginate.iterator(
octokit.dependabot.listAlertsForRepo,
{
owner: owner,
repo: repo,
per_page: 100,
state: "open"
}
)

let scaNumberOfSeverity1: number = 0
let scaNumberOfSeverity2: number = 0
let scaNumberOfSeverity3: number = 0
let scaNumberOfSeverity4: number = 0

for await (const {data: alerts } of iterator) {
for(const alert of alerts) {
switch (alert.security_vulnerability.severity){
case "low":
scaNumberOfSeverity1 ++
break
case "medium":
scaNumberOfSeverity2 ++
break
case "high":
scaNumberOfSeverity3 ++
break
case "critical":
scaNumberOfSeverity4 ++
break
}
}
}

console.log("scaNumberOfSeverityLow: " + scaNumberOfSeverity1);
console.log("scaNumberOfSeverityMedium: " + scaNumberOfSeverity2);
console.log("scaNumberOfSeverityHigh: " + scaNumberOfSeverity3);
console.log("scaNumberOfSeverityCritical: " + scaNumberOfSeverity4);

// https://www.npmjs.com/package/octokit#pagination
const iterator = octokit.paginate.iterator(octokit.dependabot.listAlertsForRepo, {
owner: owner,
repo: repo,
per_page: 100,
state: 'open',
});

core.exportVariable('scaNumberOfSeverity1', scaNumberOfSeverity1);
core.exportVariable('scaNumberOfSeverity2', scaNumberOfSeverity2);
core.exportVariable('scaNumberOfSeverity3', scaNumberOfSeverity3);
core.exportVariable('scaNumberOfSeverity4', scaNumberOfSeverity4);
}
catch(error){
core.warning("Could not set Dependabot severities")
core.exportVariable('scaNumberOfSeverity1', 0);
core.exportVariable('scaNumberOfSeverity2', 0);
core.exportVariable('scaNumberOfSeverity3', 0);
core.exportVariable('scaNumberOfSeverity4', 0);
let scaNumberOfSeverity1: number = 0;
let scaNumberOfSeverity2: number = 0;
let scaNumberOfSeverity3: number = 0;
let scaNumberOfSeverity4: number = 0;

for await (const { data: alerts } of iterator) {
for (const alert of alerts) {
switch (alert.security_vulnerability.severity) {
case 'low':
scaNumberOfSeverity1++;
break;
case 'medium':
scaNumberOfSeverity2++;
break;
case 'high':
scaNumberOfSeverity3++;
break;
case 'critical':
scaNumberOfSeverity4++;
break;
}
}

}

console.log('scaNumberOfSeverityLow: ' + scaNumberOfSeverity1);
console.log('scaNumberOfSeverityMedium: ' + scaNumberOfSeverity2);
console.log('scaNumberOfSeverityHigh: ' + scaNumberOfSeverity3);
console.log('scaNumberOfSeverityCritical: ' + scaNumberOfSeverity4);

core.exportVariable('scaNumberOfSeverity1', scaNumberOfSeverity1);
core.exportVariable('scaNumberOfSeverity2', scaNumberOfSeverity2);
core.exportVariable('scaNumberOfSeverity3', scaNumberOfSeverity3);
core.exportVariable('scaNumberOfSeverity4', scaNumberOfSeverity4);
} catch (error) {
core.warning('Could not set Dependabot severities');
core.exportVariable('scaNumberOfSeverity1', 0);
core.exportVariable('scaNumberOfSeverity2', 0);
core.exportVariable('scaNumberOfSeverity3', 0);
core.exportVariable('scaNumberOfSeverity4', 0);
}
}
}
}
14 changes: 7 additions & 7 deletions src/scatools/ScaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import { DependabotService } from './DependabotService';
export class ScaService {
public static async getStateOfScaTool(scaTool: { nameOfTool: string }): Promise<void> {
console.log('\n Running SCA control');
let sca = scaTool.nameOfTool
let sca = scaTool.nameOfTool;
if (process.env.scaTool) {
sca = process.env.scaTool
sca = process.env.scaTool;
}
console.log(`SCA Tool: ${sca}`);
core.exportVariable('scaTool', sca);
if (!sca || sca === "" || sca === 'name-of-tool') {
core.warning('SCA Tool is not set!');

if (!sca || sca === '' || sca === 'name-of-tool') {
core.warning('SCA Tool is not set!');
return;
}

if(sca.toLowerCase() === "dependabot"){
DependabotService.setDependabotFindings()
if (sca.toLowerCase() === 'dependabot') {
DependabotService.setDependabotFindings();
}
}
}
6 changes: 3 additions & 3 deletions src/types/CyDigConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export type CyDigConfig = {
};
scaTool: {
nameOfTool: string;
},
};
sastTool: {
nameOfTool: string;
},
};
codeQualityTool: {
nameOfTool: string;
}
};
};

0 comments on commit 5c61b28

Please sign in to comment.