Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .github/actions/file/src/openIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down