Skip to content

Commit 7a08475

Browse files
committed
Extracts issue body generation in prepration for adding screenshots
1 parent 7b1ad39 commit 7a08475

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { Finding } from "./types.d.js";
2+
3+
export function generateIssueBody(finding: Finding, repoWithOwner: string): string {
4+
const solutionLong = finding.solutionLong
5+
?.split("\n")
6+
.map((line: string) =>
7+
!line.trim().startsWith("Fix any") &&
8+
!line.trim().startsWith("Fix all") &&
9+
line.trim() !== ""
10+
? `- ${line}`
11+
: line
12+
)
13+
.join("\n");
14+
const acceptanceCriteria = `## Acceptance Criteria
15+
- [ ] The specific axe violation reported in this issue is no longer reproducible.
16+
- [ ] The fix MUST meet WCAG 2.1 guidelines OR the accessibility standards specified by the repository or organization.
17+
- [ ] A test SHOULD be added to ensure this specific axe violation does not regress.
18+
- [ ] This PR MUST NOT introduce any new accessibility issues or regressions.
19+
`;
20+
const body = `## What
21+
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}.
22+
23+
To fix this, ${finding.solutionShort}.
24+
${solutionLong ? `\nSpecifically:\n\n${solutionLong}` : ''}
25+
26+
${acceptanceCriteria}
27+
`;
28+
29+
return body;
30+
}
31+

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

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Octokit } from '@octokit/core';
22
import type { Finding } from './types.d.js';
3+
import { generateIssueBody } from "./generateIssueBody.js";
34
import * as url from 'node:url'
45
const URL = url.URL;
56

@@ -23,32 +24,10 @@ export async function openIssue(octokit: Octokit, repoWithOwner: string, finding
2324
const labels = [`${finding.scannerType} rule: ${finding.ruleId}`, `${finding.scannerType}-scanning-issue`];
2425
const title = truncateWithEllipsis(
2526
`Accessibility issue: ${finding.problemShort[0].toUpperCase() + finding.problemShort.slice(1)} on ${new URL(finding.url).pathname}`,
26-
GITHUB_ISSUE_TITLE_MAX_LENGTH
27+
GITHUB_ISSUE_TITLE_MAX_LENGTH,
2728
);
28-
const solutionLong = finding.solutionLong
29-
?.split("\n")
30-
.map((line) =>
31-
!line.trim().startsWith("Fix any") &&
32-
!line.trim().startsWith("Fix all") &&
33-
line.trim() !== ""
34-
? `- ${line}`
35-
: line
36-
)
37-
.join("\n");
38-
const acceptanceCriteria = `## Acceptance Criteria
39-
- [ ] The specific axe violation reported in this issue is no longer reproducible.
40-
- [ ] The fix MUST meet WCAG 2.1 guidelines OR the accessibility standards specified by the repository or organization.
41-
- [ ] A test SHOULD be added to ensure this specific axe violation does not regress.
42-
- [ ] This PR MUST NOT introduce any new accessibility issues or regressions.
43-
`;
44-
const body = `## What
45-
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}.
4629

47-
To fix this, ${finding.solutionShort}.
48-
${solutionLong ? `\nSpecifically:\n\n${solutionLong}` : ''}
49-
50-
${acceptanceCriteria}
51-
`;
30+
const body = generateIssueBody(finding, repoWithOwner);
5231

5332
return octokit.request(`POST /repos/${owner}/${repo}/issues`, {
5433
owner,

0 commit comments

Comments
 (0)