Skip to content

Commit d462476

Browse files
committed
Adds screenshot repo to ensure we are targeting the correct gh-cache branch
1 parent 3420115 commit d462476

7 files changed

Lines changed: 31 additions & 6 deletions

File tree

.github/actions/file/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ inputs:
1414
cached_filings:
1515
description: "Cached filings from previous runs, as stringified JSON. Without this, duplicate issues may be filed."
1616
required: false
17+
screenshot_repo:
18+
description: "Repository (with owner) where screenshots are stored on the gh-cache branch. Defaults to the 'repository' input if not set."
19+
required: false
1720

1821
outputs:
1922
filings:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Finding } from "./types.d.js";
22

3-
export function generateIssueBody(finding: Finding, repoWithOwner: string): string {
3+
export function generateIssueBody(finding: Finding, screenshotRepo: string): string {
44
const solutionLong = finding.solutionLong
55
?.split("\n")
66
.map((line: string) =>
@@ -14,7 +14,7 @@ export function generateIssueBody(finding: Finding, repoWithOwner: string): stri
1414

1515
let screenshotSection;
1616
if (finding.screenshotId) {
17-
const screenshotUrl = `https://github.com/${repoWithOwner}/blob/gh-cache/.screenshots/${finding.screenshotId}.png`;
17+
const screenshotUrl = `https://github.com/${screenshotRepo}/blob/gh-cache/.screenshots/${finding.screenshotId}.png`;
1818
screenshotSection = `
1919
[View screenshot](${screenshotUrl})
2020
`;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ export default async function () {
2020
);
2121
const repoWithOwner = core.getInput("repository", { required: true });
2222
const token = core.getInput("token", { required: true });
23+
const screenshotRepo = core.getInput("screenshot_repo", { required: false }) || repoWithOwner;
2324
const cachedFilings: (ResolvedFiling | RepeatedFiling)[] = JSON.parse(
2425
core.getInput("cached_filings", { required: false }) || "[]"
2526
);
2627
core.debug(`Input: 'findings: ${JSON.stringify(findings)}'`);
2728
core.debug(`Input: 'repository: ${repoWithOwner}'`);
29+
core.debug(`Input: 'screenshot_repo: ${screenshotRepo}'`);
2830
core.debug(`Input: 'cached_filings: ${JSON.stringify(cachedFilings)}'`);
2931

3032
const octokit = new OctokitWithThrottling({
@@ -61,7 +63,7 @@ export default async function () {
6163
filing.issue.state = "closed";
6264
} else if (isNewFiling(filing)) {
6365
// Open a new issue for the filing
64-
response = await openIssue(octokit, repoWithOwner, filing.findings[0]);
66+
response = await openIssue(octokit, repoWithOwner, filing.findings[0], screenshotRepo);
6567
(filing as any).issue = { state: "open" } as Issue;
6668
} else if (isRepeatedFiling(filing)) {
6769
// Reopen the filing's issue (if necessary) and update the body with the latest finding
@@ -70,6 +72,7 @@ export default async function () {
7072
new Issue(filing.issue),
7173
filing.findings[0],
7274
repoWithOwner,
75+
screenshotRepo,
7376
);
7477
filing.issue.state = "reopened";
7578
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function truncateWithEllipsis(text: string, maxLength: number): string {
1717
return text.length > maxLength ? text.slice(0, maxLength - 1) + '…' : text;
1818
}
1919

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

@@ -27,7 +27,7 @@ export async function openIssue(octokit: Octokit, repoWithOwner: string, finding
2727
GITHUB_ISSUE_TITLE_MAX_LENGTH,
2828
);
2929

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

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

.github/actions/file/src/reopenIssue.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ export async function reopenIssue(
88
{ owner, repository, issueNumber }: Issue,
99
finding?: Finding,
1010
repoWithOwner?: string,
11+
screenshotRepo?: string,
1112
) {
1213
const body =
1314
finding && repoWithOwner
14-
? generateIssueBody(finding, repoWithOwner)
15+
? generateIssueBody(finding, screenshotRepo ?? repoWithOwner)
1516
: undefined;
1617
return octokit.request(
1718
`PATCH /repos/${owner}/${repository}/issues/${issueNumber}`,

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,21 @@ describe("generateIssueBody", () => {
4747
expect(body).not.toContain("- Fix any of the following:");
4848
expect(body).not.toContain("- Fix all of the following:");
4949
});
50+
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+
);
56+
57+
expect(body).toContain("github/my-workflow-repo/blob/gh-cache/.screenshots/abc123.png");
58+
expect(body).not.toContain("github/accessibility-scanner");
59+
});
60+
61+
it("omits screenshot section when screenshotId is not present", () => {
62+
const body = generateIssueBody(baseFinding, "github/accessibility-scanner");
63+
64+
expect(body).not.toContain("View screenshot");
65+
expect(body).not.toContain(".screenshots");
66+
});
5067
});

action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ runs:
9393
repository: ${{ inputs.repository }}
9494
token: ${{ inputs.token }}
9595
cached_filings: ${{ steps.normalize_cache.outputs.value }}
96+
screenshot_repo: ${{ github.repository }}
9697
- if: ${{ steps.file.outputs.filings }}
9798
name: Get issues from filings
9899
id: get_issues_from_filings

0 commit comments

Comments
 (0)