Skip to content

Commit

Permalink
Stop requiring a config.json, and set up command line parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
jyasskin committed Oct 17, 2023
1 parent 79b01ab commit 953fc02
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
9 changes: 5 additions & 4 deletions scanner/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Bottleneck from "bottleneck";
import specs from 'browser-specs' assert { type: "json" };
import fs from 'node:fs/promises';
import { mean, quantile } from 'simple-statistics';
import config from './third_party/config.cjs';
import octokit from './third_party/octokit-cache.js';

const ghLimiter = new Bottleneck({
Expand Down Expand Up @@ -63,7 +64,7 @@ function ageStats(arr: number[]): AgeStats | undefined {
async function analyzeRepo(org: string, repo: string, globalStats: GlobalStatsInput): Promise<RepoSummary> {
let result: RepoSummary | null = null;
try {
result = JSON.parse(await fs.readFile(`summaries/${org}/${repo}.json`, { encoding: 'utf8' }),
result = JSON.parse(await fs.readFile(`${config.outDir}/${org}/${repo}.json`, { encoding: 'utf8' }),
(key, value) => {
if (['created_at', 'closed_at'].includes(key)) {
return new Date(value);
Expand Down Expand Up @@ -116,8 +117,8 @@ async function analyzeRepo(org: string, repo: string, globalStats: GlobalStatsIn
globalStats.closeAgesMs.push(...closeAgesMs);
globalStats.openAgesMs.push(...openAgesMs);

await fs.mkdir(`summaries/${org}`, { recursive: true });
await fs.writeFile(`summaries/${org}/${repo}.json`, JSON.stringify(result, undefined, 2));
await fs.mkdir(`${config.outDir}/${org}`, { recursive: true });
await fs.writeFile(`${config.outDir}/${org}/${repo}.json`, JSON.stringify(result, undefined, 2));

return result;
}
Expand Down Expand Up @@ -148,7 +149,7 @@ async function main() {
const globalStats: GlobalStatsInput = { openAgesMs: [], closeAgesMs: [] };
await Promise.all(githubRepos.map(({ org, repo }) => analyzeRepo(org, repo, globalStats)));

await fs.writeFile("summaries/global.json", JSON.stringify({
await fs.writeFile(`${config.outDir}/global.json`, JSON.stringify({
ageAtCloseMs: ageStats(globalStats.closeAgesMs),
openAgeMs: ageStats(globalStats.openAgesMs),
}, undefined, 2));
Expand Down
1 change: 1 addition & 0 deletions scanner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@octokit/plugin-throttling": "^8.0.0",
"bottleneck": "^2.19.5",
"browser-specs": "^3.62.0",
"commander": "^11.1.0",
"node-fetch": "^3.3.2",
"simple-statistics": "^7.8.3"
},
Expand Down
8 changes: 8 additions & 0 deletions scanner/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions scanner/third_party/config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
"use strict";

const path = require('path');
const config = require("../config.json");
const { program } = require('commander');

const config = {};

program
.option('--gh-token <token>', undefined, process.env["GITHUB_TOKEN"] || "missing-GitHub-token")
.option('--out-dir <directory>', "where to write scan results", "summaries");

const options = program.opts();

// environment variables

Expand All @@ -20,11 +27,12 @@ config.debug = (config.env === "development") || config.debug || false;

// auth tokens and keys

config.ghToken = config.ghToken || "missing-GitHub-token";
config.ghToken = options.ghToken;

// app specifics

config.cache = config.cache || "https://labs.w3.org/github-cache";
config.outDir = options.outDir;

// dump the configuration into the server log (but not in the server monitor!)
console.log("".padStart(80, '-'));
Expand Down

0 comments on commit 953fc02

Please sign in to comment.