Skip to content

Commit

Permalink
fix: merge commit template (#368)
Browse files Browse the repository at this point in the history
Fixes #354
  • Loading branch information
reyronald committed Jun 8, 2020
1 parent 67ac887 commit 31a60a8
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions src/merge-commit-message-new/merge-commit-message-new.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { findAllByText, findByText } from '@testing-library/dom'
import { findAllByText } from '@testing-library/dom'
import elementReady from 'element-ready'
import { getRepoURL } from '../page-detect'
import {
getFirstFileContents,
Expand Down Expand Up @@ -77,27 +78,24 @@ async function insertMergeCommitTemplate(template, dataToInject) {
const mergeBtns = mergeSpans.map(span => span.closest('button'))

const onFulfillPullrequest = async () => {
const mergeDialogHeader = await findByText(
document.body,
'Merge pull request'
)
const textarea = mergeDialogHeader
.closest('[role="dialog"]')
.querySelector('textarea')
const value = template
.replace(/{id}/g, String(dataToInject.id))
.replace(/{title}/g, dataToInject.title)
.replace(/{description}/g, dataToInject.description)
.replace(/{sourceBranch}/g, dataToInject.sourceBranch)
.replace(/{targetBranch}/g, dataToInject.targetBranch)
.replace(/{approvedByList}/g, dataToInject.approvedByList)
const dialog = await elementReady('[role="dialog"]')
if (dialog) {
const textarea = dialog.querySelector('textarea')
const value = template
.replace(/{id}/g, String(dataToInject.id))
.replace(/{title}/g, dataToInject.title)
.replace(/{description}/g, dataToInject.description)
.replace(/{sourceBranch}/g, dataToInject.sourceBranch)
.replace(/{targetBranch}/g, dataToInject.targetBranch)
.replace(/{approvedByList}/g, dataToInject.approvedByList)

const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
window.HTMLTextAreaElement.prototype,
'value'
).set
nativeInputValueSetter.call(textarea, value)
textarea.dispatchEvent(new Event('input', { bubbles: true }))
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
window.HTMLTextAreaElement.prototype,
'value'
).set
nativeInputValueSetter.call(textarea, value)
textarea.dispatchEvent(new Event('input', { bubbles: true }))
}
}

mergeBtns.forEach(b => b.addEventListener('click', onFulfillPullrequest))
Expand Down

0 comments on commit 31a60a8

Please sign in to comment.