Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions source/features/actionable-pr-view-file.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {$} from 'select-dom/strict.js';
import {elementExists} from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '../feature-manager.js';
import {getBranches} from '../github-helpers/pr-branches.js';
import observe from '../helpers/selector-observer.js';
import {deletedHeadRepository} from '../github-helpers/selectors.js';

/** Rebuilds the "View file" link because it points to the base repo and to the commit, instead of the head repo and its branch */
function alter(viewFileLink: HTMLAnchorElement): void {
Expand All @@ -26,7 +26,7 @@ void features.add(import.meta.url, {
exclude: [
// Editing files doesn't make sense after a PR is closed/merged
pageDetect.isClosedConversation,
() => $('.head-ref').title === 'This repository has been deleted',
() => elementExists(deletedHeadRepository),
// If you're viewing changes from partial commits, ensure you're on the latest one.
() => elementExists('.js-commits-filtered') && !elementExists('[aria-label="You are viewing the latest commit"]'),
],
Expand All @@ -38,6 +38,7 @@ void features.add(import.meta.url, {

Test URLs

https://github.com/refined-github/sandbox/pull/4/files
- PR: https://github.com/refined-github/sandbox/pull/4/files
- deleted head repository: https://github.com/refined-github/refined-github/pull/271

*/
7 changes: 4 additions & 3 deletions source/features/pr-base-commit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'dom-chef';
import {$} from 'select-dom/strict.js';
import * as pageDetect from 'github-url-detection';

import {elementExists} from 'select-dom';

import features from '../feature-manager.js';
import observe from '../helpers/selector-observer.js';
import {getBranches} from '../github-helpers/pr-branches.js';
Expand All @@ -11,7 +12,7 @@ import {buildRepoURL} from '../github-helpers/index.js';
import {linkifyCommit} from '../github-helpers/dom-formatters.js';
import {isTextNodeContaining} from '../helpers/dom-utils.js';
import {expectToken} from '../github-helpers/github-token.js';
import {prMergeabilityBoxCaption} from '../github-helpers/selectors.js';
import {deletedHeadRepository, prMergeabilityBoxCaption} from '../github-helpers/selectors.js';

function getBaseCommitNotice(prInfo: PullRequestInfo): JSX.Element {
const {base} = getBranches();
Expand Down Expand Up @@ -57,7 +58,7 @@ void features.add(import.meta.url, {
],
exclude: [
pageDetect.isClosedConversation,
() => $('.head-ref').title === 'This repository has been deleted',
() => elementExists(deletedHeadRepository),
],
awaitDomReady: true, // DOM-based exclusions
init,
Expand Down
4 changes: 2 additions & 2 deletions source/features/update-pr-from-base-branch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import showToast from '../github-helpers/toast.js';
import {getConversationNumber, getRepo} from '../github-helpers/index.js';
import createMergeabilityRow from '../github-widgets/mergeability-row.js';
import {expectToken} from '../github-helpers/github-token.js';
import {prMergeabilityBoxCaption} from '../github-helpers/selectors.js';
import {deletedHeadRepository, prMergeabilityBoxCaption} from '../github-helpers/selectors.js';

// TODO: Use CachedMap after https://github.com/fregante/webext-storage-cache/issues/51
const nativeRepos = new CachedFunction('native-update-button', {
Expand Down Expand Up @@ -165,7 +165,7 @@ void features.add(import.meta.url, {
],
exclude: [
pageDetect.isClosedConversation,
() => $('.head-ref').title === 'This repository has been deleted',
() => elementExists(deletedHeadRepository),
],
awaitDomReady: true, // DOM-based exclusions
init,
Expand Down
18 changes: 14 additions & 4 deletions source/github-helpers/pr-branches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,27 @@ export function parseReferenceRaw(absolute: string, relative: string): PrReferen
}

function parseReference(referenceElement: HTMLElement): PrReference {
const {title, textContent} = referenceElement;
return parseReferenceRaw(title, textContent.trim());
const {title, textContent, nextElementSibling} = referenceElement;

// In the React version, we have a `title` attribute but it's used to mark deleted repos instead
return title && title !== 'This repository has been deleted'
? parseReferenceRaw(title, textContent.trim()) // TODO: Remove in June 2026
: parseReferenceRaw(nextElementSibling!.textContent.trim(), textContent.trim());
}

export function getBranches(): {base: PrReference; head: PrReference} {
return {
get base() {
return parseReference($('.base-ref'));
return parseReference($([
'[class*="PullRequestHeaderSummary"] > [class*="PullRequestHeaderSummary"]',
'.base-ref', // TODO: Remove in June 2026
]));
},
get head() {
return parseReference($('.head-ref'));
return parseReference($([
'[class*="PullRequestHeaderSummary"] * [class*="PullRequestHeaderSummary"]',
'.head-ref', // TODO: Remove in June 2026
]));
},
};
}
10 changes: 10 additions & 0 deletions source/github-helpers/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,13 @@ export const actionBarSelectors = [

export const prMergeabilityBoxCaption = '[aria-label="Conflicts"] [class^="MergeBoxSectionHeader-module__wrapper"] h3 + .fgColor-muted';
export const prMergeabilityBoxCaption_ = requiresLogin;

export const deletedHeadRepository = [
'span[title="This repository has been deleted"]',
'.head-ref[title="This repository has been deleted"]', // TODO: Remove in June 2026
];

export const deletedHeadRepository_ = [
[1, 'https://github.com/refined-github/refined-github/pull/271'],
[1, 'https://github.com/refined-github/refined-github/pull/271/files'],
];