diff options
author | 2023-05-21 02:40:32 +0800 | |
---|---|---|
committer | 2023-05-21 02:40:32 +0800 | |
commit | 32e458ceda0607f6692cef01c68b9af57c826c6e (patch) | |
tree | f077067f06d1002eb768ebe7581540e1f9c86fad | |
parent | 7f6b216506e3e10743efb9b0ea2814d3b43a9270 (diff) | |
download | refined-github-32e458ceda0607f6692cef01c68b9af57c826c6e.tar.gz refined-github-32e458ceda0607f6692cef01c68b9af57c826c6e.tar.zst refined-github-32e458ceda0607f6692cef01c68b9af57c826c6e.zip |
Restore `wait-for-checks` (no more Firefox support) (#6673)23.5.20
-rwxr-xr-x | build/verify-test-urls.sh | 2 | ||||
-rw-r--r-- | source/features/wait-for-checks.tsx | 16 | ||||
-rw-r--r-- | source/github-helpers/pr-ci-status.ts | 13 | ||||
-rw-r--r-- | source/github-helpers/selectors.test.ts | 4 | ||||
-rw-r--r-- | source/github-helpers/selectors.ts | 16 |
5 files changed, 40 insertions, 11 deletions
diff --git a/build/verify-test-urls.sh b/build/verify-test-urls.sh index 42531907..8931d494 100755 --- a/build/verify-test-urls.sh +++ b/build/verify-test-urls.sh @@ -17,6 +17,8 @@ https://github.com/a/REAL/url/here https://github.com/another/REAL/url/here */ + +You can find or create a test URL on our sandbox repo: https://github.com/refined-github/sandbox " # Replace line breaks with "%0A" diff --git a/source/features/wait-for-checks.tsx b/source/features/wait-for-checks.tsx index c595fdcb..b1116731 100644 --- a/source/features/wait-for-checks.tsx +++ b/source/features/wait-for-checks.tsx @@ -14,6 +14,8 @@ import onPrMergePanelOpen from '../github-events/on-pr-merge-panel-open.js'; import {onPrMergePanelLoad} from '../github-events/on-fragment-load.js'; import onAbort from '../helpers/abort-controller.js'; import {userCanLikelyMergePR} from '../github-helpers/index.js'; +import {isHasSelectorSupported} from '../helpers/select-has.js'; +import {actionsTab, prCommitStatusIcon} from '../github-helpers/selectors.js'; // Reuse the same checkbox to preserve its status const generateCheckbox = onetime(() => ( @@ -43,7 +45,7 @@ function showCheckboxIfNecessary(): void { const isNecessary = lastCommitStatus === prCiStatus.PENDING // If the latest commit is missing an icon, add the checkbox as long as there's at least one CI icon on the page (including `ci-link`) - || (lastCommitStatus === false && select.exists(prCiStatus.commitStatusIconSelector)); + || (lastCommitStatus === false && select.exists(prCommitStatusIcon)); if (!checkbox && isNecessary) { select('.js-merge-form .select-menu')?.append(generateCheckbox()); @@ -181,10 +183,11 @@ function init(signal: AbortSignal): void { void features.add(import.meta.url, { asLongAs: [ + isHasSelectorSupported, userCanLikelyMergePR, pageDetect.isOpenPR, // The repo has enabled Actions - () => select.exists('#actions-tab'), + () => select.exists(actionsTab), ], include: [ pageDetect.isPRConversation, @@ -195,3 +198,12 @@ void features.add(import.meta.url, { awaitDomReady: true, // DOM-based inclusions init, }); + +/* + +Test URLs + +Checks: https://github.com/refined-github/sandbox/pull/12 +No Checks: https://github.com/refined-github/sandbox/pull/10 + +*/ diff --git a/source/github-helpers/pr-ci-status.ts b/source/github-helpers/pr-ci-status.ts index 09401bf7..e1a5cadc 100644 --- a/source/github-helpers/pr-ci-status.ts +++ b/source/github-helpers/pr-ci-status.ts @@ -1,24 +1,21 @@ import select from 'select-dom'; import api from './api.js'; +import {prCommit, prCommitStatusIcon} from './selectors.js'; export const SUCCESS = Symbol('Success'); export const FAILURE = Symbol('Failure'); export const PENDING = Symbol('Pending'); export type CommitStatus = false | typeof SUCCESS | typeof FAILURE | typeof PENDING; -export const commitSelector = '[data-test-selector="pr-timeline-commits-list"] .TimelineItem'; - -// `summary` is needed because the details dropdown contains the list of check runs, each with its status icon -export const commitStatusIconSelector = 'details.commit-build-statuses summary .octicon'; - export function getLastCommitReference(): string | undefined { - return select.last(`${commitSelector} code`)!.textContent ?? undefined; + return select.last(`${prCommit} code`)!.textContent ?? undefined; } export function getLastCommitStatus(): CommitStatus { - const lastCommit = select.last(commitSelector)!; - const lastCommitStatusIcon = lastCommit.querySelector(commitStatusIconSelector); + // Select the last commit first, THEN pick the icon, otherwise it might pick non-last commit while the CI is starting up + const lastCommit = select.last(prCommit)!; + const lastCommitStatusIcon = select(prCommitStatusIcon, lastCommit); // Some commits don't have a CI status icon at all if (lastCommitStatusIcon) { diff --git a/source/github-helpers/selectors.test.ts b/source/github-helpers/selectors.test.ts index 24eaef4e..7c42f276 100644 --- a/source/github-helpers/selectors.test.ts +++ b/source/github-helpers/selectors.test.ts @@ -22,7 +22,9 @@ describe.concurrent('selectors', () => { assert.isArray(urls, `No URLs defined for "${name}"`); await Promise.all(urls.map(async url => { const {window} = await fetchDocument(url); - assert.isDefined(window.document.querySelector(selector)); + // TODO: Drop replacement after https://github.com/jsdom/jsdom/issues/3506 + // It's not equivalent at the moment, but at least the tests don't fail. Let's see how it goes + assert.isDefined(window.document.querySelector(selector.replaceAll(':has', ':is'))); })); }, {timeout: 9999}); }); diff --git a/source/github-helpers/selectors.ts b/source/github-helpers/selectors.ts index 24663e43..681339b3 100644 --- a/source/github-helpers/selectors.ts +++ b/source/github-helpers/selectors.ts @@ -27,3 +27,19 @@ export const directoryListingFileIcon_ = [ 'https://github.com/refined-github/refined-github', 'https://github.com/refined-github/refined-github/tree/main/.github', ]; + +export const prCommit = '.TimelineItem--condensed:has(.octicon-git-commit)'; +export const prCommit_ = [ + 'https://github.com/refined-github/sandbox/pull/10', +]; + +// `summary` is needed because the details dropdown contains the list of check runs, each with its status icon +export const prCommitStatusIcon = `:is(${prCommit}) details.commit-build-statuses summary .octicon`; +export const prCommitStatusIcon_ = [ + 'https://github.com/refined-github/sandbox/pull/10', +]; + +export const actionsTab = '#actions-tab'; +export const actionsTab_ = [ + 'https://github.com/refined-github/sandbox', +]; |