feat(tool): Add ability to view all open PRs for repos other than freeCodeCamp in the Dashboard app (#40453)
* feat: show open boilerplate prs on dashboard fix: rest of boilerplate server changes fix: more fix: other * fix: update lib functions * fix: retrofitted one-off scripts * feat: added rateLimit for requests * fix: reduce time * fix: put limiter inside each route * fix: make client show when rated limited * fix: removed unused probot from app * fix: renamed folders * fix: consolidate config.js and constants.js * chore: update octokit to latest version * fix: remove invalid file * fix: refactored update-db.js * feat: add fcc logo * fix: logo url * fix: remove Home link * fix: change link colors * fix: added rate limiter to landing page * fix: ran npm install in client to create package-lock.json * fix: correct typo in doc Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com> * fix: Replace favicon, Gitter => Discord Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> * fix: add extra linting guidance to package.json * Ignore contributor app Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> * fix: revert linting rules for client * fix: add skip_preflight_check=true for tests Co-authored-by: Kristofer Koishigawa <scissorsneedfoodtoo@gmail.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Kris Koishigawa <scissorsneedfoodtoo@gmail.com> Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>
This commit is contained in:
90
tools/contributor/lib/utils/processing-log.js
Normal file
90
tools/contributor/lib/utils/processing-log.js
Normal file
@ -0,0 +1,90 @@
|
||||
const config = require('../../lib/config');
|
||||
const formatDate = require('date-fns/format');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const { saveToFile } = require('./save-to-file');
|
||||
|
||||
class ProcessingLog {
|
||||
constructor(script) {
|
||||
this._script = script;
|
||||
this._startTime = null;
|
||||
this._finishTime = null;
|
||||
this._elapsedTime = null;
|
||||
this._prs = [];
|
||||
this._prCount = null;
|
||||
this._logfile = path.resolve(
|
||||
__dirname,
|
||||
`../../work-logs/data-for_${this.getRunType()}_${this._script}.json`
|
||||
);
|
||||
}
|
||||
|
||||
getRunType() {
|
||||
return config.oneoff.productionRun ? 'production' : 'test';
|
||||
}
|
||||
|
||||
export() {
|
||||
const log = {
|
||||
startTime: this._startTime,
|
||||
finishTime: this._finishTime,
|
||||
elapsedTime: this._elapsedTime,
|
||||
prCount: this._prs.length,
|
||||
firstPR: this._firstPR,
|
||||
lastPR: this._lastPR,
|
||||
prs: this._prs
|
||||
};
|
||||
saveToFile(this._logfile, JSON.stringify(log, null, 2));
|
||||
}
|
||||
|
||||
add(prNum, props) {
|
||||
this._prs.push(props);
|
||||
}
|
||||
|
||||
getPrRange() {
|
||||
if (this._prs.length) {
|
||||
const first = this._prs[0].number;
|
||||
const last = this._prs[this._prs.length - 1].number;
|
||||
return [first, last];
|
||||
}
|
||||
console.log('Current log file does not contain any PRs');
|
||||
return [null, null];
|
||||
}
|
||||
|
||||
start() {
|
||||
this._startTime = new Date();
|
||||
this.export();
|
||||
}
|
||||
|
||||
finish(logFileName = '') {
|
||||
this._finishTime = new Date();
|
||||
const minutesElapsed = (this._finishTime - this._startTime) / 1000 / 60;
|
||||
this._elapsedTime = minutesElapsed.toFixed(2) + ' mins';
|
||||
let [first, last] = this.getPrRange();
|
||||
this._firstPR = first;
|
||||
this._lastPR = last;
|
||||
this.export();
|
||||
this.changeFilename(logFileName);
|
||||
}
|
||||
|
||||
changeFilename(logFileName) {
|
||||
const now = formatDate(new Date(), 'YYYY-MM-DDTHHmmss');
|
||||
const prRange = `${this._firstPR}-${this._lastPR}`;
|
||||
let finalFilename = `${this.getRunType()}_${
|
||||
this._script
|
||||
}_${prRange}_${now}.json`;
|
||||
let newFilename = path.resolve(
|
||||
__dirname,
|
||||
`../../work-logs/${finalFilename}`
|
||||
);
|
||||
if (logFileName) {
|
||||
newFilename = logFileName;
|
||||
}
|
||||
fs.renameSync(this._logfile, newFilename);
|
||||
if (!fs.existsSync(newFilename)) {
|
||||
throw 'File rename unsuccessful.';
|
||||
}
|
||||
this._logfile = newFilename;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { ProcessingLog };
|
Reference in New Issue
Block a user