(messageField: HTMLTextAreaElement)
| 16 | const isPrAgainstDefaultBranch = async (): Promise<boolean> => getBranches().base.branch === await getDefaultBranch(); |
| 17 | |
| 18 | async 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 | |
| 62 | async function init(signal: AbortSignal): Promise<void> { |
| 63 | observe('textarea[placeholder="Add an optional extended description…"]', clear, {signal}); |
nothing calls this directly
no test coverage detected