Skip to content

Commit

Permalink
If PR reminders too long, split in to multiple messages
Browse files Browse the repository at this point in the history
  • Loading branch information
area committed Feb 22, 2023
1 parent e3a4e2a commit f11f369
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions scripts/github-pr-reminder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@ const CronJob = require('cron').CronJob
require('dotenv').config()

const processUnreviewedPrs = async robot => {
const threshold = 3 // number of days since review requested
const roomId = process.env.HUBOT_DISCORD_DEV_CHANNEL
const messages = await getMessages(robot);
messages.forEach((chunk) => robot.messageRoom(roomId, chunk.trim()));
}

const getMessages = async robot => {
const threshold = 3 // number of days since review requested

const { getPRs, getPRsWithoutReviews } = prHelpers(robot)
let response = `The following PRs have not been reviewed in over ${threshold} days:\n`

const prs = await getPRs()
// The following PRs issued a review request over x days ago and still have no reviews:
const prsWithoutReviews = await getPRsWithoutReviews(prs, threshold)
if (prsWithoutReviews.length) {
prsWithoutReviews.forEach(pr => {
response += `**PR #${pr.number}:** ${pr.title} <${pr['html_url']}>\n`
})
robot.messageRoom(roomId, response.trim())
let responses = splitStringByNewLine(response)
return responses;
}
}

Expand All @@ -35,3 +41,23 @@ const setupCronJob = robot => {
module.exports = function(robot) {
setupCronJob(robot)
}

function splitStringByNewLine(str) {
const maxLength = 1500;
const lines = str.split('\n');
let result = [];
let currentString = '';
lines.forEach((line) => {
if (currentString.length + line.length + 1 <= maxLength) {
// Add the line to the current string
currentString += line + '\n';
} else {
// Add the current string to the result array and start a new string
result.push(currentString);
currentString = line + '\n';
}
});
// Add the final string to the result array
result.push(currentString);
return result;
}

0 comments on commit f11f369

Please sign in to comment.