From dc808a0015c767ef7012cc433d08c7d0ee5eea55 Mon Sep 17 00:00:00 2001 From: Clay Miller Date: Tue, 4 Nov 2025 12:22:44 -0500 Subject: [PATCH] =?UTF-8?q?fix(File):=20Don=E2=80=99t=20exceed=20the=20max?= =?UTF-8?q?=20allowed=20length=20for=20issue=20titles=20(256=20characters)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/actions/file/src/openIssue.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/actions/file/src/openIssue.ts b/.github/actions/file/src/openIssue.ts index 769637a2..9751772e 100644 --- a/.github/actions/file/src/openIssue.ts +++ b/.github/actions/file/src/openIssue.ts @@ -3,12 +3,28 @@ import type { Finding } from './types.d.js'; import * as url from 'node:url' const URL = url.URL; +/** Max length for GitHub issue titles */ +const GITHUB_ISSUE_TITLE_MAX_LENGTH = 256; + +/** + * Truncates text to a maximum length, adding an ellipsis if truncated. + * @param text Original text + * @param maxLength Maximum length of the returned text (including ellipsis) + * @returns Either the original text or a truncated version with an ellipsis + */ +function truncateWithEllipsis(text: string, maxLength: number): string { + return text.length > maxLength ? text.slice(0, maxLength - 1) + '…' : text; +} + export async function openIssue(octokit: Octokit, repoWithOwner: string, finding: Finding) { const owner = repoWithOwner.split('/')[0]; const repo = repoWithOwner.split('/')[1]; const labels = [`${finding.scannerType} rule: ${finding.ruleId}`, `${finding.scannerType}-scanning-issue`]; - const title = `Accessibility issue: ${finding.problemShort[0].toUpperCase() + finding.problemShort.slice(1)} on ${new URL(finding.url).pathname}`; + const title = truncateWithEllipsis( + `Accessibility issue: ${finding.problemShort[0].toUpperCase() + finding.problemShort.slice(1)} on ${new URL(finding.url).pathname}`, + GITHUB_ISSUE_TITLE_MAX_LENGTH + ); const solutionLong = finding.solutionLong ?.split("\n") .map((line) =>