Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b5df2bdca | |||
| 02ca5bbc71 |
@@ -83859,7 +83859,7 @@ function query({
|
|||||||
// package.json
|
// package.json
|
||||||
var package_default = {
|
var package_default = {
|
||||||
name: "@pullfrog/action",
|
name: "@pullfrog/action",
|
||||||
version: "0.0.126",
|
version: "0.0.128",
|
||||||
type: "module",
|
type: "module",
|
||||||
files: [
|
files: [
|
||||||
"index.js",
|
"index.js",
|
||||||
@@ -83891,7 +83891,7 @@ var package_default = {
|
|||||||
"@octokit/webhooks-types": "^7.6.1",
|
"@octokit/webhooks-types": "^7.6.1",
|
||||||
"@openai/codex-sdk": "0.58.0",
|
"@openai/codex-sdk": "0.58.0",
|
||||||
"@standard-schema/spec": "1.0.0",
|
"@standard-schema/spec": "1.0.0",
|
||||||
arktype: "2.1.25",
|
arktype: "2.1.28",
|
||||||
dotenv: "^17.2.3",
|
dotenv: "^17.2.3",
|
||||||
execa: "^9.6.0",
|
execa: "^9.6.0",
|
||||||
fastmcp: "^3.20.0",
|
fastmcp: "^3.20.0",
|
||||||
@@ -83936,6 +83936,21 @@ var core = __toESM(require_core(), 1);
|
|||||||
var import_table = __toESM(require_src(), 1);
|
var import_table = __toESM(require_src(), 1);
|
||||||
var isGitHubActions = !!process.env.GITHUB_ACTIONS;
|
var isGitHubActions = !!process.env.GITHUB_ACTIONS;
|
||||||
var isDebugEnabled = () => process.env.LOG_LEVEL === "debug";
|
var isDebugEnabled = () => process.env.LOG_LEVEL === "debug";
|
||||||
|
function getTerminalWidth() {
|
||||||
|
if (process.stdout.columns && process.stdout.columns > 0) {
|
||||||
|
return process.stdout.columns;
|
||||||
|
}
|
||||||
|
return 120;
|
||||||
|
}
|
||||||
|
function truncateLine(line, maxLength) {
|
||||||
|
if (line.length <= maxLength) {
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
if (maxLength <= 3) {
|
||||||
|
return "...".slice(0, maxLength);
|
||||||
|
}
|
||||||
|
return line.slice(0, maxLength - 3) + "...";
|
||||||
|
}
|
||||||
function startGroup2(name) {
|
function startGroup2(name) {
|
||||||
if (isGitHubActions) {
|
if (isGitHubActions) {
|
||||||
core.startGroup(name);
|
core.startGroup(name);
|
||||||
@@ -83951,35 +83966,12 @@ function endGroup2() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
function boxString(text, options) {
|
function boxString(text, options) {
|
||||||
const { title, maxWidth = 80, indent: indent2 = "", padding = 1 } = options || {};
|
const terminalWidth = getTerminalWidth();
|
||||||
|
const { title, maxWidth = terminalWidth, indent: indent2 = "", padding = 1 } = options || {};
|
||||||
|
const maxContentWidth = maxWidth - 2 - padding * 2;
|
||||||
const lines = text.trim().split("\n");
|
const lines = text.trim().split("\n");
|
||||||
const wrappedLines = [];
|
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;
|
||||||
const titleLineLength = title ? ` ${title} `.length : 0;
|
const titleLineLength = title ? ` ${title} `.length : 0;
|
||||||
const boxWidth = Math.max(contentBoxWidth, titleLineLength);
|
const boxWidth = Math.max(contentBoxWidth, titleLineLength);
|
||||||
@@ -83994,7 +83986,7 @@ function boxString(text, options) {
|
|||||||
result += `${indent2}\u250C${"\u2500".repeat(boxWidth)}\u2510
|
result += `${indent2}\u250C${"\u2500".repeat(boxWidth)}\u2510
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
for (const line of wrappedLines) {
|
for (const line of truncatedLines) {
|
||||||
const paddedLine = line.padEnd(maxLineLength);
|
const paddedLine = line.padEnd(maxLineLength);
|
||||||
result += `${indent2}\u2502${" ".repeat(padding)}${paddedLine}${" ".repeat(padding)}\u2502
|
result += `${indent2}\u2502${" ".repeat(padding)}${paddedLine}${" ".repeat(padding)}\u2502
|
||||||
`;
|
`;
|
||||||
@@ -122930,7 +122922,6 @@ To fix this, add the required secret to your GitHub repository:
|
|||||||
|
|
||||||
Alternatively, configure Pullfrog to use an agent at ${settingsUrl}`;
|
Alternatively, configure Pullfrog to use an agent at ${settingsUrl}`;
|
||||||
}
|
}
|
||||||
log.error(message);
|
|
||||||
await reportErrorToComment({ error: message });
|
await reportErrorToComment({ error: message });
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { encode as toonEncode } from "@toon-format/toon";
|
|||||||
import { type } from "arktype";
|
import { type } from "arktype";
|
||||||
import { agents } from "./agents/index.ts";
|
import { agents } from "./agents/index.ts";
|
||||||
import type { AgentResult } from "./agents/shared.ts";
|
import type { AgentResult } from "./agents/shared.ts";
|
||||||
import type { AgentName, AgentName as AgentNameType, Payload } from "./external.ts";
|
import type { AgentName, Payload } from "./external.ts";
|
||||||
import { agentsManifest } from "./external.ts";
|
import { agentsManifest } from "./external.ts";
|
||||||
import { ensureProgressCommentUpdated } from "./mcp/comment.ts";
|
import { ensureProgressCommentUpdated } from "./mcp/comment.ts";
|
||||||
import { createMcpConfigs } from "./mcp/config.ts";
|
import { createMcpConfigs } from "./mcp/config.ts";
|
||||||
@@ -111,7 +111,7 @@ export async function main(inputs: Inputs): Promise<MainResult> {
|
|||||||
/**
|
/**
|
||||||
* Get agents that have matching API keys in the inputs
|
* Get agents that have matching API keys in the inputs
|
||||||
*/
|
*/
|
||||||
function getAvailableAgents(inputs: Inputs): (typeof agents)[AgentNameType][] {
|
function getAvailableAgents(inputs: Inputs): (typeof agents)[AgentName][] {
|
||||||
return Object.values(agents).filter((agent) =>
|
return Object.values(agents).filter((agent) =>
|
||||||
agent.apiKeyNames.some((inputKey) => inputs[inputKey])
|
agent.apiKeyNames.some((inputKey) => inputs[inputKey])
|
||||||
);
|
);
|
||||||
@@ -135,7 +135,7 @@ async function throwMissingApiKeyError({
|
|||||||
agent,
|
agent,
|
||||||
repoContext,
|
repoContext,
|
||||||
}: {
|
}: {
|
||||||
agent: (typeof agents)[AgentNameType] | null;
|
agent: (typeof agents)[AgentName] | null;
|
||||||
repoContext: RepoContext;
|
repoContext: RepoContext;
|
||||||
}): Promise<never> {
|
}): Promise<never> {
|
||||||
const apiUrl = process.env.API_URL || "https://pullfrog.com";
|
const apiUrl = process.env.API_URL || "https://pullfrog.com";
|
||||||
@@ -167,7 +167,6 @@ To fix this, add the required secret to your GitHub repository:
|
|||||||
message += `\n\nAlternatively, configure Pullfrog to use an agent at ${settingsUrl}`;
|
message += `\n\nAlternatively, configure Pullfrog to use an agent at ${settingsUrl}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.error(message);
|
|
||||||
// report to comment if MCP context is available (server has started)
|
// report to comment if MCP context is available (server has started)
|
||||||
await reportErrorToComment({ error: message });
|
await reportErrorToComment({ error: message });
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
@@ -177,8 +176,8 @@ interface MainContext {
|
|||||||
inputs: Inputs;
|
inputs: Inputs;
|
||||||
githubInstallationToken: string;
|
githubInstallationToken: string;
|
||||||
repoContext: RepoContext;
|
repoContext: RepoContext;
|
||||||
agentName: AgentNameType;
|
agentName: AgentName;
|
||||||
agent: (typeof agents)[AgentNameType];
|
agent: (typeof agents)[AgentName];
|
||||||
sharedTempDir: string;
|
sharedTempDir: string;
|
||||||
payload: Payload;
|
payload: Payload;
|
||||||
mcpServerUrl: string;
|
mcpServerUrl: string;
|
||||||
@@ -226,7 +225,7 @@ async function resolveAgent(
|
|||||||
payload: Payload,
|
payload: Payload,
|
||||||
githubInstallationToken: string,
|
githubInstallationToken: string,
|
||||||
repoContext: RepoContext
|
repoContext: RepoContext
|
||||||
): Promise<{ agentName: AgentNameType; agent: (typeof agents)[AgentNameType] }> {
|
): Promise<{ agentName: AgentName; agent: (typeof agents)[AgentName] }> {
|
||||||
const repoSettings = await fetchRepoSettings({
|
const repoSettings = await fetchRepoSettings({
|
||||||
token: githubInstallationToken,
|
token: githubInstallationToken,
|
||||||
repoContext,
|
repoContext,
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pullfrog/action",
|
"name": "@pullfrog/action",
|
||||||
"version": "0.0.126",
|
"version": "0.0.128",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"files": [
|
"files": [
|
||||||
"index.js",
|
"index.js",
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
"@octokit/webhooks-types": "^7.6.1",
|
"@octokit/webhooks-types": "^7.6.1",
|
||||||
"@openai/codex-sdk": "0.58.0",
|
"@openai/codex-sdk": "0.58.0",
|
||||||
"@standard-schema/spec": "1.0.0",
|
"@standard-schema/spec": "1.0.0",
|
||||||
"arktype": "2.1.25",
|
"arktype": "2.1.28",
|
||||||
"dotenv": "^17.2.3",
|
"dotenv": "^17.2.3",
|
||||||
"execa": "^9.6.0",
|
"execa": "^9.6.0",
|
||||||
"fastmcp": "^3.20.0",
|
"fastmcp": "^3.20.0",
|
||||||
|
|||||||
Generated
+26
-21
@@ -36,8 +36,8 @@ importers:
|
|||||||
specifier: 1.0.0
|
specifier: 1.0.0
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
arktype:
|
arktype:
|
||||||
specifier: 2.1.25
|
specifier: 2.1.28
|
||||||
version: 2.1.25
|
version: 2.1.28
|
||||||
dotenv:
|
dotenv:
|
||||||
specifier: ^17.2.3
|
specifier: ^17.2.3
|
||||||
version: 17.2.3
|
version: 17.2.3
|
||||||
@@ -46,7 +46,7 @@ importers:
|
|||||||
version: 9.6.0
|
version: 9.6.0
|
||||||
fastmcp:
|
fastmcp:
|
||||||
specifier: ^3.20.0
|
specifier: ^3.20.0
|
||||||
version: 3.20.0(arktype@2.1.25)
|
version: 3.20.0(arktype@2.1.28)
|
||||||
table:
|
table:
|
||||||
specifier: ^6.9.0
|
specifier: ^6.9.0
|
||||||
version: 6.9.0
|
version: 6.9.0
|
||||||
@@ -96,12 +96,15 @@ packages:
|
|||||||
'@ark/fs@0.53.0':
|
'@ark/fs@0.53.0':
|
||||||
resolution: {integrity: sha512-XL0EbBAZgyy+j9aPhftYaBsbKAW5PTNSKCN6oLRRdrHuHPSAZgR6765/z0YZGhPxHEUNmq0vBoSk8yOLk91dNQ==}
|
resolution: {integrity: sha512-XL0EbBAZgyy+j9aPhftYaBsbKAW5PTNSKCN6oLRRdrHuHPSAZgR6765/z0YZGhPxHEUNmq0vBoSk8yOLk91dNQ==}
|
||||||
|
|
||||||
'@ark/schema@0.53.0':
|
'@ark/schema@0.56.0':
|
||||||
resolution: {integrity: sha512-1PB7RThUiTlmIu8jbSurPrhHpVixPd4C+xNBUF/HrjIENCeDcAMg36n5mpMzED7OQGDVIzpfXXiMnaTiutjHJw==}
|
resolution: {integrity: sha512-ECg3hox/6Z/nLajxXqNhgPtNdHWC9zNsDyskwO28WinoFEnWow4IsERNz9AnXRhTZJnYIlAJ4uGn3nlLk65vZA==}
|
||||||
|
|
||||||
'@ark/util@0.53.0':
|
'@ark/util@0.53.0':
|
||||||
resolution: {integrity: sha512-TGn4gLlA6dJcQiqrtCtd88JhGb2XBHo6qIejsDre+nxpGuUVW4G3YZGVrwjNBTO0EyR+ykzIo4joHJzOj+/cpA==}
|
resolution: {integrity: sha512-TGn4gLlA6dJcQiqrtCtd88JhGb2XBHo6qIejsDre+nxpGuUVW4G3YZGVrwjNBTO0EyR+ykzIo4joHJzOj+/cpA==}
|
||||||
|
|
||||||
|
'@ark/util@0.56.0':
|
||||||
|
resolution: {integrity: sha512-BghfRC8b9pNs3vBoDJhcta0/c1J1rsoS1+HgVUreMFPdhz/CRAKReAu57YEllNaSy98rWAdY1gE+gFup7OXpgA==}
|
||||||
|
|
||||||
'@borewit/text-codec@0.1.1':
|
'@borewit/text-codec@0.1.1':
|
||||||
resolution: {integrity: sha512-5L/uBxmjaCIX5h8Z+uu+kA9BQLkc/Wl06UGR5ajNRxu+/XjonB5i8JpgFMrPj3LXTCPA0pv8yxUvbUi+QthGGA==}
|
resolution: {integrity: sha512-5L/uBxmjaCIX5h8Z+uu+kA9BQLkc/Wl06UGR5ajNRxu+/XjonB5i8JpgFMrPj3LXTCPA0pv8yxUvbUi+QthGGA==}
|
||||||
|
|
||||||
@@ -486,11 +489,11 @@ packages:
|
|||||||
arg@5.0.2:
|
arg@5.0.2:
|
||||||
resolution: {integrity: sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==}
|
resolution: {integrity: sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==}
|
||||||
|
|
||||||
arkregex@0.0.2:
|
arkregex@0.0.4:
|
||||||
resolution: {integrity: sha512-ttjDUICBVoXD/m8bf7eOjx8XMR6yIT2FmmW9vsN0FCcFOygEZvvIX8zK98tTdXkzi0LkRi5CmadB44jFEIyDNA==}
|
resolution: {integrity: sha512-biS/FkvSwQq59TZ453piUp8bxMui11pgOMV9WHAnli1F8o0ayNCZzUwQadL/bGIUic5TkS/QlPcyMuI8ZIwedQ==}
|
||||||
|
|
||||||
arktype@2.1.25:
|
arktype@2.1.28:
|
||||||
resolution: {integrity: sha512-fdj10sNlUPeDRg1QUqMbzJ4Q7gutTOWOpLUNdcC4vxeVrN0G+cbDOvLbuxQOFj/NDAode1G7kwFv4yKwQvupJg==}
|
resolution: {integrity: sha512-LVZqXl2zWRpNFnbITrtFmqeqNkPPo+KemuzbGSY6jvJwCb4v8NsDzrWOLHnQgWl26TkJeWWcUNUeBpq2Mst1/Q==}
|
||||||
|
|
||||||
astral-regex@2.0.0:
|
astral-regex@2.0.0:
|
||||||
resolution: {integrity: sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==}
|
resolution: {integrity: sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==}
|
||||||
@@ -1133,12 +1136,14 @@ snapshots:
|
|||||||
|
|
||||||
'@ark/fs@0.53.0': {}
|
'@ark/fs@0.53.0': {}
|
||||||
|
|
||||||
'@ark/schema@0.53.0':
|
'@ark/schema@0.56.0':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@ark/util': 0.53.0
|
'@ark/util': 0.56.0
|
||||||
|
|
||||||
'@ark/util@0.53.0': {}
|
'@ark/util@0.53.0': {}
|
||||||
|
|
||||||
|
'@ark/util@0.56.0': {}
|
||||||
|
|
||||||
'@borewit/text-codec@0.1.1': {}
|
'@borewit/text-codec@0.1.1': {}
|
||||||
|
|
||||||
'@esbuild/aix-ppc64@0.25.12':
|
'@esbuild/aix-ppc64@0.25.12':
|
||||||
@@ -1456,15 +1461,15 @@ snapshots:
|
|||||||
|
|
||||||
arg@5.0.2: {}
|
arg@5.0.2: {}
|
||||||
|
|
||||||
arkregex@0.0.2:
|
arkregex@0.0.4:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@ark/util': 0.53.0
|
'@ark/util': 0.56.0
|
||||||
|
|
||||||
arktype@2.1.25:
|
arktype@2.1.28:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@ark/schema': 0.53.0
|
'@ark/schema': 0.56.0
|
||||||
'@ark/util': 0.53.0
|
'@ark/util': 0.56.0
|
||||||
arkregex: 0.0.2
|
arkregex: 0.0.4
|
||||||
|
|
||||||
astral-regex@2.0.0: {}
|
astral-regex@2.0.0: {}
|
||||||
|
|
||||||
@@ -1663,7 +1668,7 @@ snapshots:
|
|||||||
|
|
||||||
fast-uri@3.1.0: {}
|
fast-uri@3.1.0: {}
|
||||||
|
|
||||||
fastmcp@3.20.0(arktype@2.1.25):
|
fastmcp@3.20.0(arktype@2.1.28):
|
||||||
dependencies:
|
dependencies:
|
||||||
'@modelcontextprotocol/sdk': 1.20.0
|
'@modelcontextprotocol/sdk': 1.20.0
|
||||||
'@standard-schema/spec': 1.0.0
|
'@standard-schema/spec': 1.0.0
|
||||||
@@ -1674,7 +1679,7 @@ snapshots:
|
|||||||
strict-event-emitter-types: 2.0.0
|
strict-event-emitter-types: 2.0.0
|
||||||
undici: 7.16.0
|
undici: 7.16.0
|
||||||
uri-templates: 0.2.0
|
uri-templates: 0.2.0
|
||||||
xsschema: 0.3.5(arktype@2.1.25)(zod-to-json-schema@3.24.6(zod@3.25.76))(zod@3.25.76)
|
xsschema: 0.3.5(arktype@2.1.28)(zod-to-json-schema@3.24.6(zod@3.25.76))(zod@3.25.76)
|
||||||
yargs: 18.0.0
|
yargs: 18.0.0
|
||||||
zod: 3.25.76
|
zod: 3.25.76
|
||||||
zod-to-json-schema: 3.24.6(zod@3.25.76)
|
zod-to-json-schema: 3.24.6(zod@3.25.76)
|
||||||
@@ -2050,9 +2055,9 @@ snapshots:
|
|||||||
|
|
||||||
wrappy@1.0.2: {}
|
wrappy@1.0.2: {}
|
||||||
|
|
||||||
xsschema@0.3.5(arktype@2.1.25)(zod-to-json-schema@3.24.6(zod@3.25.76))(zod@3.25.76):
|
xsschema@0.3.5(arktype@2.1.28)(zod-to-json-schema@3.24.6(zod@3.25.76))(zod@3.25.76):
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
arktype: 2.1.25
|
arktype: 2.1.28
|
||||||
zod: 3.25.76
|
zod: 3.25.76
|
||||||
zod-to-json-schema: 3.24.6(zod@3.25.76)
|
zod-to-json-schema: 3.24.6(zod@3.25.76)
|
||||||
|
|
||||||
|
|||||||
+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