|
1 |
| - |
2 | 1 | export function addGitLabMRPatchComposer() {
|
3 |
| - const forkContainer = document.querySelector('#drupalorg-issue-forks'); |
4 |
| - if (!forkContainer) return; |
| 2 | + const forkContainer = document.querySelector('#drupalorg-issue-forks'); |
| 3 | + if (!forkContainer) return; |
5 | 4 |
|
6 |
| - const projectMatch = location.pathname.match(/\/project\/([^/]+)\/issues\//); |
7 |
| - if (!projectMatch) return; |
| 5 | + const projectMatch = location.pathname.match(/\/project\/([^/]+)\/issues\//); |
| 6 | + if (!projectMatch) return; |
8 | 7 |
|
9 |
| - const project = projectMatch[1]; |
10 |
| - const issueIdMatch = location.pathname.match(/\/issues\/(\d+)/); |
11 |
| - const issueId = issueIdMatch ? issueIdMatch[1] : 'Patch'; |
| 8 | + const project = projectMatch[1]; |
| 9 | + const issueIdMatch = location.pathname.match(/\/issues\/(\d+)/); |
| 10 | + const issueId = issueIdMatch ? issueIdMatch[1] : 'Patch'; |
12 | 11 |
|
13 |
| - const issueTitleEl = document.querySelector('.node__title, h1#page-title'); |
14 |
| - const issueTitle = issueTitleEl ? issueTitleEl.textContent.trim() : 'Patch'; |
15 |
| - const safeTitle = JSON.stringify(`#${issueId}: ${issueTitle}`).slice(1, -1); |
| 12 | + const issueTitleEl = document.querySelector('.node__title, h1#page-title'); |
| 13 | + const issueTitle = issueTitleEl ? issueTitleEl.textContent.trim() : 'Patch'; |
| 14 | + const safeTitle = JSON.stringify(`#${issueId}: ${issueTitle}`).slice(1, -1); |
16 | 15 |
|
17 |
| - const mrLinks = forkContainer.querySelectorAll('a.merge-request'); |
18 |
| - if (!mrLinks.length) return; |
| 16 | + const mrLinks = forkContainer.querySelectorAll('a.merge-request'); |
| 17 | + if (!mrLinks.length) return; |
19 | 18 |
|
20 |
| - const table = document.createElement('table'); |
21 |
| - table.className = 'gitlab-mr-patches'; |
22 |
| - table.style.marginTop = '1em'; |
23 |
| - table.style.width = '100%'; |
24 |
| - table.style.borderCollapse = 'collapse'; |
| 19 | + const table = document.createElement('table'); |
| 20 | + table.className = 'gitlab-mr-patches'; |
| 21 | + table.style.marginTop = '1em'; |
| 22 | + table.style.width = '100%'; |
| 23 | + table.style.borderCollapse = 'collapse'; |
25 | 24 |
|
26 |
| - const thead = document.createElement('thead'); |
27 |
| - thead.innerHTML = ` |
| 25 | + const thead = document.createElement('thead'); |
| 26 | + thead.innerHTML = ` |
28 | 27 | <tr>
|
29 | 28 | <th style="text-align: left; border: 1px solid #ccc; border-right: 0; padding: 4px;">Merge Request</th>
|
30 | 29 | <th style="text-align: left; border: 1px solid #ccc; border-left: 0; border-right: 0; padding: 4px;">Patch URL</th>
|
31 | 30 | <th style="text-align: left; border: 1px solid #ccc; border-left: 0; padding: 4px;">Composer</th>
|
32 | 31 | </tr>
|
33 | 32 | `;
|
34 |
| - table.appendChild(thead); |
35 |
| - |
36 |
| - const tbody = document.createElement('tbody'); |
37 |
| - |
38 |
| - mrLinks.forEach(link => { |
39 |
| - const mrIdMatch = link.href.match(/\/merge_requests\/(\d+)/); |
40 |
| - if (!mrIdMatch) return; |
41 |
| - |
42 |
| - const mrId = mrIdMatch[1]; |
43 |
| - const patchUrl = `https://git.drupalcode.org/project/${project}/-/merge_requests/${mrId}.patch`; |
44 |
| - |
45 |
| - const row = document.createElement('tr'); |
46 |
| - |
47 |
| - const mrCell = document.createElement('td'); |
48 |
| - mrCell.textContent = `!${mrId}`; |
49 |
| - mrCell.style.padding = '4px'; |
50 |
| - mrCell.style.borderRight = '0'; |
51 |
| - |
52 |
| - const urlCell = document.createElement('td'); |
53 |
| - const urlLink = document.createElement('a'); |
54 |
| - urlLink.href = patchUrl; |
55 |
| - urlLink.textContent = `${mrId}.patch`; |
56 |
| - urlCell.appendChild(urlLink); |
57 |
| - urlCell.style.padding = '4px'; |
58 |
| - urlCell.style.borderLeft = '0'; |
59 |
| - urlCell.style.borderRight = '0'; |
60 |
| - |
61 |
| - const composerCell = document.createElement('td'); |
62 |
| - const copyButton = document.createElement('button'); |
63 |
| - copyButton.textContent = 'Copy'; |
64 |
| - copyButton.style.padding = '4px 8px'; |
65 |
| - copyButton.style.backgroundColor = '#7cbc48'; |
66 |
| - copyButton.style.color = '#fff'; |
67 |
| - copyButton.style.border = 'none'; |
68 |
| - copyButton.style.cursor = 'pointer'; |
69 |
| - |
70 |
| - copyButton.addEventListener('click', () => { |
71 |
| - const composerJson = `"drupal/${project}": { |
| 33 | + table.appendChild(thead); |
| 34 | + |
| 35 | + const tbody = document.createElement('tbody'); |
| 36 | + |
| 37 | + mrLinks.forEach(link => { |
| 38 | + const mrIdMatch = link.href.match(/\/merge_requests\/(\d+)/); |
| 39 | + if (!mrIdMatch) return; |
| 40 | + |
| 41 | + const mrId = mrIdMatch[1]; |
| 42 | + const patchUrl = `https://git.drupalcode.org/project/${project}/-/merge_requests/${mrId}.patch`; |
| 43 | + |
| 44 | + const row = document.createElement('tr'); |
| 45 | + |
| 46 | + const mrCell = document.createElement('td'); |
| 47 | + mrCell.textContent = `!${mrId}`; |
| 48 | + mrCell.style.padding = '4px'; |
| 49 | + mrCell.style.borderRight = '0'; |
| 50 | + |
| 51 | + const urlCell = document.createElement('td'); |
| 52 | + const urlLink = document.createElement('a'); |
| 53 | + urlLink.href = patchUrl; |
| 54 | + urlLink.textContent = `${mrId}.patch`; |
| 55 | + urlCell.appendChild(urlLink); |
| 56 | + urlCell.style.padding = '4px'; |
| 57 | + urlCell.style.borderLeft = '0'; |
| 58 | + urlCell.style.borderRight = '0'; |
| 59 | + |
| 60 | + const composerCell = document.createElement('td'); |
| 61 | + const copyButton = document.createElement('button'); |
| 62 | + copyButton.textContent = 'Copy'; |
| 63 | + copyButton.style.padding = '4px 8px'; |
| 64 | + copyButton.style.backgroundColor = '#7cbc48'; |
| 65 | + copyButton.style.color = '#fff'; |
| 66 | + copyButton.style.border = 'none'; |
| 67 | + copyButton.style.cursor = 'pointer'; |
| 68 | + |
| 69 | + copyButton.addEventListener('click', () => { |
| 70 | + const composerJson = `"drupal/${project}": { |
72 | 71 | "${safeTitle}": "${patchUrl}"
|
73 | 72 | }`;
|
74 |
| - navigator.clipboard.writeText(composerJson).then(() => { |
75 |
| - copyButton.textContent = '✔ Copied'; |
76 |
| - setTimeout(() => { |
77 |
| - copyButton.textContent = 'Copy'; |
78 |
| - }, 1500); |
79 |
| - }); |
80 |
| - }); |
81 |
| - |
82 |
| - composerCell.appendChild(copyButton); |
83 |
| - composerCell.style.padding = '4px'; |
84 |
| - composerCell.style.borderLeft = '0'; |
85 |
| - |
86 |
| - row.appendChild(mrCell); |
87 |
| - row.appendChild(urlCell); |
88 |
| - row.appendChild(composerCell); |
89 |
| - tbody.appendChild(row); |
90 |
| - }); |
91 |
| - |
92 |
| - table.appendChild(tbody); |
93 |
| - forkContainer.appendChild(table); |
94 |
| - |
95 |
| - const warning = document.createElement('div'); |
96 |
| - warning.style.marginTop = '0.5em'; |
97 |
| - warning.style.padding = '0.5em'; |
98 |
| - warning.style.backgroundColor = '#fff8e1'; |
99 |
| - warning.style.border = '1px solid #ffcc80'; |
100 |
| - warning.style.color = '#8a6d3b'; |
101 |
| - warning.style.fontSize = '14px'; |
102 |
| - warning.style.lineHeight = '1.4'; |
103 |
| - warning.innerHTML = '⚠️ GitLab MR patch URLs may change when the branch is updated. For stability, download the patch and store it locally.'; |
104 |
| - |
105 |
| - forkContainer.appendChild(warning); |
| 73 | + navigator.clipboard.writeText(composerJson).then(() => { |
| 74 | + copyButton.textContent = '✔ Copied'; |
| 75 | + setTimeout(() => { |
| 76 | + copyButton.textContent = 'Copy'; |
| 77 | + }, 1500); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + composerCell.appendChild(copyButton); |
| 82 | + composerCell.style.padding = '4px'; |
| 83 | + composerCell.style.borderLeft = '0'; |
| 84 | + |
| 85 | + row.appendChild(mrCell); |
| 86 | + row.appendChild(urlCell); |
| 87 | + row.appendChild(composerCell); |
| 88 | + tbody.appendChild(row); |
| 89 | + }); |
| 90 | + |
| 91 | + table.appendChild(tbody); |
| 92 | + forkContainer.appendChild(table); |
| 93 | + |
| 94 | + const warning = document.createElement('div'); |
| 95 | + warning.style.marginTop = '0.5em'; |
| 96 | + warning.style.padding = '0.5em'; |
| 97 | + warning.style.backgroundColor = '#fff8e1'; |
| 98 | + warning.style.border = '1px solid #ffcc80'; |
| 99 | + warning.style.color = '#8a6d3b'; |
| 100 | + warning.style.fontSize = '14px'; |
| 101 | + warning.style.lineHeight = '1.4'; |
| 102 | + warning.innerHTML = '⚠️ GitLab MR patch URLs may change when the branch is updated. For stability, download the patch and store it locally.'; |
| 103 | + |
| 104 | + forkContainer.appendChild(warning); |
106 | 105 | }
|
0 commit comments