Skip to content

Commit 01dae6e

Browse files
authored
feat: Refactor into a composite action (#8)
Fixes github/accessibility#9221 (Hubber access only) This PR migrates to a composite action, with no user-facing changes—the main public action takes the same inputs as before, and it performs the same tasks. This PR adds 3 new public actions (‘find’, ‘file’, and ‘fix’) inside the `.github/actions` subdirectory. Each of these can be run by itself, without the others, as long as its required inputs are supplied. This increases flexibility; for example, a user with scanning automations already in place could leverage just the ‘file’ and ‘fix’ actions. To test, I ran this branch’s code (excluding github-community-projects/continuous-ai-for-accessibility-scanner@9e6b693) in https://github.com/github/accessibility-sandbox/actions/runs/16734265309/job/47369451800 (Hubber access only), which created github/accessibility-sandbox#4355 (Hubber access only).
2 parents 7ab62ae + 9e6b693 commit 01dae6e

29 files changed

+878
-136
lines changed

.github/actions/file/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# file
2+
3+
Files GitHub issues to track potential accessibility gaps.
4+
5+
## Usage
6+
7+
### Inputs
8+
9+
#### `findings`
10+
11+
**Required** List of potential accessibility gaps, as stringified JSON. For example:
12+
13+
```JS
14+
'[]'
15+
```
16+
17+
#### `repository`
18+
19+
**Required** Repository (with owner) to file issues in. For example: `primer/primer-docs`.
20+
21+
#### `token`
22+
23+
**Required** Token with fine-grained permission 'issues: write'.
24+
25+
### Outputs
26+
27+
#### `issue_numbers`
28+
29+
List of issue numbers for created issues, as stringified JSON. For example: `'[123, 124, 126, 127]'`.

.github/actions/file/action.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: "File"
2+
description: "Files GitHub issues to track potential accessibility gaps."
3+
4+
inputs:
5+
findings:
6+
description: "List of potential accessibility gaps, as stringified JSON"
7+
required: true
8+
repository:
9+
description: "Repository (with owner) to file issues in"
10+
required: true
11+
token:
12+
description: "Token with fine-grained permission 'issues: write'"
13+
required: true
14+
15+
outputs:
16+
issue_numbers:
17+
description: "List of issue numbers for created issues, as stringified JSON"
18+
19+
runs:
20+
using: "node20"
21+
main: "bootstrap.js"
22+
23+
branding:
24+
icon: "compass"
25+
color: "blue"
Lines changed: 13 additions & 80 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/file/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "file",
3+
"version": "1.0.0",
4+
"description": "Files GitHub issues to track potential accessibility gaps.",
5+
"main": "dist/index.js",
6+
"module": "dist/index.js",
7+
"scripts": {
8+
"start": "node bootstrap.js",
9+
"build": "tsc"
10+
},
11+
"keywords": [],
12+
"author": "GitHub",
13+
"license": "MIT",
14+
"type": "module",
15+
"dependencies": {
16+
"@actions/core": "^1.11.1",
17+
"@octokit/core": "^7.0.3"
18+
},
19+
"devDependencies": {
20+
"@types/node": "^24.1.0",
21+
"typescript": "^5.8.3"
22+
}
23+
}

src/fileIssueForResult.ts renamed to .github/actions/file/src/fileIssueForFinding.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { Octokit } from '@octokit/core';
2-
import type { Result } from './types.d.js';
2+
import type { Finding } from './types.d.js';
33
import * as url from 'node:url'
44
const URL = url.URL;
55

6-
export async function fileIssueForResult(octokit: Octokit, repoWithOwner: string, result: Result) {
6+
export async function fileIssueForFinding(octokit: Octokit, repoWithOwner: string, finding: Finding) {
77
const owner = repoWithOwner.split('/')[0];
88
const repo = repoWithOwner.split('/')[1];
9-
const title = `Accessibility issue: ${result.problemShort[0].toUpperCase() + result.problemShort.slice(1)} on ${new URL(result.url).pathname}`;
10-
const solutionLong = result.solutionLong
9+
const title = `Accessibility issue: ${finding.problemShort[0].toUpperCase() + finding.problemShort.slice(1)} on ${new URL(finding.url).pathname}`;
10+
const solutionLong = finding.solutionLong
1111
?.split("\n")
1212
.map((line) =>
1313
!line.trim().startsWith("Fix any") &&
@@ -18,9 +18,9 @@ export async function fileIssueForResult(octokit: Octokit, repoWithOwner: string
1818
)
1919
.join("\n");
2020
const body = `
21-
An accessibility scan flagged the element \`${result.html}\` on ${result.url} because ${result.problemShort}. Learn more about why this was flagged by visiting ${result.problemUrl}.
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}.
2222
23-
To fix this, ${result.solutionShort}.
23+
To fix this, ${finding.solutionShort}.
2424
${solutionLong ? `\nSpecifically:\n\n${solutionLong}` : ''}
2525
`;
2626

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Finding } from "./types.d.js";
2+
import core from "@actions/core";
3+
import { Octokit } from '@octokit/core';
4+
import { fileIssueForFinding } from "./fileIssueForFinding.js";
5+
6+
export default async function () {
7+
const findings: Finding[] = JSON.parse(core.getInput('findings', { required: true }));
8+
const repoWithOwner = core.getInput('repository', { required: true });
9+
const token = core.getInput('token', { required: true });
10+
11+
const issueNumbers = [];
12+
const octokit = new Octokit({ auth: token });
13+
for (const finding of findings) {
14+
const response = await fileIssueForFinding(octokit, repoWithOwner, finding);
15+
issueNumbers.push(response.data.number);
16+
console.log(`Created issue: ${response.data.title} (${repoWithOwner}#${response.data.number})`);
17+
}
18+
19+
core.setOutput("issue_numbers", JSON.stringify(issueNumbers));
20+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type Result = {
1+
export type Finding = {
22
url: string;
33
html: string;
44
problemShort: string;

.github/actions/find/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# find
2+
3+
Finds potential accessibility gaps.
4+
5+
## Usage
6+
7+
### Inputs
8+
9+
#### `urls`
10+
11+
**Required** Newline-delimited list of URLs to check for accessibility issues. For example:
12+
13+
```txt
14+
https://primer.style
15+
https://primer.style/octicons/
16+
```
17+
18+
### Outputs
19+
20+
#### `findings`
21+
22+
List of potential accessibility gaps, as stringified JSON. For example:
23+
24+
```JS
25+
'[]'
26+
```

0 commit comments

Comments
 (0)