-
Notifications
You must be signed in to change notification settings - Fork 21
Adds links to screenshots when include_screenshots is true
#137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
14a7ae9
Adds screenshots to issues
lindseywild 177a78a
Updates to wait until DOMContentLoaded, moves Axe scan
lindseywild 7b42fca
Fixes markdown
lindseywild ae45dcd
Fixes screenshot location
lindseywild c7fa1f5
Moves axe builder back
lindseywild e7ace49
Updates save action
lindseywild 706e363
Ensures re-opened issues are updated
lindseywild dba8913
Updates action
lindseywild b3430a2
Changes screenshot to link
lindseywild 4618a36
Removes duplicate save workflow
lindseywild 6d230de
Attempt to fix matrix gh-cache push
lindseywild 3420115
Removes gh-cache updates
lindseywild d462476
Adds screenshot repo to ensure we are targeting the correct gh-cache …
lindseywild c4fbd5b
Minor tweaks after initial code review
lindseywild a5b6a29
Adds additional tests
lindseywild b150539
Merge branch 'main' into adds-screenshots
lindseywild e28ed11
Updates site-with-errors test
lindseywild 7cfce7c
Updates test
lindseywild e2bf89a
Adds crypto import
lindseywild 4f3fa07
Initial updates from PR review
lindseywild 4dd03c7
Removes page.waitForLoadState
lindseywild 0fbb9d7
Extracts generareScreenshots into another function
lindseywild 124d17c
Fixes naming
lindseywild dfc8c4b
Updates ternary
lindseywild 7131561
Merge branch 'main' into adds-screenshots
lindseywild a0e058e
Formatting / linting
lindseywild f03c192
Changes include_screenshots from true to false
lindseywild 51b0cc5
Updates README
lindseywild 035975f
Update tests
lindseywild 8dee19c
Fixes bad semi
lindseywild 594d6b6
Removes extra tests
lindseywild 0b1f891
Removes silly destructure
lindseywild File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,25 @@ | ||
| import type {Octokit} from '@octokit/core' | ||
| import type {Issue} from './Issue.js' | ||
| import type {Finding} from './types.d.js' | ||
| import {generateIssueBody} from './generateIssueBody.js' | ||
|
|
||
| export async function reopenIssue( | ||
| octokit: Octokit, | ||
| {owner, repository, issueNumber}: Issue, | ||
| finding?: Finding, | ||
| repoWithOwner?: string, | ||
| screenshotRepo?: string, | ||
| ) { | ||
| let body: string | undefined | ||
| if (finding && repoWithOwner) { | ||
| body = generateIssueBody(finding, screenshotRepo ?? repoWithOwner) | ||
| } | ||
|
|
||
| export async function reopenIssue(octokit: Octokit, {owner, repository, issueNumber}: Issue) { | ||
| return octokit.request(`PATCH /repos/${owner}/${repository}/issues/${issueNumber}`, { | ||
| owner, | ||
| repository, | ||
| issue_number: issueNumber, | ||
| state: 'open', | ||
| body, | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import {describe, it, expect, vi} from 'vitest' | ||
|
|
||
| // Mock generateIssueBody so we can inspect what screenshotRepo is passed | ||
| vi.mock('../src/generateIssueBody.js', () => ({ | ||
| generateIssueBody: vi.fn((_finding, screenshotRepo: string) => `body with screenshotRepo=${screenshotRepo}`), | ||
| })) | ||
|
|
||
| import {openIssue} from '../src/openIssue.ts' | ||
| import {generateIssueBody} from '../src/generateIssueBody.ts' | ||
|
|
||
| const baseFinding = { | ||
| scannerType: 'axe', | ||
| ruleId: 'color-contrast', | ||
| url: 'https://example.com/page', | ||
| html: '<span>Low contrast</span>', | ||
| problemShort: 'elements must meet minimum color contrast ratio thresholds', | ||
| problemUrl: 'https://dequeuniversity.com/rules/axe/4.10/color-contrast?application=playwright', | ||
| solutionShort: 'ensure the contrast between foreground and background colors meets WCAG thresholds', | ||
| } | ||
|
|
||
| function mockOctokit() { | ||
| return { | ||
| request: vi.fn().mockResolvedValue({data: {id: 1, html_url: 'https://github.com/org/repo/issues/1'}}), | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| } as any | ||
| } | ||
|
|
||
| describe('openIssue', () => { | ||
| it('passes screenshotRepo to generateIssueBody when provided', async () => { | ||
| const octokit = mockOctokit() | ||
| await openIssue(octokit, 'org/filing-repo', baseFinding, 'org/workflow-repo') | ||
|
|
||
| expect(generateIssueBody).toHaveBeenCalledWith(baseFinding, 'org/workflow-repo') | ||
| }) | ||
|
|
||
| it('falls back to repoWithOwner when screenshotRepo is not provided', async () => { | ||
| const octokit = mockOctokit() | ||
| await openIssue(octokit, 'org/filing-repo', baseFinding) | ||
|
|
||
| expect(generateIssueBody).toHaveBeenCalledWith(baseFinding, 'org/filing-repo') | ||
| }) | ||
|
|
||
| it('posts to the correct filing repo, not the screenshot repo', async () => { | ||
| const octokit = mockOctokit() | ||
| await openIssue(octokit, 'org/filing-repo', baseFinding, 'org/workflow-repo') | ||
|
|
||
| expect(octokit.request).toHaveBeenCalledWith( | ||
| 'POST /repos/org/filing-repo/issues', | ||
| expect.objectContaining({ | ||
| owner: 'org', | ||
| repo: 'filing-repo', | ||
| }), | ||
| ) | ||
| }) | ||
|
|
||
| it('includes the correct labels based on the finding', async () => { | ||
| const octokit = mockOctokit() | ||
| await openIssue(octokit, 'org/repo', baseFinding) | ||
|
|
||
| expect(octokit.request).toHaveBeenCalledWith( | ||
| expect.any(String), | ||
| expect.objectContaining({ | ||
| labels: ['axe rule: color-contrast', 'axe-scanning-issue'], | ||
| }), | ||
| ) | ||
| }) | ||
|
|
||
| it('truncates long titles with ellipsis', async () => { | ||
| const octokit = mockOctokit() | ||
| const longFinding = { | ||
| ...baseFinding, | ||
| problemShort: 'a'.repeat(300), | ||
| } | ||
| await openIssue(octokit, 'org/repo', longFinding) | ||
|
|
||
| const callArgs = octokit.request.mock.calls[0][1] | ||
| expect(callArgs.title.length).toBeLessThanOrEqual(256) | ||
| expect(callArgs.title).toMatch(/…$/) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import {describe, it, expect, vi, beforeEach} from 'vitest' | ||
|
|
||
| // Mock generateIssueBody so we can inspect what screenshotRepo is passed | ||
| vi.mock('../src/generateIssueBody.js', () => ({ | ||
| generateIssueBody: vi.fn((_finding, screenshotRepo: string) => `body with screenshotRepo=${screenshotRepo}`), | ||
| })) | ||
|
|
||
| import {reopenIssue} from '../src/reopenIssue.ts' | ||
| import {generateIssueBody} from '../src/generateIssueBody.ts' | ||
| import {Issue} from '../src/Issue.ts' | ||
|
|
||
| const baseFinding = { | ||
| scannerType: 'axe', | ||
| ruleId: 'color-contrast', | ||
| url: 'https://example.com/page', | ||
| html: '<span>Low contrast</span>', | ||
| problemShort: 'elements must meet minimum color contrast ratio thresholds', | ||
| problemUrl: 'https://dequeuniversity.com/rules/axe/4.10/color-contrast?application=playwright', | ||
| solutionShort: 'ensure the contrast between foreground and background colors meets WCAG thresholds', | ||
| } | ||
|
|
||
| const testIssue = new Issue({ | ||
| id: 42, | ||
| nodeId: 'MDU6SXNzdWU0Mg==', | ||
| url: 'https://github.com/org/filing-repo/issues/7', | ||
| title: 'Accessibility issue: test', | ||
| state: 'closed', | ||
| }) | ||
|
|
||
| function mockOctokit() { | ||
| return { | ||
| request: vi.fn().mockResolvedValue({data: {id: 42, html_url: 'https://github.com/org/filing-repo/issues/7'}}), | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| } as any | ||
| } | ||
|
|
||
| describe('reopenIssue', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| it('passes screenshotRepo to generateIssueBody when provided', async () => { | ||
| const octokit = mockOctokit() | ||
| await reopenIssue(octokit, testIssue, baseFinding, 'org/filing-repo', 'org/workflow-repo') | ||
|
|
||
| expect(generateIssueBody).toHaveBeenCalledWith(baseFinding, 'org/workflow-repo') | ||
| }) | ||
|
|
||
| it('falls back to repoWithOwner when screenshotRepo is not provided', async () => { | ||
| const octokit = mockOctokit() | ||
| await reopenIssue(octokit, testIssue, baseFinding, 'org/filing-repo') | ||
|
|
||
| expect(generateIssueBody).toHaveBeenCalledWith(baseFinding, 'org/filing-repo') | ||
| }) | ||
|
|
||
| it('does not generate a body when finding is not provided', async () => { | ||
| const octokit = mockOctokit() | ||
| await reopenIssue(octokit, testIssue) | ||
|
|
||
| expect(generateIssueBody).not.toHaveBeenCalled() | ||
| expect(octokit.request).toHaveBeenCalledWith( | ||
| expect.any(String), | ||
| expect.not.objectContaining({body: expect.anything()}), | ||
| ) | ||
| }) | ||
|
|
||
| it('does not generate a body when repoWithOwner is not provided', async () => { | ||
| const octokit = mockOctokit() | ||
| await reopenIssue(octokit, testIssue, baseFinding) | ||
|
|
||
| expect(generateIssueBody).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('sends PATCH to the correct issue URL with state open', async () => { | ||
| const octokit = mockOctokit() | ||
| await reopenIssue(octokit, testIssue, baseFinding, 'org/filing-repo', 'org/workflow-repo') | ||
|
|
||
| expect(octokit.request).toHaveBeenCalledWith( | ||
| 'PATCH /repos/org/filing-repo/issues/7', | ||
| expect.objectContaining({ | ||
| state: 'open', | ||
| issue_number: 7, | ||
| }), | ||
| ) | ||
| }) | ||
|
|
||
| it('includes generated body when finding and repoWithOwner are provided', async () => { | ||
| const octokit = mockOctokit() | ||
| await reopenIssue(octokit, testIssue, baseFinding, 'org/filing-repo', 'org/workflow-repo') | ||
|
|
||
| expect(octokit.request).toHaveBeenCalledWith( | ||
| expect.any(String), | ||
| expect.objectContaining({ | ||
| body: 'body with screenshotRepo=org/workflow-repo', | ||
| }), | ||
| ) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prettier / eslint cleanup -- I have it installed locally on VSCode so you may see some unrelated changes that are purely linting. Once we add eslint/Prettier in this repo it will be updated if it doesn't follow suit with the guidelines anyway.