diff --git a/csv-report.js b/csv-report.js new file mode 100644 index 0000000..4ba615f --- /dev/null +++ b/csv-report.js @@ -0,0 +1,34 @@ +const GithubClient = require("./github"); +const _ = require("lodash"); +const Promise = require("bluebird"); + +const token = process.env.GITHUB_TOKEN; +const searchQuery = process.env.GITHUB_QUERY; + +const githubClient = new GithubClient(token); + +async function doTheThing() { + + const repos = await githubClient.getRepos(searchQuery); + + await Promise.map(repos, async ({ name, org, language, archived }) => { + const repoName = `${org}/${name}`; + const link = `https://github.com/${org}/${name}`; + const hasAlertsEnabled = await githubClient.hasAlertsEnabled(org, name); + let hasCritical = ''; + if (hasAlertsEnabled) { + const alerts = await githubClient.getVulnerabilities(org, name); + const criticalAlerts = _.filter(alerts, { + severity: "critical", + dismissed: false, + }); + hasCritical = criticalAlerts.length > 0 ? 'Yes' : 'No'; + } + console.log(`${repoName},${link},${language},${hasAlertsEnabled ? 'Yes' : 'No'},${archived ? 'Yes' : 'No'},${hasCritical}`); + }); +} + +return doTheThing().catch((err) => { + console.log(`It failed :( - ${err.message})`); + process.exit(-1); +}); diff --git a/github.js b/github.js index 0fe99e7..04d27d9 100644 --- a/github.js +++ b/github.js @@ -22,8 +22,12 @@ class GitHubClient { edges { node { ... on Repository { + isArchived name nameWithOwner + primaryLanguage { + name + } } } } @@ -68,7 +72,9 @@ class GitHubClient { const repos = _.map(results.search.edges, 'node'); return _.map(repos, (repo) => { const [org, name] = repo.nameWithOwner.split('/'); - return { org, name }; + const language = _.get(repo, 'primaryLanguage.name', ''); + const archived = repo.isArchived; + return { org, name, language, archived }; }); }