Skip to content

Commit

Permalink
Merge pull request #2534 from snyk/fix/iac_sarif_output
Browse files Browse the repository at this point in the history
fix: IaC SARIF output
  • Loading branch information
YairZ101 committed Jan 10, 2022
2 parents 6bb68b3 + b2656d9 commit c5d0e5d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/lib/formatters/iac-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function createSarifOutputForIac(
const basePath = isLocalFolder(iacTestResponses[0].path)
? pathLib.resolve('.', iacTestResponses[0].path)
: pathLib.resolve('.');
const repoRoot = getRepoRoot();
const repoRoot = getRepoRoot(basePath);
const issues = iacTestResponses.reduce((collect: ResponseIssues, res) => {
if (res.result) {
// targetFile is the computed relative path of the scanned file
Expand Down Expand Up @@ -294,13 +294,17 @@ export function mapIacTestResponseToSarifResults(
});
}

function getRepoRoot() {
const cwd = process.cwd();
const stdout = execSync('git rev-parse --show-toplevel', {
encoding: 'utf8',
cwd,
});
return stdout.trim() + '/';
function getRepoRoot(basePath: string) {
try {
const cwd = process.cwd();
const stdout = execSync('git rev-parse --show-toplevel', {
encoding: 'utf8',
cwd,
});
return stdout.trim() + '/';
} catch {
return basePath;
}
}

function getPathRelativeToRepoRoot(
Expand Down

0 comments on commit c5d0e5d

Please sign in to comment.