summaryrefslogtreecommitdiff
path: root/source/features/warn-pr-from-master.tsx
blob: 2ede11ee2a2b40a8c9046b2aef22cb6f67a92674 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import React from 'dom-chef';
import select from 'select-dom';
import features from '../libs/features';
import getDefaultBranch from '../libs/get-default-branch';

async function init(): Promise<false | void> {
	const defaultBranch = await getDefaultBranch();
	// Expected: /user/repo/compare/master...user:master
	if (!location.pathname.endsWith(':' + defaultBranch)) {
		return false;
	}

	select('.gh-header-new-pr')!.append(
		<div className="flash flash-error my-3">
			<strong>Note:</strong> Creating a PR from the the default branch is an <a href="https://blog.jasonmeridth.com/posts/do-not-issue-pull-requests-from-your-master-branch/" target="_blank">anti-pattern</a>.
		</div>
	);
}

features.add({
	id: __featureName__,
	description: 'Warns you when creating a pull request from the default branch, as it’s an anti-pattern.',
	screenshot: 'https://user-images.githubusercontent.com/1402241/52543516-3ca94e00-2de5-11e9-9f80-ff8f9fe8bdc4.png',
	include: [
		features.isCompare
	],
	load: features.onAjaxedPages,
	init
});