* 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>
111 lines
3.1 KiB
JavaScript
111 lines
3.1 KiB
JavaScript
/*
|
|
This script was created to find all open PRs that have merge
|
|
conflicts and then add a the 'status: merge conflict' label to any PR
|
|
which does not already have the label.
|
|
|
|
To run the script for a specific language, call the script with the language
|
|
name as the first argument.
|
|
|
|
Note: It is possible that it could take more than 4 seconds for GitHub to
|
|
determine if a PR is mergeable. If that happens, the PR will not be labeled.
|
|
*/
|
|
|
|
const { Octokit } = require('@octokit/rest');
|
|
const {
|
|
github: { owner, secret, freeCodeCampRepo, defaultBase }
|
|
} = require('../lib/config');
|
|
|
|
const octokit = new Octokit({ auth: secret });
|
|
|
|
const { getPRs, getUserInput } = require('../lib/get-prs');
|
|
const { ProcessingLog, rateLimiter } = require('../lib/utils');
|
|
const { addLabels } = require('../lib/pr-tasks');
|
|
const { validLabels } = require('../lib/validation/valid-labels');
|
|
|
|
let languageLabel;
|
|
let [languageArg] = process.argv.slice(2);
|
|
if (languageArg) {
|
|
languageArg = languageArg.toLowerCase();
|
|
languageLabel = validLabels[languageArg] ? validLabels[languageArg] : null;
|
|
}
|
|
|
|
if (languageLabel) {
|
|
console.log(`finding PRs with label = ${languageLabel}`);
|
|
}
|
|
|
|
const log = new ProcessingLog('prs-with-merge-conflicts');
|
|
log.start();
|
|
(async () => {
|
|
const { totalPRs, firstPR, lastPR } = await getUserInput(
|
|
freeCodeCampRepo,
|
|
defaultBase,
|
|
'all'
|
|
);
|
|
const prPropsToGet = ['number', 'labels', 'user'];
|
|
const { openPRs } = await getPRs(
|
|
freeCodeCampRepo,
|
|
defaultBase,
|
|
totalPRs,
|
|
firstPR,
|
|
lastPR,
|
|
prPropsToGet
|
|
);
|
|
if (openPRs.length) {
|
|
let count = 0;
|
|
let mergeConflictCount = 0;
|
|
for (let i = 0; i < openPRs.length; i++) {
|
|
let { labels, number } = openPRs[i];
|
|
|
|
const hasLanguage =
|
|
languageLabel && labels.some(({ name }) => languageLabel === name);
|
|
|
|
const hasMergeConflictLabel = labels.some(
|
|
({ name }) => 'status: merge conflict' === name
|
|
);
|
|
|
|
if (!languageLabel || hasLanguage) {
|
|
let data = await octokit.pulls.get({
|
|
owner,
|
|
repo: freeCodeCampRepo,
|
|
number
|
|
});
|
|
let mergeableState = data.data.mergeable_state;
|
|
count++;
|
|
if (mergeableState === 'unknown') {
|
|
await rateLimiter(4000);
|
|
data = await octokit.pulls.get({
|
|
owner,
|
|
repo: freeCodeCampRepo,
|
|
number
|
|
});
|
|
mergeableState = data.data.mergeable_state;
|
|
count++;
|
|
}
|
|
|
|
if (mergeableState === 'dirty' && !hasMergeConflictLabel) {
|
|
mergeConflictCount++;
|
|
addLabels(number, ['status: merge conflict'], log);
|
|
await rateLimiter();
|
|
}
|
|
|
|
if (count > 4000) {
|
|
await rateLimiter(2350);
|
|
}
|
|
}
|
|
}
|
|
console.log(
|
|
`There were ${mergeConflictCount} PRs with potential merge conflicts out of ${count} PRs received from GitHub`
|
|
);
|
|
} else {
|
|
throw 'There were no open PRs received from Github';
|
|
}
|
|
})()
|
|
.then(async () => {
|
|
log.finish();
|
|
console.log('Finished finding PRs with merge conflicts');
|
|
})
|
|
.catch(err => {
|
|
log.finish();
|
|
console.log(err);
|
|
});
|