import React from 'dom-chef'; import {$, elementExists} from 'select-dom'; import * as pageDetect from 'github-url-detection'; import features from '../feature-manager.js'; import getDefaultBranch, {defaultBranchOfRepo} from '../github-helpers/get-default-branch.js'; import {getRepo} from '../github-helpers/index.js'; async function init(): Promise { let defaultBranch; if (elementExists('.is-cross-repo')) { const forkedRepository = getRepo($('[title^="head: "]')!.textContent)!; defaultBranch = await defaultBranchOfRepo.get(forkedRepository); } else { defaultBranch = await getDefaultBranch(); } // Expected: /user/repo/compare/master...user:master if (!location.pathname.endsWith(':' + defaultBranch)) { return false; } $('.js-compare-pr')!.before(
Note: Creating a PR from the default branch is an anti-pattern.
, ); } void features.add(import.meta.url, { include: [ pageDetect.isCompare, ], exclude: [ pageDetect.isBlank, ], awaitDomReady: true, deduplicate: 'has-rgh', init, });