Randell Dawson c8f6d15688
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>
2020-12-22 13:43:36 +09:00

64 lines
1.7 KiB
JavaScript

/*
This script was originally created to iterate over all open PRs to label and
comment on specific PR errors (i.e. guide related filenmame syntax and
frontmatter).
Since the first run which covered over 10,000+ PRs, it is curently ran every
couple of days for just the most recent PRs.
To run the script for a specific range,
run `node sweeper.js range startingPrNumber endingPrNumber`
*/
const {
github: { freeCodeCampRepo, defaultBase }
} = require('../lib/config');
const { getPRs, getUserInput, getFiles } = require('../lib/get-prs');
const { ProcessingLog, rateLimiter } = require('../lib/utils');
const { labeler } = require('../lib/pr-tasks');
const log = new ProcessingLog('sweeper');
log.start();
console.log('Sweeper started...');
(async () => {
const { totalPRs, firstPR, lastPR } = await getUserInput(
freeCodeCampRepo,
defaultBase
);
const prPropsToGet = ['number', 'labels', 'user'];
const { openPRs } = await getPRs(
freeCodeCampRepo,
defaultBase,
totalPRs,
firstPR,
lastPR,
prPropsToGet
);
let count = 0;
if (openPRs.length) {
console.log('Processing PRs...');
for (let i = 0; i < openPRs.length; i++) {
let { number, labels: currentLabels } = openPRs[i];
const prFiles = await getFiles(freeCodeCampRepo, number);
count++;
const labelsAdded = await labeler(number, prFiles, currentLabels);
const labelLogVal = labelsAdded.length ? labelsAdded : 'none added';
log.add(number, { number, labels: labelLogVal });
if (count > 4000) {
await rateLimiter(2350);
}
}
}
})()
.then(() => {
log.finish();
console.log('Sweeper complete');
})
.catch(err => {
log.finish();
console.log(err);
});