MCPcopy Index your code
hub / github.com/refined-github/refined-github / clear

Function clear

source/features/clear-pr-merge-commit-message.tsx:18–60  ·  view source on GitHub ↗
(messageField: HTMLTextAreaElement)

Source from the content-addressed store, hash-verified

16const isPrAgainstDefaultBranch = async (): Promise<boolean> => getBranches().base.branch === await getDefaultBranch();
17
18async function clear(messageField: HTMLTextAreaElement): Promise<void> {
19 if (!/squash/i.test($(confirmMergeButton).textContent)) {
20 return;
21 }
22
23 const originalMessage = messageField.value;
24 const author = getConversationAuthor();
25 let cleanedMessage = cleanCommitMessage(originalMessage, !await isPrAgainstDefaultBranch(), [author]);
26
27 if (cleanedMessage === originalMessage.trim()) {
28 return;
29 }
30
31 cleanedMessage = cleanedMessage ? cleanedMessage + '\n' : '';
32 // Do not use `text-field-edit` #6348
33 setReactTextareaValue(messageField, cleanedMessage);
34
35 let isUndoing = false;
36 function toggleUndoRedo({currentTarget}: React.MouseEvent<HTMLButtonElement>): void {
37 isUndoing = !isUndoing;
38 setReactTextareaValue(messageField, isUndoing ? originalMessage : cleanedMessage);
39 currentTarget.textContent = isUndoing ? 'Redo' : 'Undo';
40 }
41
42 const anchor = closestElement('div[data-has-label]', messageField);
43 attachElement(anchor, {
44 after: () => (
45 <div className="flex-self-stretch">
46 <p className="note">
47 The description field was{' '}
48 <a
49 target="_blank"
50 href="https://github.com/refined-github/refined-github/wiki/Extended-feature-descriptions#clear-pr-merge-commit-message"
51 rel="noreferrer"
52 >
53 cleared
54 </a>{' '}
55 by Refined GitHub. <button type="button" className="btn-link" onClick={toggleUndoRedo}>Undo</button>
56 </p>
57 </div>
58 ),
59 });
60}
61
62async function init(signal: AbortSignal): Promise<void> {
63 observe('textarea[placeholder="Add an optional extended description…"]', clear, {signal});

Callers

nothing calls this directly

Calls 5

getConversationAuthorFunction · 0.85
cleanCommitMessageFunction · 0.85
isPrAgainstDefaultBranchFunction · 0.85
setReactTextareaValueFunction · 0.85
attachElementFunction · 0.85

Tested by

no test coverage detected