summaryrefslogtreecommitdiff
path: root/source/features/pr-branch-auto-delete.tsx
blob: 57b3f81593bd5f984b501d765c3efa1e254cf1d5 (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
30
31
32
import select from 'select-dom';
import delegate from 'delegate-it';
import * as pageDetect from 'github-url-detection';

import features from '.';
import observeElement from '../helpers/simplified-element-observer';

function init(): void {
	const subscription = delegate(document, '.js-merge-commit-button', 'click', () => {
		subscription.destroy();

		observeElement('.discussion-timeline-actions', (_, observer) => {
			const deleteButton = select('[action$="/cleanup"] [type="submit"]');
			if (deleteButton) {
				deleteButton.dataset.disableWith = 'Auto-deleting…';
				deleteButton.click();
				observer.disconnect();
			}
		});
	});
}

void features.add({
	id: __filebasename,
	description: 'Automatically deletes the branch right after merging a PR, if possible.',
	screenshot: false
}, {
	include: [
		pageDetect.isPRConversation
	],
	init
});