Skip to content

Commit a0e058e

Browse files
committed
Formatting / linting
1 parent 7131561 commit a0e058e

14 files changed

Lines changed: 284 additions & 323 deletions

.github/actions/file/src/generateIssueBody.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,35 @@ import type {Finding} from './types.d.js'
22

33
export function generateIssueBody(finding: Finding, screenshotRepo: string): string {
44
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");
5+
?.split('\n')
6+
.map((line: string) =>
7+
!line.trim().startsWith('Fix any') && !line.trim().startsWith('Fix all') && line.trim() !== ''
8+
? `- ${line}`
9+
: line,
10+
)
11+
.join('\n')
1412

15-
let screenshotSection;
13+
let screenshotSection
1614
if (finding.screenshotId) {
17-
const screenshotUrl = `https://github.com/${screenshotRepo}/blob/gh-cache/.screenshots/${finding.screenshotId}.png`;
15+
const screenshotUrl = `https://github.com/${screenshotRepo}/blob/gh-cache/.screenshots/${finding.screenshotId}.png`
1816
screenshotSection = `
1917
[View screenshot](${screenshotUrl})
20-
`;
18+
`
2119
}
2220

2321
const acceptanceCriteria = `## Acceptance Criteria
2422
- [ ] The specific axe violation reported in this issue is no longer reproducible.
2523
- [ ] The fix MUST meet WCAG 2.1 guidelines OR the accessibility standards specified by the repository or organization.
2624
- [ ] A test SHOULD be added to ensure this specific axe violation does not regress.
2725
- [ ] This PR MUST NOT introduce any new accessibility issues or regressions.
28-
`;
26+
`
2927

3028
const body = `## What
3129
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}.
3230
33-
${screenshotSection ?? ""}
31+
${screenshotSection ?? ''}
3432
To fix this, ${finding.solutionShort}.
35-
${solutionLong ? `\nSpecifically:\n\n${solutionLong}` : ""}
33+
${solutionLong ? `\nSpecifically:\n\n${solutionLong}` : ''}
3634
3735
${acceptanceCriteria}
3836
`

.github/actions/file/src/index.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,18 @@ import {updateFilingsWithNewFindings} from './updateFilingsWithNewFindings.js'
1414
const OctokitWithThrottling = Octokit.plugin(throttling)
1515

1616
export default async function () {
17-
core.info("Started 'file' action");
18-
const findings: Finding[] = JSON.parse(
19-
core.getInput("findings", { required: true })
20-
);
21-
const repoWithOwner = core.getInput("repository", { required: true });
22-
const token = core.getInput("token", { required: true });
23-
const screenshotRepo =
24-
core.getInput("screenshot_repository", { required: false }) ||
25-
repoWithOwner;
17+
core.info("Started 'file' action")
18+
const findings: Finding[] = JSON.parse(core.getInput('findings', {required: true}))
19+
const repoWithOwner = core.getInput('repository', {required: true})
20+
const token = core.getInput('token', {required: true})
21+
const screenshotRepo = core.getInput('screenshot_repository', {required: false}) || repoWithOwner
2622
const cachedFilings: (ResolvedFiling | RepeatedFiling)[] = JSON.parse(
27-
core.getInput("cached_filings", { required: false }) || "[]"
28-
);
29-
core.debug(`Input: 'findings: ${JSON.stringify(findings)}'`);
30-
core.debug(`Input: 'repository: ${repoWithOwner}'`);
31-
core.debug(`Input: 'screenshot_repository: ${screenshotRepo}'`);
32-
core.debug(`Input: 'cached_filings: ${JSON.stringify(cachedFilings)}'`);
23+
core.getInput('cached_filings', {required: false}) || '[]',
24+
)
25+
core.debug(`Input: 'findings: ${JSON.stringify(findings)}'`)
26+
core.debug(`Input: 'repository: ${repoWithOwner}'`)
27+
core.debug(`Input: 'screenshot_repository: ${screenshotRepo}'`)
28+
core.debug(`Input: 'cached_filings: ${JSON.stringify(cachedFilings)}'`)
3329

3430
const octokit = new OctokitWithThrottling({
3531
auth: token,
@@ -61,8 +57,9 @@ export default async function () {
6157
filing.issue.state = 'closed'
6258
} else if (isNewFiling(filing)) {
6359
// Open a new issue for the filing
64-
response = await openIssue(octokit, repoWithOwner, filing.findings[0], screenshotRepo);
65-
(filing as any).issue = { state: "open" } as Issue;
60+
response = await openIssue(octokit, repoWithOwner, filing.findings[0], screenshotRepo)
61+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
62+
;(filing as any).issue = {state: 'open'} as Issue
6663
} else if (isRepeatedFiling(filing)) {
6764
// Reopen the filing's issue (if necessary) and update the body with the latest finding
6865
response = await reopenIssue(
@@ -71,8 +68,8 @@ export default async function () {
7168
filing.findings[0],
7269
repoWithOwner,
7370
screenshotRepo,
74-
);
75-
filing.issue.state = "reopened";
71+
)
72+
filing.issue.state = 'reopened'
7673
}
7774
if (response?.data && filing.issue) {
7875
// Update the filing with the latest issue data

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ function truncateWithEllipsis(text: string, maxLength: number): string {
1818
}
1919

2020
export async function openIssue(octokit: Octokit, repoWithOwner: string, finding: Finding, screenshotRepo?: string) {
21-
const owner = repoWithOwner.split('/')[0];
22-
const repo = repoWithOwner.split('/')[1];
21+
const owner = repoWithOwner.split('/')[0]
22+
const repo = repoWithOwner.split('/')[1]
2323

2424
const labels = [`${finding.scannerType} rule: ${finding.ruleId}`, `${finding.scannerType}-scanning-issue`]
2525
const title = truncateWithEllipsis(
2626
`Accessibility issue: ${finding.problemShort[0].toUpperCase() + finding.problemShort.slice(1)} on ${new URL(finding.url).pathname}`,
2727
GITHUB_ISSUE_TITLE_MAX_LENGTH,
2828
)
2929

30-
const body = generateIssueBody(finding, screenshotRepo ?? repoWithOwner);
30+
const body = generateIssueBody(finding, screenshotRepo ?? repoWithOwner)
3131

3232
return octokit.request(`POST /repos/${owner}/${repo}/issues`, {
3333
owner,
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
1-
import type { Octokit } from '@octokit/core';
2-
import type { Issue } from './Issue.js';
3-
import type { Finding } from "./types.d.js";
4-
import { generateIssueBody } from "./generateIssueBody.js";
1+
import type {Octokit} from '@octokit/core'
2+
import type {Issue} from './Issue.js'
3+
import type {Finding} from './types.d.js'
4+
import {generateIssueBody} from './generateIssueBody.js'
55

66
export async function reopenIssue(
77
octokit: Octokit,
8-
{ owner, repository, issueNumber }: Issue,
8+
{owner, repository, issueNumber}: Issue,
99
finding?: Finding,
1010
repoWithOwner?: string,
1111
screenshotRepo?: string,
1212
) {
13-
let body = {};
13+
let body = {}
1414
if (finding && repoWithOwner) {
1515
body = {
1616
body: generateIssueBody(finding, screenshotRepo ?? repoWithOwner),
17-
};
17+
}
1818
}
1919

20-
return octokit.request(
21-
`PATCH /repos/${owner}/${repository}/issues/${issueNumber}`,
22-
{
23-
owner,
24-
repository,
25-
issue_number: issueNumber,
26-
state: "open",
27-
...body,
28-
},
29-
);
20+
return octokit.request(`PATCH /repos/${owner}/${repository}/issues/${issueNumber}`, {
21+
owner,
22+
repository,
23+
issue_number: issueNumber,
24+
state: 'open',
25+
...body,
26+
})
3027
}

.github/actions/file/src/types.d.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
export type Finding = {
2-
scannerType: string;
3-
ruleId: string;
4-
url: string;
5-
html: string;
6-
problemShort: string;
7-
problemUrl: string;
8-
solutionShort: string;
9-
solutionLong?: string;
10-
screenshotId?: string;
11-
};
2+
scannerType: string
3+
ruleId: string
4+
url: string
5+
html: string
6+
problemShort: string
7+
problemUrl: string
8+
solutionShort: string
9+
solutionLong?: string
10+
screenshotId?: string
11+
}
1212

1313
export type Issue = {
1414
id: number

.github/actions/file/tests/generateIssueBody.test.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,21 @@ describe('generateIssueBody', () => {
4444
expect(body).toContain('Fix all of the following:')
4545
expect(body).toContain('- Add a non-color visual indicator.')
4646

47-
expect(body).not.toContain("- Fix any of the following:");
48-
expect(body).not.toContain("- Fix all of the following:");
49-
});
47+
expect(body).not.toContain('- Fix any of the following:')
48+
expect(body).not.toContain('- Fix all of the following:')
49+
})
5050

51-
it("uses the screenshotRepo for the screenshot URL, not the filing repo", () => {
52-
const body = generateIssueBody(
53-
{ ...baseFinding, screenshotId: "abc123" },
54-
"github/my-workflow-repo",
55-
);
51+
it('uses the screenshotRepo for the screenshot URL, not the filing repo', () => {
52+
const body = generateIssueBody({...baseFinding, screenshotId: 'abc123'}, 'github/my-workflow-repo')
5653

57-
expect(body).toContain("github/my-workflow-repo/blob/gh-cache/.screenshots/abc123.png");
58-
expect(body).not.toContain("github/accessibility-scanner");
59-
});
54+
expect(body).toContain('github/my-workflow-repo/blob/gh-cache/.screenshots/abc123.png')
55+
expect(body).not.toContain('github/accessibility-scanner')
56+
})
6057

61-
it("omits screenshot section when screenshotId is not present", () => {
62-
const body = generateIssueBody(baseFinding, "github/accessibility-scanner");
58+
it('omits screenshot section when screenshotId is not present', () => {
59+
const body = generateIssueBody(baseFinding, 'github/accessibility-scanner')
6360

64-
expect(body).not.toContain("View screenshot");
65-
expect(body).not.toContain(".screenshots");
66-
});
67-
});
61+
expect(body).not.toContain('View screenshot')
62+
expect(body).not.toContain('.screenshots')
63+
})
64+
})
Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,80 @@
1-
import { describe, it, expect, vi } from "vitest";
1+
import {describe, it, expect, vi} from 'vitest'
22

33
// Mock generateIssueBody so we can inspect what screenshotRepo is passed
4-
vi.mock("../src/generateIssueBody.js", () => ({
5-
generateIssueBody: vi.fn(
6-
(_finding, screenshotRepo: string) =>
7-
`body with screenshotRepo=${screenshotRepo}`,
8-
),
9-
}));
4+
vi.mock('../src/generateIssueBody.js', () => ({
5+
generateIssueBody: vi.fn((_finding, screenshotRepo: string) => `body with screenshotRepo=${screenshotRepo}`),
6+
}))
107

11-
import { openIssue } from "../src/openIssue.ts";
12-
import { generateIssueBody } from "../src/generateIssueBody.ts";
8+
import {openIssue} from '../src/openIssue.ts'
9+
import {generateIssueBody} from '../src/generateIssueBody.ts'
1310

1411
const baseFinding = {
15-
scannerType: "axe",
16-
ruleId: "color-contrast",
17-
url: "https://example.com/page",
18-
html: "<span>Low contrast</span>",
19-
problemShort: "elements must meet minimum color contrast ratio thresholds",
20-
problemUrl:
21-
"https://dequeuniversity.com/rules/axe/4.10/color-contrast?application=playwright",
22-
solutionShort:
23-
"ensure the contrast between foreground and background colors meets WCAG thresholds",
24-
};
12+
scannerType: 'axe',
13+
ruleId: 'color-contrast',
14+
url: 'https://example.com/page',
15+
html: '<span>Low contrast</span>',
16+
problemShort: 'elements must meet minimum color contrast ratio thresholds',
17+
problemUrl: 'https://dequeuniversity.com/rules/axe/4.10/color-contrast?application=playwright',
18+
solutionShort: 'ensure the contrast between foreground and background colors meets WCAG thresholds',
19+
}
2520

2621
function mockOctokit() {
2722
return {
28-
request: vi.fn().mockResolvedValue({ data: { id: 1, html_url: "https://github.com/org/repo/issues/1" } }),
29-
} as any;
23+
request: vi.fn().mockResolvedValue({data: {id: 1, html_url: 'https://github.com/org/repo/issues/1'}}),
24+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
25+
} as any
3026
}
3127

32-
describe("openIssue", () => {
33-
it("passes screenshotRepo to generateIssueBody when provided", async () => {
34-
const octokit = mockOctokit();
35-
await openIssue(octokit, "org/filing-repo", baseFinding, "org/workflow-repo");
28+
describe('openIssue', () => {
29+
it('passes screenshotRepo to generateIssueBody when provided', async () => {
30+
const octokit = mockOctokit()
31+
await openIssue(octokit, 'org/filing-repo', baseFinding, 'org/workflow-repo')
3632

37-
expect(generateIssueBody).toHaveBeenCalledWith(baseFinding, "org/workflow-repo");
38-
});
33+
expect(generateIssueBody).toHaveBeenCalledWith(baseFinding, 'org/workflow-repo')
34+
})
3935

40-
it("falls back to repoWithOwner when screenshotRepo is not provided", async () => {
41-
const octokit = mockOctokit();
42-
await openIssue(octokit, "org/filing-repo", baseFinding);
36+
it('falls back to repoWithOwner when screenshotRepo is not provided', async () => {
37+
const octokit = mockOctokit()
38+
await openIssue(octokit, 'org/filing-repo', baseFinding)
4339

44-
expect(generateIssueBody).toHaveBeenCalledWith(baseFinding, "org/filing-repo");
45-
});
40+
expect(generateIssueBody).toHaveBeenCalledWith(baseFinding, 'org/filing-repo')
41+
})
4642

47-
it("posts to the correct filing repo, not the screenshot repo", async () => {
48-
const octokit = mockOctokit();
49-
await openIssue(octokit, "org/filing-repo", baseFinding, "org/workflow-repo");
43+
it('posts to the correct filing repo, not the screenshot repo', async () => {
44+
const octokit = mockOctokit()
45+
await openIssue(octokit, 'org/filing-repo', baseFinding, 'org/workflow-repo')
5046

5147
expect(octokit.request).toHaveBeenCalledWith(
52-
"POST /repos/org/filing-repo/issues",
48+
'POST /repos/org/filing-repo/issues',
5349
expect.objectContaining({
54-
owner: "org",
55-
repo: "filing-repo",
50+
owner: 'org',
51+
repo: 'filing-repo',
5652
}),
57-
);
58-
});
53+
)
54+
})
5955

60-
it("includes the correct labels based on the finding", async () => {
61-
const octokit = mockOctokit();
62-
await openIssue(octokit, "org/repo", baseFinding);
56+
it('includes the correct labels based on the finding', async () => {
57+
const octokit = mockOctokit()
58+
await openIssue(octokit, 'org/repo', baseFinding)
6359

6460
expect(octokit.request).toHaveBeenCalledWith(
6561
expect.any(String),
6662
expect.objectContaining({
67-
labels: ["axe rule: color-contrast", "axe-scanning-issue"],
63+
labels: ['axe rule: color-contrast', 'axe-scanning-issue'],
6864
}),
69-
);
70-
});
65+
)
66+
})
7167

72-
it("truncates long titles with ellipsis", async () => {
73-
const octokit = mockOctokit();
68+
it('truncates long titles with ellipsis', async () => {
69+
const octokit = mockOctokit()
7470
const longFinding = {
7571
...baseFinding,
76-
problemShort: "a".repeat(300),
77-
};
78-
await openIssue(octokit, "org/repo", longFinding);
72+
problemShort: 'a'.repeat(300),
73+
}
74+
await openIssue(octokit, 'org/repo', longFinding)
7975

80-
const callArgs = octokit.request.mock.calls[0][1];
81-
expect(callArgs.title.length).toBeLessThanOrEqual(256);
82-
expect(callArgs.title).toMatch(/$/);
83-
});
84-
});
76+
const callArgs = octokit.request.mock.calls[0][1]
77+
expect(callArgs.title.length).toBeLessThanOrEqual(256)
78+
expect(callArgs.title).toMatch(/$/)
79+
})
80+
})

0 commit comments

Comments
 (0)