diff --git a/source/features/pr-notification-link.tsx b/source/features/pr-notification-link.tsx index 625b78865758..a4ebbd1d46d5 100644 --- a/source/features/pr-notification-link.tsx +++ b/source/features/pr-notification-link.tsx @@ -1,20 +1,20 @@ import * as pageDetect from 'github-url-detection'; +import {getCleanPathname} from '../github-helpers/index.js'; +import {commentBoxHashPr} from '../github-helpers/selectors.js'; import features from '../feature-manager.js'; import observe from '../helpers/selector-observer.js'; -const regex = /\/files\/[\da-f]{40}..[\da-f]{40}$/; - export function removeLinkToPrFilesTab(link: HTMLAnchorElement): void { - if (regex.test(link.pathname)) { - link.pathname = link.pathname.replace(regex, ''); - link.hash = '#issue-comment-box'; + if (pageDetect.isPRFiles(link)) { + // Owner + name + pull + number + link.pathname = getCleanPathname(link).split('/').slice(0, 4).join('/'); + link.hash = commentBoxHashPr; } } function init(signal: AbortSignal): void { - // It's ok if it's not 100% safe because trimLink's regex is super specific - observe('[href*="/pull/"][href*="/files/"][href*=".."]', removeLinkToPrFilesTab, {signal}); + observe('[href*="/pull/"][href*=".."]', removeLinkToPrFilesTab, {signal}); } void features.add(import.meta.url, {