forked from adeyosemanputra/pygoat
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2021b59
commit bd5ca12
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @module extractOrcaFindings | ||
* @description Extract security issues information from Orca PR reviews | ||
* @param {Object} pr - the gitStream's PR context variable | ||
* @returns {Object} Findings | ||
* Findings.infrastructure_as_code: { count: null, priority: '' }, | ||
* Findings.vulnerabilities: { count: null, priority: '' }, | ||
* Findings.secrets: { count: null, priority: '' }, | ||
* @example {{ pr | extractOrcaFindings }} | ||
* @license MIT | ||
**/ | ||
|
||
|
||
function getOrcaPropertyRating(lines, lineIdentifierRegex, findingsCellIndex) { | ||
const matches = lines.filter(x => x.match(lineIdentifierRegex)); | ||
const [firstMatch] = matches; | ||
const cells = firstMatch.split('|'); | ||
const [_, high, medium, low, info] = /"High"> ([\d]+).*"Medium"> ([\d]+).*"Low"> ([\d]+).*"Info"> ([\d]+)/ | ||
.exec(cells[findingsCellIndex]) | ||
.map(x => parseInt(x)); | ||
return {high, medium, low, info}; | ||
} | ||
|
||
module.exports = (pr) => { | ||
let orcaObject = { | ||
infrastructure_as_code: { count: null, priority: '' }, | ||
vulnerabilities: { count: null, priority: '' }, | ||
secrets: { count: null, priority: '' }, | ||
}; | ||
|
||
// Orca comments are added as PR review | ||
const orcaComment = pr.reviews.filter(x => x.commenter.includes('orca-security')); | ||
|
||
if (orcaComment.length) { | ||
const orcaCommentArray = orcaComment[orcaComment.length - 1].content.split('\n'); | ||
|
||
var priority = getOrcaPropertyRating(orcaCommentArray, /Infrastructure as Code/, 3); | ||
orcaObject.infrastructure_as_code = { | ||
count: priority.high + priority.medium + priority.low + priority.info, | ||
priority, | ||
}; | ||
|
||
var priority = getOrcaPropertyRating(orcaCommentArray, /Vulnerabilities/, 3); | ||
orcaObject.vulnerabilities = { | ||
count: priority.high + priority.medium + priority.low + priority.info, | ||
priority, | ||
}; | ||
|
||
var priority = getOrcaPropertyRating(orcaCommentArray, /Secrets/, 3); | ||
orcaObject.secrets = { | ||
count: priority.high + priority.medium + priority.low + priority.info, | ||
priority, | ||
}; | ||
} | ||
|
||
return JSON.stringify(orcaObject); | ||
} |