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