Skip to content

Commit 37f4f5e

Browse files
authored
chore: move the widget above deployments box (#93)
This moves the widget above the deployment box and rework the layout. This avoids plugging the popup on the lazy-loaded part of the page.
1 parent ee8932a commit 37f4f5e

File tree

1 file changed

+44
-71
lines changed

1 file changed

+44
-71
lines changed

src/mergify.js

Lines changed: 44 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -208,53 +208,10 @@ function buildMergifySectionForClassicMergeBox() {
208208
}
209209

210210
function buildLogoContainer() {
211-
// <div class="mr-2 flex-shrink-0">
212211
const container = document.createElement("div");
213-
container.className = "mr-2 flex-shrink-0";
214-
container.style.marginTop = "12px";
215-
216-
// <div overflow="hidden" size="32" class="Box-sc-g0xbh4-0 iAmUFw">
217-
const container2 = document.createElement("div");
218-
container2.setAttribute("overflow", "hidden");
219-
container2.setAttribute("size", "32");
220-
container2.className = "Box-sc-g0xbh4-0 iAmUFw";
221-
container.appendChild(container2);
222-
223-
// <div display="flex" size="32" class="Box-sc-g0xbh4-0 jneZjk">
224-
const container3 = document.createElement("div");
225-
container3.setAttribute("display", "flex");
226-
container3.setAttribute("size", "32");
227-
container3.className = "Box-sc-g0xbh4-0 jneZjk";
228-
container3.innerHTML = getLogoSvg();
229-
container2.appendChild(container3);
230-
231-
return container;
232-
}
233-
234-
function buildTitleContainer() {
235-
const container = document.createElement("div");
236-
container.className = "flex-1 pt-1";
237-
238-
const title = document.createElement("h3");
239-
title.className = "Box-sc-g0xbh4-0 isSOdJ prc-Heading-Heading-6CmGO";
240-
title.textContent = "Mergify";
241-
container.appendChild(title);
242-
243-
const subtitle = document.createElement("p");
244-
subtitle.className = "fgColor-muted mb-0";
245-
subtitle.textContent = "This pull request is managed by Mergify.";
246-
container.appendChild(subtitle);
247-
248-
const mergeQueueLink = document.createElement("p");
249-
mergeQueueLink.className = "fgColor-muted mb-0";
250-
mergeQueueLink.innerHTML = `<a class="Link--inTextBlock btn-link" href="${getMergeQueueLink()}" target="_blank">View merge queue</a>`;
251-
container.appendChild(mergeQueueLink);
252-
253-
const eventLogLink = document.createElement("p");
254-
eventLogLink.className = "fgColor-muted mb-0";
255-
eventLogLink.innerHTML = `<a class="Link--inTextBlock btn-link" href="${getEventLogLink()}" target="_blank">View event logs of the pull request</a>`;
256-
container.appendChild(eventLogLink);
257-
212+
container.className =
213+
"float-left branch-action-item-icon completeness-indicator circle color-fg-muted border";
214+
container.innerHTML = getLogoSvg();
258215
return container;
259216
}
260217

@@ -284,16 +241,12 @@ function buildButton(command, label, tooltip, disabled) {
284241
return container;
285242
}
286243

287-
function buildTitleAndButtonsContainer() {
244+
function buildButtons() {
288245
const pullIsClosed = getPullStatus() !== "open";
289-
290-
const container = document.createElement("div");
291-
container.className = "d-flex flex-1 flex-column flex-sm-row gap-2";
292-
293-
container.appendChild(buildTitleContainer());
294-
246+
const containerButtons = document.createElement("div");
247+
containerButtons.className = "d-flex flex-1 flex-column flex-sm-row gap-2";
295248
for (const button of BUTTONS) {
296-
container.appendChild(
249+
containerButtons.appendChild(
297250
buildButton(
298251
button.command,
299252
button.label,
@@ -302,33 +255,53 @@ function buildTitleAndButtonsContainer() {
302255
),
303256
);
304257
}
258+
return containerButtons;
259+
}
260+
261+
function buildLinks() {
262+
const container = document.createElement("div");
263+
container.className = "float-right";
264+
container.style = "text-align: right";
265+
266+
const eventLogLink = document.createElement("p");
267+
eventLogLink.className = "fgColor-muted mb-0";
268+
eventLogLink.innerHTML = `<a class="Button Button--link Button--medium" href="${getEventLogLink()}" target="_blank">View event logs of the pull request</a>`;
269+
container.appendChild(eventLogLink);
270+
271+
const mergeQueueLink = document.createElement("p");
272+
mergeQueueLink.className = "fgColor-muted mb-0";
273+
mergeQueueLink.innerHTML = `<a class="Button Button--link Button--medium" href="${getMergeQueueLink()}" target="_blank">View merge queue</a>`;
274+
container.appendChild(mergeQueueLink);
305275

306276
return container;
307277
}
308278

309-
function buildMergifySectionForNewMergeBox() {
310-
const section = document.createElement("section");
311-
section.className = "border-bottom borderColor-muted pl-3 pb-3 pr-3";
312-
section.id = "mergify";
313-
section.setAttribute("aria-label", "Mergify");
314-
279+
function buildMergifySectionForTimelineActions() {
315280
const container1 = document.createElement("div");
316-
container1.className = "d-flex flex-column width-full overflow-hidden";
317-
section.appendChild(container1);
281+
container1.className = "branch-action py-0 my-3 pl-0 pl-md-3 ml-md-6";
282+
container1.id = "mergify";
283+
container1.setAttribute("aria-label", "Mergify");
318284

319285
const container2 = document.createElement("div");
320286
container2.className =
321-
"MergeBoxSectionHeader-module__wrapper--f99Ts flex-column flex-sm-row flex-items-center flex-sm-items-start flex-justify-between";
287+
"border color-border-default rounded-2 branch-action-item js-details-container js-transitionable";
322288
container1.appendChild(container2);
323289

324-
const container3 = document.createElement("div");
325-
container3.className = "d-flex width-full";
326-
container2.appendChild(container3);
290+
const title = document.createElement("h3");
291+
title.className = "h4 status-heading";
292+
title.textContent = "Mergify";
293+
294+
const subtitle = document.createElement("span");
295+
subtitle.className = "status-meta";
296+
subtitle.textContent = "This pull request is managed by Mergify.";
327297

328-
container3.appendChild(buildLogoContainer());
329-
container3.appendChild(buildTitleAndButtonsContainer());
298+
container2.appendChild(buildLogoContainer());
299+
container2.appendChild(buildLinks());
300+
container2.appendChild(title);
301+
container2.appendChild(subtitle);
302+
container2.appendChild(buildButtons());
330303

331-
return section;
304+
return container1;
332305
}
333306

334307
function isGitHubPullRequestPage() {
@@ -339,7 +312,7 @@ function isGitHubPullRequestPage() {
339312

340313
function findNewMergeBox() {
341314
const mergeBoxDiv = document.querySelector(
342-
"div[data-testid=mergebox-partial] > :last-child > :last-child",
315+
"div[class=discussion-timeline-actions] > :first-child",
343316
);
344317
if (mergeBoxDiv && mergeBoxDiv.tagName === "DIV") {
345318
return mergeBoxDiv;
@@ -372,7 +345,7 @@ function tryInject() {
372345
const detailSection = findNewMergeBox();
373346
if (detailSection) {
374347
detailSection.insertBefore(
375-
buildMergifySectionForNewMergeBox(),
348+
buildMergifySectionForTimelineActions(),
376349
detailSection.firstChild,
377350
);
378351
}

0 commit comments

Comments
 (0)