feat: changed to module.exports
This commit is contained in:
committed by
mrugesh mohapatra
parent
76c23be416
commit
2ae521c995
@ -5,7 +5,7 @@ const octokit = require('@octokit/rest')(octokitConfig);
|
||||
|
||||
octokit.authenticate(octokitAuth);
|
||||
|
||||
const addComment = async (number, comment) => {
|
||||
const addComment = async (number, comment, log) => {
|
||||
const result = await octokit.issues.createComment({ owner, repo, number, body: comment })
|
||||
.catch((err) => {
|
||||
console.log(`PR #${number} had an error when trying to add a comment\n`);
|
||||
|
@ -8,7 +8,6 @@ octokit.authenticate(octokitAuth);
|
||||
const addLabels = (number, labels, log) => {
|
||||
octokit.issues.addLabels({ owner, repo, number, labels })
|
||||
.then(() => {
|
||||
log.update(number, true);
|
||||
console.log(`PR #${number} added ${JSON.stringify(labels)}\n`);
|
||||
})
|
||||
.catch((err) => {
|
||||
@ -18,4 +17,4 @@ const addLabels = (number, labels, log) => {
|
||||
})
|
||||
};
|
||||
|
||||
exports.addLabels = addLabels;
|
||||
module.exports = { addLabels };
|
||||
|
@ -4,7 +4,4 @@ const repo = process.env.REPOSITORY;
|
||||
const fccBaseUrl = `https://github.com/${owner}/${repo}/`;
|
||||
const prBaseUrl = `${fccBaseUrl}pull/`;
|
||||
|
||||
exports.owner = owner;
|
||||
exports.repo = repo;
|
||||
exports.fccBaseUrl = fccBaseUrl;
|
||||
exports.prBaseUrl = prBaseUrl;
|
||||
module.exports = { owner, repo, fccBaseUrl, prBaseUrl }
|
||||
|
@ -12,5 +12,4 @@ const openJSONFile = fileName => {
|
||||
return data;
|
||||
};
|
||||
|
||||
exports.saveToFile = saveToFile;
|
||||
exports.openJSONFile = openJSONFile;
|
||||
module.exports = { saveToFile, openJSONFile };
|
||||
|
@ -44,5 +44,4 @@ const getOpenPrs = async (firstPR, lastPR, prPropsToGet) => {
|
||||
return { firstPR, lastPR, openPRs };
|
||||
}
|
||||
|
||||
exports.getOpenPrs = getOpenPrs;
|
||||
exports.getPrRange = getPrRange;
|
||||
module.exports = { getOpenPrs, getPrRange };
|
||||
|
@ -5,7 +5,9 @@ const octokit = require('@octokit/rest')(octokitConfig);
|
||||
|
||||
octokit.authenticate(octokitAuth);
|
||||
|
||||
exports.getStatuses = async function getStatuses (method, methodProps) {
|
||||
const getStatuses = async function getStatuses (method, methodProps) {
|
||||
const { data } = await method(methodProps);
|
||||
return data
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
module.exports = { getStatuses }
|
||||
|
@ -84,7 +84,7 @@ const guideFolderChecks = (prFiles, user) => {
|
||||
return newErrors ? errorsFound.concat(newErrors) : errorsFound;
|
||||
}, []);
|
||||
|
||||
return createErrorMsg(prErrors, user);
|
||||
return prErrors.length ? createErrorMsg(prErrors, user) : null;
|
||||
};
|
||||
|
||||
exports.guideFolderChecks = guideFolderChecks;
|
||||
module.exports = { guideFolderChecks };
|
||||
|
@ -36,15 +36,19 @@ const prPropsToGet = ['number', 'labels', 'user'];
|
||||
for (let count = 0; count < openPRs.length; count++) {
|
||||
let { number, labels, user: { login: username } } = openPRs[count];
|
||||
const { data: prFiles } = await octokit.pullRequests.getFiles({ owner, repo, number });
|
||||
log.add(number)
|
||||
log.add(number, 'labels', 'comment');
|
||||
const labelsToAdd = {}; // holds potential labels to add based on file path
|
||||
|
||||
const guideFolderErrorsComment = guideFolderChecks(prFiles, username);
|
||||
if (guideFolderErrorsComment) {
|
||||
log.update(number, 'comment', guideFolderErrorsComment);
|
||||
const result = await addComment(number, guideFolderErrorsComment);
|
||||
await rateLimiter(1000);
|
||||
labelsToAdd['status: needs update'] = 1;
|
||||
}
|
||||
else {
|
||||
log.update(number, 'comment', 'not added');
|
||||
}
|
||||
|
||||
const existingLabels = labels.map(({ name }) => name);
|
||||
|
||||
@ -65,11 +69,12 @@ const prPropsToGet = ['number', 'labels', 'user'];
|
||||
/* 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);
|
||||
addLabels(number, newLabels, log);
|
||||
await rateLimiter(1000);
|
||||
}
|
||||
else {
|
||||
log.update(number, false);
|
||||
log.update(number, 'labels', 'none added');
|
||||
}
|
||||
if (count % 25 === 0) {
|
||||
log.export()
|
||||
|
@ -10,8 +10,10 @@ exports.octokitConfig = {
|
||||
agent: undefined
|
||||
}
|
||||
|
||||
exports.octokitAuth = {
|
||||
const octokitAuth = {
|
||||
type: 'basic',
|
||||
username: process.env.USERNAME,
|
||||
password: process.env.ACCESS_TOKEN
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { octokitAuth };
|
||||
|
@ -39,6 +39,4 @@ const getOpenPrRange = async () => {
|
||||
return [firstPR, lastPR];
|
||||
};
|
||||
|
||||
exports.getOpenPrCount = getOpenPrCount;
|
||||
exports.getFirstPr = getFirstPr;
|
||||
exports.getOpenPrRange = getOpenPrRange;
|
||||
module.exports = { getOpenPrCount, getFirstPr, getOpenPrRange };
|
||||
|
@ -38,4 +38,4 @@ const paginate = async function paginate (method, octokit, firstPR, lastPR, prPr
|
||||
return data;
|
||||
};
|
||||
|
||||
exports.paginate = paginate;
|
||||
module.exports = { paginate };
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* closes and reopens an open PR with applicable comment */
|
||||
require('dotenv').config();
|
||||
const { owner, repo, fccBaseUrl, prBaseUrl } = require('./constants');
|
||||
const { octokitConfig, octokitAuth } = require('./octokitConfig');
|
||||
@ -19,4 +20,4 @@ const prOpenClose = async (number) => {
|
||||
})
|
||||
};
|
||||
|
||||
exports.prOpenClose = prOpenClose;
|
||||
module.exports = prOpenClose;
|
||||
|
@ -27,12 +27,13 @@ class PrProcessingLog {
|
||||
saveToFile(this._logfile, JSON.stringify(log))
|
||||
}
|
||||
|
||||
add(prNum) {
|
||||
this._prs[prNum] = null;
|
||||
add(prNum, prop) {
|
||||
this._prs[prNum] = {};
|
||||
this._prs[prNum][prop] = null;
|
||||
}
|
||||
|
||||
update(prNum, status) {
|
||||
this._prs[prNum] = status;
|
||||
update(prNum, prop, value) {
|
||||
this._prs[prNum][prop] = value;
|
||||
}
|
||||
|
||||
start() {
|
||||
@ -45,4 +46,4 @@ class PrProcessingLog {
|
||||
}
|
||||
};
|
||||
|
||||
exports.PrProcessingLog = PrProcessingLog;
|
||||
module.exports = { PrProcessingLog };
|
||||
|
@ -1,4 +1,4 @@
|
||||
exports.validLabels = {
|
||||
const validLabels = {
|
||||
arabic: 'language: Arabic',
|
||||
chinese: 'language: Chinese',
|
||||
portuguese: 'language: Portuguese',
|
||||
@ -8,3 +8,5 @@ exports.validLabels = {
|
||||
docs: 'scope: documentation',
|
||||
guide: 'scope: guide'
|
||||
};
|
||||
|
||||
module.exports = { validLabels };
|
||||
|
Reference in New Issue
Block a user