diff --git a/dist/index.js b/dist/index.js index e116bf8..013b559 100644 --- a/dist/index.js +++ b/dist/index.js @@ -852,25 +852,29 @@ module.exports = /******/ (function (modules, runtime) { /***/ 197: /***/ function (module) { // TODO: can't this be done within the GraphQL query itself? + // This is really fugly as a result... function formatVulnerabilityAlerts(data) { - console.log('data', data) - // const { - // repository: { - // vulnerabilityAlerts: { edges }, - // }, - // } = data - - // return edges.map(edge => { - // const advisory = edge.node.securityAdvisory - // const { vulnerabilities, ...rest } = advisory - // const firstVulnerabilityNode = vulnerabilities.edges[0].node - // const vulnerableVersionRange = firstVulnerabilityNode.vulnerableVersionRange - - // return { - // ...rest, - // versionRange: vulnerableVersionRange, - // } - // }) + const { repository } = data + + if (!repository) return console.log('No repository found') + + const { vulnerabilityAlerts } = repository + + if (!vulnerabilityAlerts) return console.log('No vulnerability alerts found') + + const { edges } = vulnerabilityAlerts + + return edges.map(edge => { + const advisory = edge.node.securityAdvisory + const { vulnerabilities, ...rest } = advisory + const firstVulnerabilityNode = vulnerabilities.edges[0].node + const vulnerableVersionRange = firstVulnerabilityNode.vulnerableVersionRange + + return { + ...rest, + versionRange: vulnerableVersionRange, + } + }) } module.exports = { @@ -3022,6 +3026,8 @@ module.exports = /******/ (function (modules, runtime) { const { data } = await getSecurityVulnerabilities() const vulnerabilityAlerts = formatVulnerabilityAlerts(data) + if (!vulnerabilityAlerts) return console.log('No security vulnerabilities found.') + if (vulnerabilityAlerts.length > 0) { const introMsg = getIntroMsg(vulnerabilityAlerts.length) diff --git a/src/helpers.js b/src/helpers.js index 7e17e72..36dd68a 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -1,23 +1,27 @@ // TODO: can't this be done within the GraphQL query itself? +// This is really fugly as a result... function formatVulnerabilityAlerts(data) { - console.log('data', data) - // const { - // repository: { - // vulnerabilityAlerts: { edges }, - // }, - // } = data + const { repository } = data - // return edges.map(edge => { - // const advisory = edge.node.securityAdvisory - // const { vulnerabilities, ...rest } = advisory - // const firstVulnerabilityNode = vulnerabilities.edges[0].node - // const vulnerableVersionRange = firstVulnerabilityNode.vulnerableVersionRange + if (!repository) return console.log('No repository found') - // return { - // ...rest, - // versionRange: vulnerableVersionRange, - // } - // }) + const { vulnerabilityAlerts } = repository + + if (!vulnerabilityAlerts) return console.log('No vulnerability alerts found') + + const { edges } = vulnerabilityAlerts + + return edges.map(edge => { + const advisory = edge.node.securityAdvisory + const { vulnerabilities, ...rest } = advisory + const firstVulnerabilityNode = vulnerabilities.edges[0].node + const vulnerableVersionRange = firstVulnerabilityNode.vulnerableVersionRange + + return { + ...rest, + versionRange: vulnerableVersionRange, + } + }) } module.exports = { diff --git a/src/index.js b/src/index.js index 017f18f..52ec800 100644 --- a/src/index.js +++ b/src/index.js @@ -13,6 +13,8 @@ async function start() { const { data } = await getSecurityVulnerabilities() const vulnerabilityAlerts = formatVulnerabilityAlerts(data) + if (!vulnerabilityAlerts) return console.log('No security vulnerabilities found.') + if (vulnerabilityAlerts.length > 0) { const introMsg = getIntroMsg(vulnerabilityAlerts.length)