Skip to content

Commit

Permalink
Add notice to clear-pr-merge-commit-message (#6019)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Sep 25, 2022
1 parent da89c8e commit 184cbf9
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions source/features/clear-pr-merge-commit-message.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import React from 'dom-chef';
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '../feature-manager';
import onPrMergePanelOpen from '../github-events/on-pr-merge-panel-open';

function init(): void {
function init(): void | false {
const messageField = select('textarea#merge_message_field')!;
const originalMessage = messageField.value;
const deduplicatedAuthors = new Set();

// This method ensures that "Co-authored-by" capitalization doesn't affect deduplication
for (const [, author] of messageField.value.matchAll(/co-authored-by: ([^\n]+)/gi)) {
for (const [, author] of originalMessage.matchAll(/co-authored-by: ([^\n]+)/gi)) {
deduplicatedAuthors.add('Co-authored-by: ' + author);
}

messageField.value = [...deduplicatedAuthors].join('\n');
const cleanedMessage = [...deduplicatedAuthors].join('\n');
if (cleanedMessage === originalMessage.trim()) {
return false;
}

messageField.value = cleanedMessage;
messageField.after(
<p className="note rgh-sync-pr-commit-title-note">
The description field was cleared by <a target="_blank" href="https://github.com/refined-github/refined-github/wiki/Extended-feature-descriptions#clear-pr-merge-commit-message" rel="noreferrer">Refined GitHub</a>.
</p>,
<hr/>,
);
}

void features.add(import.meta.url, {
Expand Down

0 comments on commit 184cbf9

Please sign in to comment.