fix: addComment and labler issues

This commit is contained in:
Randell Dawson
2018-11-09 21:58:12 -08:00
committed by mrugesh mohapatra
parent ade0b9a53f
commit 76c23be416
2 changed files with 17 additions and 26 deletions

View File

@ -5,17 +5,18 @@ const octokit = require('@octokit/rest')(octokitConfig);
octokit.authenticate(octokitAuth);
const addComment = (number, comment) => {
setTimeout(async () => {
octokit.issues.createComment({ owner, repo, number, body: comment })
.then(() => {
console.log(`PR #${number} successfully added a comment\n`);
})
.catch((err) => {
console.log(`PR #${number} had an error when trying to add a comment\n`);
console.log(err)
})
}, 1000); // wait one second to comment for API rate limiting compliance
const addComment = async (number, comment) => {
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`);
console.log(err)
});
if (result) {
console.log(`PR #${number} successfully added a comment\n`);
}
return result;
};
exports.addComment = addComment;
module.exports = { addComment };

View File

@ -10,13 +10,10 @@ const { validLabels } = require('./validLabels');
const { addLabels } = require('./addLabels');
const { guideFolderChecks } = require('./guideFolderChecks');
const { addComment } = require('./addComment');
const { rateLimiter } = require('./utils');
octokit.authenticate(octokitAuth);
const rateLimiter = (delay) => {
return new Promise(resolve => setTimeout(() => resolve(true), delay));
};
const { PrProcessingLog } = require('./prProcessingLog');
const log = new PrProcessingLog();
@ -44,15 +41,8 @@ const prPropsToGet = ['number', 'labels', 'user'];
const guideFolderErrorsComment = guideFolderChecks(prFiles, username);
if (guideFolderErrorsComment) {
const result = await octokit.issues.createComment({ owner, repo, number, body: guideFolderErrorsComment })
.catch((err) => {
console.log(`PR #${number} had an error when trying to add a comment\n`);
console.log(err)
});
if (result) {
console.log(`PR #${number} successfully added a comment\n`);
await rateLimiter(3000);
}
const result = await addComment(number, guideFolderErrorsComment);
await rateLimiter(1000);
labelsToAdd['status: needs update'] = 1;
}
@ -76,7 +66,7 @@ const prPropsToGet = ['number', 'labels', 'user'];
const newLabels = Object.keys(labelsToAdd).filter(label => !existingLabels.includes(label));
if (newLabels.length) {
addLabels(number, newLabels, log);
await rateLimiter(3000);
await rateLimiter(1000);
}
else {
log.update(number, false);