Skip to content

Commit b2bda4b

Browse files
authored
Mention pr-branch-auto-delete after branch deletion (refined-github#5766)
1 parent 93d602e commit b2bda4b

2 files changed

Lines changed: 36 additions & 20 deletions

File tree

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ Thanks for contributing! 🦋🙌
289289
- [](# "warn-pr-from-master") [Warns you when creating a pull request from the default branch, as it’s an anti-pattern.](https://user-images.githubusercontent.com/1402241/52543516-3ca94e00-2de5-11e9-9f80-ff8f9fe8bdc4.png)
290290
- [](# "warning-for-disallow-edits") [Warns you when unchecking `Allow edits from maintainers`, as it’s maintainer-hostile.](https://user-images.githubusercontent.com/1402241/53151888-24101380-35ef-11e9-8d30-d6315ad97325.gif)
291291
- [](# "pull-request-hotkeys") [Adds keyboard shortcuts to cycle through PR tabs: <kbd>g</kbd> <kbd>←</kbd> and <kbd>g</kbd> <kbd>→</kbd>, or <kbd>g</kbd> <kbd>1</kbd>, <kbd>g</kbd> <kbd>2</kbd>, <kbd>g</kbd> <kbd>3</kbd> and <kbd>g</kbd> <kbd>4</kbd>](https://user-images.githubusercontent.com/16872793/94634958-7e7b5680-029f-11eb-82ea-1f96cd11e4cd.png).
292-
- [](# "pr-branch-auto-delete") Automatically deletes the branch right after merging a PR, if possible.
292+
- [](# "pr-branch-auto-delete") [Automatically deletes the branch right after merging a PR, if possible.](https://user-images.githubusercontent.com/1402241/177067141-eabc7494-38a2-45b5-aef9-ac33cc0da370.png)
293293
- [](# "one-click-pr-or-gist") [Lets you create draft pull requests and public gists in one click.](https://user-images.githubusercontent.com/34235681/152473201-868ad7c1-e06f-4826-b808-d90bca7f08b3.png)
294294
- [](# "clear-pr-merge-commit-message") [Clears the PR merge commit message of clutter, leaving only deduplicated co-authors.](https://user-images.githubusercontent.com/1402241/79257078-62b6fc00-7e89-11ea-8798-c06f33baa94b.png)
295295
- [](# "quick-review") [Adds a review button to the PR sidebar, automatically focuses the review textarea and adds a keyboard shortcut to open the review popup: <kbd>v</kbd>.](https://user-images.githubusercontent.com/202916/83269671-bb3b2200-a1c7-11ea-90b3-b9457a454162.png)
Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,50 @@
1+
import React from 'dom-chef';
12
import select from 'select-dom';
2-
import delegate from 'delegate-it';
3+
import {InfoIcon} from '@primer/octicons-react';
4+
import elementReady from 'element-ready';
35
import * as pageDetect from 'github-url-detection';
46

57
import features from '.';
8+
import onPrMerge from '../github-events/on-pr-merge';
9+
import featureLink from '../helpers/feature-link';
10+
import attachElement from '../helpers/attach-element';
11+
import {canEditEveryComment} from './quick-comment-edit';
612

7-
function init(): Deinit {
8-
const observer = new MutationObserver(() => {
9-
const deleteButton = select('[action$="/cleanup"] [type="submit"]');
10-
if (deleteButton) {
11-
deleteButton.dataset.disableWith = 'Auto-deleting…';
12-
deleteButton.click();
13-
observer.disconnect();
14-
}
15-
});
13+
// TODO: Not an exact match; Moderators can edit comments but not create releases
14+
const canCreateRelease = canEditEveryComment;
15+
16+
async function init(): Promise<void> {
17+
const deleteButton = select('[action$="/cleanup"] [type="submit"]');
18+
if (!deleteButton) {
19+
return;
20+
}
21+
22+
deleteButton.dataset.disableWith = 'Auto-deleting…';
23+
deleteButton.click();
1624

17-
const subscription = delegate(document, '.js-merge-commit-button', 'click', () => {
18-
subscription.destroy();
19-
observer.observe(select('.discussion-timeline-actions')!, {childList: true});
25+
const deletionEvent = await elementReady('[data-test-selector="head-ref-deleted-event-ref-name"]', {
26+
stopOnDomReady: false,
2027
});
2128

22-
return [
23-
observer,
24-
subscription,
25-
];
29+
attachElement({
30+
anchor: deletionEvent!.closest('.TimelineItem-body')!,
31+
position: 'append',
32+
getNewElement() {
33+
const url = featureLink(features.getFeatureID(import.meta.url));
34+
return <a className="d-inline-block" href={url}>via Refined GitHub <InfoIcon/></a>;
35+
},
36+
});
2637
}
2738

2839
void features.add(import.meta.url, {
29-
include: [
40+
asLongAs: [
3041
pageDetect.isPRConversation,
42+
pageDetect.isOpenPR,
43+
canCreateRelease,
44+
],
45+
additionalListeners: [
46+
onPrMerge,
3147
],
32-
deduplicate: 'has-rgh-inner',
48+
onlyAdditionalListeners: true,
3349
init,
3450
});

0 commit comments

Comments
 (0)