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

103 lines
2.9 KiB
JavaScript

/*
This is a one-off script to find all open PRs which have one of the
console.error descriptions in the failuresToFind.json file.
*/
const { Octokit } = require('@octokit/rest');
const fetch = require('node-fetch');
const {
github: { owner, secret, freeCodeCampRepo, defaultBase }
} = require('../lib/config');
const octokit = new Octokit({ auth: secret });
const { getPRs, getUserInput } = require('../lib/get-prs');
const { savePrData, ProcessingLog } = require('../lib/utils');
const log = new ProcessingLog('find-failures-script');
const errorsToFind = [
{
error: '',
regex: ''
}
];
(async () => {
const { totalPRs, firstPR, lastPR } = await getUserInput(
freeCodeCampRepo,
defaultBase
);
const prPropsToGet = ['number', 'labels', 'head'];
const { openPRs } = await getPRs(
freeCodeCampRepo,
defaultBase,
totalPRs,
firstPR,
lastPR,
prPropsToGet
);
if (openPRs.length) {
savePrData(openPRs, firstPR, lastPR);
log.start();
console.log('Starting error finding process...');
for (let count = 0; count < openPRs.length; count++) {
let {
number,
labels,
head: { sha: ref }
} = openPRs[count];
const existingLabels = labels.map(({ name }) => name);
if (
!existingLabels.includes('status: merge conflict') &&
!existingLabels.includes('status: needs update') &&
!existingLabels.includes('status: discussing')
) {
const { data: statuses } = await octokit.repos.listStatusesForRef({
owner,
repo: freeCodeCampRepo,
ref
});
if (statuses.length) {
// first element contain most recent status
const { state, target_url: targetUrl } = statuses[0];
const hasProblem = state === 'failure' || state === 'error';
if (hasProblem) {
let buildNum = Number(targetUrl.match(/\/builds\/(\d+)\?/i)[1]);
/*
const logNumber = 'need to use Travis api to
access the full log for the buildNum above'
*/
const logNumber = ++buildNum;
const travisBaseUrl = 'https://api.travis-ci.org/v3/job/';
const travisLogUrl = `${travisBaseUrl + logNumber}/log.txt`;
const response = await fetch(travisLogUrl);
const logText = await response.text();
let error;
for (let { error: errorDesc, regex } of errorsToFind) {
regex = RegExp(regex);
if (regex.test(logText)) {
error = errorDesc;
break;
}
}
const errorDesc = error ? error : 'unknown error';
log.add(number, { number, errorDesc, buildLog: travisLogUrl });
}
}
}
}
}
})()
.then(() => {
log.finish();
console.log('Successfully finished finding all specified errors.');
})
.catch(err => {
log.finish();
console.log(err);
});