fix: addComment and labler issues
This commit is contained in:
committed by
mrugesh mohapatra
parent
ade0b9a53f
commit
76c23be416
@ -5,17 +5,18 @@ const octokit = require('@octokit/rest')(octokitConfig);
|
|||||||
|
|
||||||
octokit.authenticate(octokitAuth);
|
octokit.authenticate(octokitAuth);
|
||||||
|
|
||||||
const addComment = (number, comment) => {
|
const addComment = async (number, comment) => {
|
||||||
setTimeout(async () => {
|
const result = await octokit.issues.createComment({ owner, repo, number, body: comment })
|
||||||
octokit.issues.createComment({ owner, repo, number, body: comment })
|
.catch((err) => {
|
||||||
.then(() => {
|
console.log(`PR #${number} had an error when trying to add a comment\n`);
|
||||||
console.log(`PR #${number} successfully added a comment\n`);
|
console.log(err)
|
||||||
})
|
});
|
||||||
.catch((err) => {
|
|
||||||
console.log(`PR #${number} had an error when trying to add a comment\n`);
|
if (result) {
|
||||||
console.log(err)
|
console.log(`PR #${number} successfully added a comment\n`);
|
||||||
})
|
}
|
||||||
}, 1000); // wait one second to comment for API rate limiting compliance
|
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.addComment = addComment;
|
module.exports = { addComment };
|
||||||
|
@ -10,13 +10,10 @@ const { validLabels } = require('./validLabels');
|
|||||||
const { addLabels } = require('./addLabels');
|
const { addLabels } = require('./addLabels');
|
||||||
const { guideFolderChecks } = require('./guideFolderChecks');
|
const { guideFolderChecks } = require('./guideFolderChecks');
|
||||||
const { addComment } = require('./addComment');
|
const { addComment } = require('./addComment');
|
||||||
|
const { rateLimiter } = require('./utils');
|
||||||
|
|
||||||
octokit.authenticate(octokitAuth);
|
octokit.authenticate(octokitAuth);
|
||||||
|
|
||||||
const rateLimiter = (delay) => {
|
|
||||||
return new Promise(resolve => setTimeout(() => resolve(true), delay));
|
|
||||||
};
|
|
||||||
|
|
||||||
const { PrProcessingLog } = require('./prProcessingLog');
|
const { PrProcessingLog } = require('./prProcessingLog');
|
||||||
const log = new PrProcessingLog();
|
const log = new PrProcessingLog();
|
||||||
|
|
||||||
@ -44,15 +41,8 @@ const prPropsToGet = ['number', 'labels', 'user'];
|
|||||||
|
|
||||||
const guideFolderErrorsComment = guideFolderChecks(prFiles, username);
|
const guideFolderErrorsComment = guideFolderChecks(prFiles, username);
|
||||||
if (guideFolderErrorsComment) {
|
if (guideFolderErrorsComment) {
|
||||||
const result = await octokit.issues.createComment({ owner, repo, number, body: guideFolderErrorsComment })
|
const result = await addComment(number, guideFolderErrorsComment);
|
||||||
.catch((err) => {
|
await rateLimiter(1000);
|
||||||
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);
|
|
||||||
}
|
|
||||||
labelsToAdd['status: needs update'] = 1;
|
labelsToAdd['status: needs update'] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +66,7 @@ const prPropsToGet = ['number', 'labels', 'user'];
|
|||||||
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) {
|
||||||
addLabels(number, newLabels, log);
|
addLabels(number, newLabels, log);
|
||||||
await rateLimiter(3000);
|
await rateLimiter(1000);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.update(number, false);
|
log.update(number, false);
|
||||||
|
Reference in New Issue
Block a user