Skip to content

Commit ddcbf9e

Browse files
authored
fix(File): Don’t exceed the max allowed length for issue titles (256 characters) (#69)
Fixes #61
2 parents fd7cdea + dc808a0 commit ddcbf9e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

.github/actions/file/src/openIssue.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,28 @@ import type { Finding } from './types.d.js';
33
import * as url from 'node:url'
44
const URL = url.URL;
55

6+
/** Max length for GitHub issue titles */
7+
const GITHUB_ISSUE_TITLE_MAX_LENGTH = 256;
8+
9+
/**
10+
* Truncates text to a maximum length, adding an ellipsis if truncated.
11+
* @param text Original text
12+
* @param maxLength Maximum length of the returned text (including ellipsis)
13+
* @returns Either the original text or a truncated version with an ellipsis
14+
*/
15+
function truncateWithEllipsis(text: string, maxLength: number): string {
16+
return text.length > maxLength ? text.slice(0, maxLength - 1) + '…' : text;
17+
}
18+
619
export async function openIssue(octokit: Octokit, repoWithOwner: string, finding: Finding) {
720
const owner = repoWithOwner.split('/')[0];
821
const repo = repoWithOwner.split('/')[1];
922

1023
const labels = [`${finding.scannerType} rule: ${finding.ruleId}`, `${finding.scannerType}-scanning-issue`];
11-
const title = `Accessibility issue: ${finding.problemShort[0].toUpperCase() + finding.problemShort.slice(1)} on ${new URL(finding.url).pathname}`;
24+
const title = truncateWithEllipsis(
25+
`Accessibility issue: ${finding.problemShort[0].toUpperCase() + finding.problemShort.slice(1)} on ${new URL(finding.url).pathname}`,
26+
GITHUB_ISSUE_TITLE_MAX_LENGTH
27+
);
1228
const solutionLong = finding.solutionLong
1329
?.split("\n")
1430
.map((line) =>

0 commit comments

Comments
 (0)