From 2ae521c995977496cb8552328fcac363a44f8d36 Mon Sep 17 00:00:00 2001 From: Randell Dawson Date: Sun, 11 Nov 2018 23:52:00 -0800 Subject: [PATCH] feat: changed to module.exports --- addComment.js | 2 +- addLabels.js | 3 +-- constants.js | 5 +---- fileFunctions.js | 3 +-- getOpenPrs.js | 3 +-- getStatuses.js | 8 +++++--- guideFolderChecks.js | 4 ++-- labelOpenPrs.js | 9 +++++++-- octokitConfig.js | 6 ++++-- openPrStats.js | 4 +--- paginate.js | 2 +- prOpenClose.js | 3 ++- prProcessingLog.js | 11 ++++++----- validLabels.js | 4 +++- 14 files changed, 36 insertions(+), 31 deletions(-) diff --git a/addComment.js b/addComment.js index 46d2b09e8a..0e0bd70354 100644 --- a/addComment.js +++ b/addComment.js @@ -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`); diff --git a/addLabels.js b/addLabels.js index 6889799d24..48ade4a2e4 100644 --- a/addLabels.js +++ b/addLabels.js @@ -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 }; diff --git a/constants.js b/constants.js index e9a8f98757..f3399a2bac 100644 --- a/constants.js +++ b/constants.js @@ -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 } diff --git a/fileFunctions.js b/fileFunctions.js index 38b026d0b3..e319946bc8 100644 --- a/fileFunctions.js +++ b/fileFunctions.js @@ -12,5 +12,4 @@ const openJSONFile = fileName => { return data; }; -exports.saveToFile = saveToFile; -exports.openJSONFile = openJSONFile; +module.exports = { saveToFile, openJSONFile }; diff --git a/getOpenPrs.js b/getOpenPrs.js index dce3ff9d3f..d056fde4cc 100644 --- a/getOpenPrs.js +++ b/getOpenPrs.js @@ -44,5 +44,4 @@ const getOpenPrs = async (firstPR, lastPR, prPropsToGet) => { return { firstPR, lastPR, openPRs }; } -exports.getOpenPrs = getOpenPrs; -exports.getPrRange = getPrRange; +module.exports = { getOpenPrs, getPrRange }; diff --git a/getStatuses.js b/getStatuses.js index 1b7e918ead..1d19f5bdd9 100644 --- a/getStatuses.js +++ b/getStatuses.js @@ -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 } diff --git a/guideFolderChecks.js b/guideFolderChecks.js index a8f967657f..f4b801dde1 100644 --- a/guideFolderChecks.js +++ b/guideFolderChecks.js @@ -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 }; diff --git a/labelOpenPrs.js b/labelOpenPrs.js index 9444532a3a..346ef7aae1 100644 --- a/labelOpenPrs.js +++ b/labelOpenPrs.js @@ -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() diff --git a/octokitConfig.js b/octokitConfig.js index ea9f26a960..883aacee1b 100644 --- a/octokitConfig.js +++ b/octokitConfig.js @@ -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 }; diff --git a/openPrStats.js b/openPrStats.js index 4b5b917256..7c370060a6 100644 --- a/openPrStats.js +++ b/openPrStats.js @@ -39,6 +39,4 @@ const getOpenPrRange = async () => { return [firstPR, lastPR]; }; -exports.getOpenPrCount = getOpenPrCount; -exports.getFirstPr = getFirstPr; -exports.getOpenPrRange = getOpenPrRange; +module.exports = { getOpenPrCount, getFirstPr, getOpenPrRange }; diff --git a/paginate.js b/paginate.js index 41198a3cd6..3ea07e3bd8 100644 --- a/paginate.js +++ b/paginate.js @@ -38,4 +38,4 @@ const paginate = async function paginate (method, octokit, firstPR, lastPR, prPr return data; }; -exports.paginate = paginate; +module.exports = { paginate }; diff --git a/prOpenClose.js b/prOpenClose.js index e0045cdf44..8f1e20cae5 100644 --- a/prOpenClose.js +++ b/prOpenClose.js @@ -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; diff --git a/prProcessingLog.js b/prProcessingLog.js index 5819d90b1b..e54189b1f2 100644 --- a/prProcessingLog.js +++ b/prProcessingLog.js @@ -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 }; diff --git a/validLabels.js b/validLabels.js index 508e8e41ae..c5537ad15c 100644 --- a/validLabels.js +++ b/validLabels.js @@ -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 };