Truncate prompt
This commit is contained in:
@@ -57,6 +57,14 @@ export type PayloadEvent =
|
|||||||
branch: string;
|
branch: string;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
| {
|
||||||
|
trigger: "pull_request_ready_for_review";
|
||||||
|
issue_number: number;
|
||||||
|
pr_title: string;
|
||||||
|
pr_body: string | null;
|
||||||
|
branch: string;
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
| {
|
| {
|
||||||
trigger: "pull_request_review_requested";
|
trigger: "pull_request_review_requested";
|
||||||
issue_number: number;
|
issue_number: number;
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pullfrog/action",
|
"name": "@pullfrog/action",
|
||||||
"version": "0.0.127",
|
"version": "0.0.128",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"files": [
|
"files": [
|
||||||
"index.js",
|
"index.js",
|
||||||
|
|||||||
+32
-32
@@ -10,6 +10,30 @@ import { table } from "table";
|
|||||||
const isGitHubActions = !!process.env.GITHUB_ACTIONS;
|
const isGitHubActions = !!process.env.GITHUB_ACTIONS;
|
||||||
const isDebugEnabled = () => process.env.LOG_LEVEL === "debug";
|
const isDebugEnabled = () => process.env.LOG_LEVEL === "debug";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the terminal width, or a reasonable default if not available
|
||||||
|
*/
|
||||||
|
function getTerminalWidth(): number {
|
||||||
|
if (process.stdout.columns && process.stdout.columns > 0) {
|
||||||
|
return process.stdout.columns;
|
||||||
|
}
|
||||||
|
// reasonable default for most terminals
|
||||||
|
return 120;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Truncate a line to fit within maxLength, adding ellipsis if needed
|
||||||
|
*/
|
||||||
|
function truncateLine(line: string, maxLength: number): string {
|
||||||
|
if (line.length <= maxLength) {
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
if (maxLength <= 3) {
|
||||||
|
return "...".slice(0, maxLength);
|
||||||
|
}
|
||||||
|
return line.slice(0, maxLength - 3) + "...";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a collapsed group (GitHub Actions) or regular group (local)
|
* Start a collapsed group (GitHub Actions) or regular group (local)
|
||||||
*/
|
*/
|
||||||
@@ -44,40 +68,16 @@ function boxString(
|
|||||||
padding?: number;
|
padding?: number;
|
||||||
}
|
}
|
||||||
): string {
|
): string {
|
||||||
const { title, maxWidth = 80, indent = "", padding = 1 } = options || {};
|
const terminalWidth = getTerminalWidth();
|
||||||
|
const { title, maxWidth = terminalWidth, indent = "", padding = 1 } = options || {};
|
||||||
|
|
||||||
|
// account for box borders (2 chars: │ on each side) and padding
|
||||||
|
const maxContentWidth = maxWidth - 2 - padding * 2;
|
||||||
|
|
||||||
const lines = text.trim().split("\n");
|
const lines = text.trim().split("\n");
|
||||||
const wrappedLines: string[] = [];
|
const truncatedLines = lines.map((line) => truncateLine(line, maxContentWidth));
|
||||||
|
|
||||||
for (const line of lines) {
|
const maxLineLength = Math.max(...truncatedLines.map((line) => line.length));
|
||||||
if (line.length <= maxWidth - padding * 2) {
|
|
||||||
wrappedLines.push(line);
|
|
||||||
} else {
|
|
||||||
const words = line.split(" ");
|
|
||||||
let currentLine = "";
|
|
||||||
|
|
||||||
for (const word of words) {
|
|
||||||
const testLine = currentLine ? `${currentLine} ${word}` : word;
|
|
||||||
if (testLine.length <= maxWidth - padding * 2) {
|
|
||||||
currentLine = testLine;
|
|
||||||
} else {
|
|
||||||
if (currentLine) {
|
|
||||||
wrappedLines.push(currentLine);
|
|
||||||
currentLine = word;
|
|
||||||
} else {
|
|
||||||
wrappedLines.push(word.substring(0, maxWidth - padding * 2));
|
|
||||||
currentLine = word.substring(maxWidth - padding * 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentLine) {
|
|
||||||
wrappedLines.push(currentLine);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const maxLineLength = Math.max(...wrappedLines.map((line) => line.length));
|
|
||||||
const contentBoxWidth = maxLineLength + padding * 2;
|
const contentBoxWidth = maxLineLength + padding * 2;
|
||||||
|
|
||||||
// ensure box width is at least as wide as the title line when title exists
|
// ensure box width is at least as wide as the title line when title exists
|
||||||
@@ -96,7 +96,7 @@ function boxString(
|
|||||||
result += `${indent}┌${"─".repeat(boxWidth)}┐\n`;
|
result += `${indent}┌${"─".repeat(boxWidth)}┐\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const line of wrappedLines) {
|
for (const line of truncatedLines) {
|
||||||
const paddedLine = line.padEnd(maxLineLength);
|
const paddedLine = line.padEnd(maxLineLength);
|
||||||
result += `${indent}│${" ".repeat(padding)}${paddedLine}${" ".repeat(padding)}│\n`;
|
result += `${indent}│${" ".repeat(padding)}${paddedLine}${" ".repeat(padding)}│\n`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user