Skip to content
This repository was archived by the owner on Jan 24, 2023. It is now read-only.

Commit db63cca

Browse files
authored
Support auto-merge projects (#22)
GitHub seems to emit two input fields with the same ID when auto-merge is available. The browser is not too happy about this either. ![image](https://user-images.githubusercontent.com/56807/115578388-89dab180-a2c5-11eb-86cd-e4dbc913a2ec.png)
1 parent 6b539e4 commit db63cca

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

content.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ function copyPrDescription(event) {
2121
return;
2222
};
2323

24-
const titleField = document.getElementById('merge_title_field');
25-
if (!titleField) {
24+
// When using auto-merge, GitHub has two text fields with the same ID.
25+
const titleFields = document.querySelectorAll('[id=merge_title_field]');
26+
if (!titleFields.length) {
2627
warn('failed to find merge commit title field');
2728
return;
2829
};
2930

30-
const messageField = document.getElementById('merge_message_field');
31-
if (!messageField) {
31+
// When using auto-merge, GitHub has two text fields with the same ID.
32+
const messageFields = document.querySelectorAll('[id=merge_message_field]');
33+
if (!messageFields.length) {
3234
warn('failed to find merge commit body field');
3335
return;
3436
};
@@ -39,13 +41,13 @@ function copyPrDescription(event) {
3941
let commitBody = prBodyEl.textContent.replace(/^<!--.*?-->\n*/gs, '');
4042

4143
// Preserve and de-duplicate co-authors
42-
const coauthors = new Set(messageField.value.match(/Co-authored-by: .*/g));
44+
const coauthors = new Set(messageFields[0].value.match(/Co-authored-by: .*/g));
4345
if (coauthors.size > 0) {
4446
commitBody += '\n\n' + [...coauthors].join('\n');
4547
}
4648

47-
titleField.value = commitTitle;
48-
messageField.value = commitBody;
49+
titleFields.forEach(f => f.value = commitTitle);
50+
messageFields.forEach(f => f.value = commitBody);
4951
}
5052

5153
function addMergeListener(event) {

0 commit comments

Comments
 (0)