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);
|
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 })
|
const result = await octokit.issues.createComment({ owner, repo, number, body: comment })
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(`PR #${number} had an error when trying to add a comment\n`);
|
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) => {
|
const addLabels = (number, labels, log) => {
|
||||||
octokit.issues.addLabels({ owner, repo, number, labels })
|
octokit.issues.addLabels({ owner, repo, number, labels })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
log.update(number, true);
|
|
||||||
console.log(`PR #${number} added ${JSON.stringify(labels)}\n`);
|
console.log(`PR #${number} added ${JSON.stringify(labels)}\n`);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.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 fccBaseUrl = `https://github.com/${owner}/${repo}/`;
|
||||||
const prBaseUrl = `${fccBaseUrl}pull/`;
|
const prBaseUrl = `${fccBaseUrl}pull/`;
|
||||||
|
|
||||||
exports.owner = owner;
|
module.exports = { owner, repo, fccBaseUrl, prBaseUrl }
|
||||||
exports.repo = repo;
|
|
||||||
exports.fccBaseUrl = fccBaseUrl;
|
|
||||||
exports.prBaseUrl = prBaseUrl;
|
|
||||||
|
@ -12,5 +12,4 @@ const openJSONFile = fileName => {
|
|||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.saveToFile = saveToFile;
|
module.exports = { saveToFile, openJSONFile };
|
||||||
exports.openJSONFile = openJSONFile;
|
|
||||||
|
@ -44,5 +44,4 @@ const getOpenPrs = async (firstPR, lastPR, prPropsToGet) => {
|
|||||||
return { firstPR, lastPR, openPRs };
|
return { firstPR, lastPR, openPRs };
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getOpenPrs = getOpenPrs;
|
module.exports = { getOpenPrs, getPrRange };
|
||||||
exports.getPrRange = getPrRange;
|
|
||||||
|
@ -5,7 +5,9 @@ const octokit = require('@octokit/rest')(octokitConfig);
|
|||||||
|
|
||||||
octokit.authenticate(octokitAuth);
|
octokit.authenticate(octokitAuth);
|
||||||
|
|
||||||
exports.getStatuses = async function getStatuses (method, methodProps) {
|
const getStatuses = async function getStatuses (method, methodProps) {
|
||||||
const { data } = await 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 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++) {
|
for (let count = 0; count < openPRs.length; count++) {
|
||||||
let { number, labels, user: { login: username } } = openPRs[count];
|
let { number, labels, user: { login: username } } = openPRs[count];
|
||||||
const { data: prFiles } = await octokit.pullRequests.getFiles({ owner, repo, number });
|
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 labelsToAdd = {}; // holds potential labels to add based on file path
|
||||||
|
|
||||||
const guideFolderErrorsComment = guideFolderChecks(prFiles, username);
|
const guideFolderErrorsComment = guideFolderChecks(prFiles, username);
|
||||||
if (guideFolderErrorsComment) {
|
if (guideFolderErrorsComment) {
|
||||||
|
log.update(number, 'comment', guideFolderErrorsComment);
|
||||||
const result = await addComment(number, guideFolderErrorsComment);
|
const result = await addComment(number, guideFolderErrorsComment);
|
||||||
await rateLimiter(1000);
|
await rateLimiter(1000);
|
||||||
labelsToAdd['status: needs update'] = 1;
|
labelsToAdd['status: needs update'] = 1;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
log.update(number, 'comment', 'not added');
|
||||||
|
}
|
||||||
|
|
||||||
const existingLabels = labels.map(({ name }) => name);
|
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. */
|
/* this next section only adds needed labels which are NOT currently on the PR. */
|
||||||
const newLabels = Object.keys(labelsToAdd).filter(label => !existingLabels.includes(label));
|
const newLabels = Object.keys(labelsToAdd).filter(label => !existingLabels.includes(label));
|
||||||
if (newLabels.length) {
|
if (newLabels.length) {
|
||||||
|
log.update(number, 'labels', newLabels);
|
||||||
addLabels(number, newLabels, log);
|
addLabels(number, newLabels, log);
|
||||||
await rateLimiter(1000);
|
await rateLimiter(1000);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.update(number, false);
|
log.update(number, 'labels', 'none added');
|
||||||
}
|
}
|
||||||
if (count % 25 === 0) {
|
if (count % 25 === 0) {
|
||||||
log.export()
|
log.export()
|
||||||
|
@ -10,8 +10,10 @@ exports.octokitConfig = {
|
|||||||
agent: undefined
|
agent: undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.octokitAuth = {
|
const octokitAuth = {
|
||||||
type: 'basic',
|
type: 'basic',
|
||||||
username: process.env.USERNAME,
|
username: process.env.USERNAME,
|
||||||
password: process.env.ACCESS_TOKEN
|
password: process.env.ACCESS_TOKEN
|
||||||
}
|
};
|
||||||
|
|
||||||
|
module.exports = { octokitAuth };
|
||||||
|
@ -39,6 +39,4 @@ const getOpenPrRange = async () => {
|
|||||||
return [firstPR, lastPR];
|
return [firstPR, lastPR];
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getOpenPrCount = getOpenPrCount;
|
module.exports = { getOpenPrCount, getFirstPr, getOpenPrRange };
|
||||||
exports.getFirstPr = getFirstPr;
|
|
||||||
exports.getOpenPrRange = getOpenPrRange;
|
|
||||||
|
@ -38,4 +38,4 @@ const paginate = async function paginate (method, octokit, firstPR, lastPR, prPr
|
|||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.paginate = paginate;
|
module.exports = { paginate };
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
/* closes and reopens an open PR with applicable comment */
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const { owner, repo, fccBaseUrl, prBaseUrl } = require('./constants');
|
const { owner, repo, fccBaseUrl, prBaseUrl } = require('./constants');
|
||||||
const { octokitConfig, octokitAuth } = require('./octokitConfig');
|
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))
|
saveToFile(this._logfile, JSON.stringify(log))
|
||||||
}
|
}
|
||||||
|
|
||||||
add(prNum) {
|
add(prNum, prop) {
|
||||||
this._prs[prNum] = null;
|
this._prs[prNum] = {};
|
||||||
|
this._prs[prNum][prop] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
update(prNum, status) {
|
update(prNum, prop, value) {
|
||||||
this._prs[prNum] = status;
|
this._prs[prNum][prop] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
@ -45,4 +46,4 @@ class PrProcessingLog {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.PrProcessingLog = PrProcessingLog;
|
module.exports = { PrProcessingLog };
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
exports.validLabels = {
|
const validLabels = {
|
||||||
arabic: 'language: Arabic',
|
arabic: 'language: Arabic',
|
||||||
chinese: 'language: Chinese',
|
chinese: 'language: Chinese',
|
||||||
portuguese: 'language: Portuguese',
|
portuguese: 'language: Portuguese',
|
||||||
@ -8,3 +8,5 @@ exports.validLabels = {
|
|||||||
docs: 'scope: documentation',
|
docs: 'scope: documentation',
|
||||||
guide: 'scope: guide'
|
guide: 'scope: guide'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = { validLabels };
|
||||||
|
Reference in New Issue
Block a user