Files
freeCodeCamp/one-off-scripts/addTestLocallyLabel.js

55 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-11-20 15:31:28 -08:00
require('dotenv').config({ path: '../.env' });
const { owner, repo, octokitConfig, octokitAuth } = require('../constants');
2018-11-14 23:40:26 -08:00
const octokit = require('@octokit/rest')(octokitConfig);
2018-11-20 15:31:28 -08:00
const { getPRs, getUserInput } = require('../getPRs');
const { addLabels } = require('../prTasks');
const { rateLimiter, savePrData, ProcessingLog } = require('../utils');
2018-11-14 23:40:26 -08:00
2018-11-20 15:31:28 -08:00
octokit.authenticate(octokitAuth);
2018-11-14 23:40:26 -08:00
2018-11-20 15:31:28 -08:00
const log = new ProcessingLog();
2018-11-14 23:40:26 -08:00
(async () => {
2018-11-20 15:31:28 -08:00
const { firstPR, lastPR } = await getUserInput();
const prPropsToGet = ['number', 'labels'];
const { openPRs } = await getPRs(firstPR, lastPR, prPropsToGet);
2018-11-14 23:40:26 -08:00
if (openPRs.length) {
savePrData(openPRs, firstPR, lastPR);
log.start();
console.log('Starting labeling process...');
2018-11-20 15:31:28 -08:00
for (let count in openPRs) {
2018-11-14 23:40:26 -08:00
let { number, labels } = openPRs[count];
log.add(number, 'labels');
const labelsToAdd = {}; // holds potential labels to add based on file path
const existingLabels = labels.map(({ name }) => name);
if (existingLabels.includes('scope: curriculum')) {
labelsToAdd['status: need to test locally'] = 1;
}
/* this next section only adds needed labels which are NOT currently on the PR. */
const newLabels = Object.keys(labelsToAdd).filter(label => !existingLabels.includes(label));
if (newLabels.length) {
log.update(number, 'labels', newLabels);
if (process.env.PRODUCTION_RUN === 'true') {
addLabels(number, newLabels, log);
2018-11-20 15:31:28 -08:00
await rateLimiter(+process.env.RATELIMIT_INTERVAL | 1500);
2018-11-14 23:40:26 -08:00
}
}
else {
log.update(number, 'labels', 'none added');
}
}
}
})()
.then(() => {
log.finish();
console.log('Successfully completed labeling');
})
.catch(err => {
log.finish();
console.log(err)
})