Skip to content

Commit

Permalink
Break up github issue link message
Browse files Browse the repository at this point in the history
  • Loading branch information
area committed Jan 17, 2025
1 parent 1e530f6 commit 691ee7d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
5 changes: 4 additions & 1 deletion scripts/github-issue-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// Author:
// sprusr

const { splitStringByNewLine } = require('./utils/strings')

module.exports = function(robot) {
const github = require('githubot')(robot)
const issueRegex = /([/A-Za-z0-9\-.]*)?#(\d+)/g
Expand Down Expand Up @@ -55,6 +57,7 @@ module.exports = function(robot) {

response += `**${type} #${issueNumber}:** ${title} <${url}>\n`
}
msg.send(response.trim())
const responses = splitStringByNewLine(response, 2000)
responses.forEach(response => msg.send(response.trim()))
})
}
23 changes: 2 additions & 21 deletions scripts/github-pr-reminder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { prHelpers } = require('./utils/prs.js')
const { splitStringByNewLine } = require('./utils/strings.js')
const CronJob = require('cron').CronJob
require('dotenv').config()

Expand All @@ -20,7 +21,7 @@ const getMessages = async robot => {
prsWithoutReviews.forEach(pr => {
response += `**PR #${pr.number}:** ${pr.title} <${pr['html_url']}>\n`
})
let responses = splitStringByNewLine(response)
let responses = splitStringByNewLine(response, 2000)
return responses;
}
}
Expand All @@ -41,23 +42,3 @@ 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;
}
22 changes: 22 additions & 0 deletions scripts/utils/strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function splitStringByNewLine(str, maxLength) {
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;
}

module.exports = {
splitStringByNewLine
}

0 comments on commit 691ee7d

Please sign in to comment.