-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathopenIssue.ts
More file actions
60 lines (53 loc) · 2.24 KB
/
openIssue.ts
File metadata and controls
60 lines (53 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import type { Octokit } from '@octokit/core';
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 = 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) =>
!line.trim().startsWith("Fix any") &&
!line.trim().startsWith("Fix all") &&
line.trim() !== ""
? `- ${line}`
: line
)
.join("\n");
const acceptanceCriteria = `## Acceptance Criteria
- [ ] The specific axe violation reported in this issue is no longer reproducible.
- [ ] The fix MUST meet WCAG 2.1 guidelines OR the accessibility standards specified by the repository or organization.
- [ ] A test SHOULD be added to ensure this specific axe violation does not regress.
- [ ] This PR MUST NOT introduce any new accessibility issues or regressions.
`;
const body = `## What
An accessibility scan flagged the element \`${finding.html}\` on ${finding.url} because ${finding.problemShort}. Learn more about why this was flagged by visiting ${finding.problemUrl}.
To fix this, ${finding.solutionShort}.
${solutionLong ? `\nSpecifically:\n\n${solutionLong}` : ''}
${acceptanceCriteria}
`;
return octokit.request(`POST /repos/${owner}/${repo}/issues`, {
owner,
repo,
title,
body,
labels
});
}