mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-23 13:00:41 -04:00
This PR has the following items: 1. Introduces a couple of fixes to the sweeper script from issues right before the move to the mono repo. These were related to moving labeler out of the root of the sweeper folder and placing into the pr-tasks sub-folder. 2. Combined two scripts which were being used to update the data manually on Glitch (pr-relations.glitch.me). The new one-off script (get-pr-relations-data.js) downloads the current data.json and then pulls down applicable Github data which updates the data.json and automatically uploads it back to the Glitch server. 3. In an effort to use the same log file across all current one-off scripts and sweeper.js, the ProcessLog class was modified, so now every log created has the same JSON structure as is uploaded to the Glitch server. This removed a lot of redundant code across 3 files. 4. During a pair-coding session with @honmanyau, we tweaked the UI for the Dashboard app to give it a more consistent look across all views. 5. Based on feedback from a couple of the moderators using the new Dashboard app, the PR title was added along with some other styling. 6. Added some environment variables for running dashboard-api and dashboard-client in a development mode. 7. Added a sample_data.json file as a starter file, so someone does not have to do a full data pull to get things up and running. 8. Modified Pareto view to only display files with 2 or more PRs to speed up the report.
57 lines
2.0 KiB
JavaScript
57 lines
2.0 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 (i.e. label and comment on guide errors),
|
|
run `node sweeper.js range startingPrNumber endingPrNumber`
|
|
*/
|
|
|
|
const { owner, repo, octokitConfig, octokitAuth } = require('./constants');
|
|
|
|
const octokit = require('@octokit/rest')(octokitConfig);
|
|
|
|
const { getPRs, getUserInput } = require('./get-prs');
|
|
const { guideFolderChecks } = require('./validation');
|
|
const { savePrData, ProcessingLog, rateLimiter } = require('./utils');
|
|
const { labeler } = require('./pr-tasks');
|
|
|
|
octokit.authenticate(octokitAuth);
|
|
|
|
const log = new ProcessingLog('sweeper');
|
|
|
|
log.start();
|
|
console.log('Sweeper started...');
|
|
(async () => {
|
|
const { totalPRs, firstPR, lastPR } = await getUserInput();
|
|
const prPropsToGet = ['number', 'labels', 'user'];
|
|
const { openPRs } = await getPRs(totalPRs, firstPR, lastPR, prPropsToGet);
|
|
|
|
if (openPRs.length) {
|
|
console.log('Processing PRs...');
|
|
for (let count in openPRs) {
|
|
let { number, labels: currentLabels, user: { login: username } } = openPRs[count];
|
|
const { data: prFiles } = await octokit.pullRequests.listFiles({ owner, repo, number });
|
|
|
|
const guideFolderErrorsComment = await guideFolderChecks(number, prFiles, username);
|
|
const commentLogVal = guideFolderErrorsComment ? guideFolderErrorsComment : 'none';
|
|
|
|
const labelsAdded = await labeler(number, prFiles, currentLabels, guideFolderErrorsComment);
|
|
const labelLogVal = labelsAdded.length ? labelsAdded : 'none added';
|
|
|
|
log.add(number, { number, comment: commentLogVal, labels: labelLogVal });
|
|
await rateLimiter(+process.env.RATELIMIT_INTERVAL | 1500);
|
|
}
|
|
}
|
|
})()
|
|
.then(() => {
|
|
log.finish();
|
|
console.log('Sweeper complete');
|
|
})
|
|
.catch(err => {
|
|
log.finish();
|
|
console.log(err)
|
|
})
|