fix: correct logging bug

This commit is contained in:
Randell Dawson
2018-11-23 00:44:48 -08:00
committed by mrugesh mohapatra
parent f172410304
commit 69d3b8cb84
3 changed files with 29 additions and 10 deletions

View File

@@ -2,7 +2,7 @@
This is a one-off script to run on all open PRs to add
a comment and "status: needs update" label to any PR with guide articles which
have frontmatter issues.
*//************ log.js **************/
*/
require('dotenv').config({ path: '../.env' });
const fetch = require('node-fetch');
@@ -85,6 +85,7 @@ const guideFolderChecks = async (number, prFiles, user) => {
(async () => {
const { firstPR, lastPR } = await getUserInput();
log.setFirstLast({ firstPR, lastPR });
const prPropsToGet = ['number', 'labels', 'user'];
const { openPRs } = await getPRs(firstPR, lastPR, prPropsToGet);
@@ -102,7 +103,7 @@ const guideFolderChecks = async (number, prFiles, user) => {
const labelsAdded = await labeler(number, prFiles, currentLabels, guideFolderErrorsComment);
const labelLogVal = labelsAdded.length ? labelsAdded : 'none added';
log.update(number, { comment: commentLogVal, labels: labelLogVal });
log.add(number, { comment: commentLogVal, labels: labelLogVal });
await rateLimiter(+process.env.RATELIMIT_INTERVAL | 1500);
}
}

View File

@@ -19,6 +19,7 @@ const log = new ProcessingLog('all-locally-tested-labels');
(async () => {
const { firstPR, lastPR } = await getUserInput();
log.setFirstLast({ firstPR, lastPR });
const prPropsToGet = ['number', 'labels'];
const { openPRs } = await getPRs(firstPR, lastPR, prPropsToGet);

View File

@@ -1,28 +1,45 @@
/*
This is a one-off script which can be used to parse a production or test version of
the open-prs-processed.json file in the work-logs directory. It will generate a text
file referencing only PRs and any comments/labels either added (prodouction) or
would be added (test) based on data stored in the open-prs-processed.json file.
file referencing only PRs with any comments/labels either added (prodouction) or
would be added (test) based on data stored in the specific JSON log file.
*/
const { saveToFile, openJSONFile } = require('../utils');
const path = require('path');
const dedent = require("dedent");
const specificLogFile = path.resolve(__dirname, `../work-logs/production_sweeper_3-6_2018-11-23T003553.json`);
(() => {
let fileObj = openJSONFile(path.resolve(__dirname, `../work-logs/test_open-prs-processed.json`));
let fileObj = openJSONFile(specificLogFile);
let { prs } = fileObj;
let count = 0;
let prsWithComments = prs.reduce((text, pr) => {
let number = Object.keys(pr).map(key => key);
let { comment, labels } = pr[number];
let prsWithComments = prs.reduce((text, { number, data: { comment, labels } }) => {
if (comment !== 'none' || labels !== 'none added') {
text += `PR #${number}\r\nComment: ${comment}\r\n\r\nLabels: ${labels}\r\n*************************\r\n\r\n`;
text += dedent`
PR #${number}
Comment: ${comment}
Labels: ${labels}
*************************\n
`;
count++;
}
return text;
}, '');
prsWithComments = '# of PRs with comments or labels added: ' + count + '\r\n\r\n*************************\r\n' + prsWithComments;
prsWithComments = dedent`
# of PRs with comments or labels added: ${count}
*************************
${prsWithComments}
`;
saveToFile(path.resolve(__dirname, `../work-logs/guideErrorComments.txt`), prsWithComments);
console.log('guideErrorComments.txt created');
})()