From 6d7d5129e0eb81e7db70c22f457be1f9f0c7f978 Mon Sep 17 00:00:00 2001 From: Randell Dawson Date: Fri, 9 Nov 2018 11:26:59 -0800 Subject: [PATCH] feature: added addComment feature --- addComment.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 addComment.js diff --git a/addComment.js b/addComment.js new file mode 100644 index 0000000000..a3deecaf22 --- /dev/null +++ b/addComment.js @@ -0,0 +1,21 @@ +require('dotenv').config(); +const { owner, repo } = require('./constants'); +const { octokitConfig, octokitAuth } = require('./octokitConfig'); +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 +}; + +exports.addComment = addComment;