Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate a csv report #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions csv-report.js
Original file line number Diff line number Diff line change
@@ -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);
});
8 changes: 7 additions & 1 deletion github.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ class GitHubClient {
edges {
node {
... on Repository {
isArchived
name
nameWithOwner
primaryLanguage {
name
}
}
}
}
Expand Down Expand Up @@ -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 };
});
}

Expand Down