Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deemphasize update-pr-from-base-branch button #3154

Merged
merged 6 commits into from
May 30, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/features/clean-mergeability-box.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

/* Hide extra copy on PR mergeability summary */
.mergeability-details .js-details-container .h4,
.mergeability-details .js-details-container .status-meta .btn-link,
.mergeability-details > :not(.js-details-container) .completeness-indicator-success ~ .status-meta { /* Hides merge information unless it's negative */
.mergeability-details .js-details-container .status-meta:not(.rgh-update-pr-from-base-branch) .btn-link,
.mergeability-details > :not(.js-details-container) .completeness-indicator-success ~ .status-meta:not(.rgh-update-pr-from-base-branch) { /* Hides merge information unless it's negative */
display: none;
}

Expand Down
42 changes: 24 additions & 18 deletions source/features/update-pr-from-base-branch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,43 @@ async function mergeBranches(): Promise<AnyObject> {
});
}

async function handler(event: delegate.Event): Promise<void> {
const button = event.target as HTMLButtonElement;
button.disabled = true;
button.textContent = 'Updating branch…';
button.classList.remove('tooltipped');
async function handler({delegateTarget}: delegate.Event): Promise<void> {
if (!confirm(delegateTarget.getAttribute('aria-label')! + '?')) {
return;
}

const statusMeta = delegateTarget.parentElement!;
statusMeta.textContent = 'Updating branch…';
observer.disconnect();

const response = await mergeBranches();
if (response.ok) {
button.remove();
statusMeta.remove();
} else if (response.message?.toLowerCase().startsWith('merge conflict')) {
// Only shown on Draft PRs
button.replaceWith(
statusMeta.textContent = '';
statusMeta.append(
<a href={location.pathname + '/conflicts'} className="btn float-right"><AlertIcon/> Resolve conflicts</a>
);
} else {
button.textContent = response.message ?? 'Error';
button.prepend(<AlertIcon/>, ' ');
statusMeta.textContent = response.message ?? 'Error';
statusMeta.prepend(<AlertIcon/>, ' ');
throw new api.RefinedGitHubAPIError('update-pr-from-base-branch: ' + JSON.stringify(response));
}
}

function createButton(base: string, head: string): HTMLElement {
return (
<button type="button" className="btn float-right rgh-update-pr-from-master tooltipped tooltipped-n" aria-label={`Merge the ${base} branch into ${head}`}>
Update branch
const button = (
<button type="button" className="btn-link tooltipped tooltipped-n" aria-label={`Merge the ${base} branch into ${head}`}>
FloEdelmann marked this conversation as resolved.
Show resolved Hide resolved
update the base branch
</button>
);

return <span className="status-meta rgh-update-pr-from-base-branch">You can {button}.</span>;
}

async function addButton(): Promise<void> {
if (select.exists('.rgh-update-pr-from-master, .branch-action-btn:not([action$="ready_for_review"]) > .btn')) {
if (select.exists('.rgh-update-pr-from-base-branch, .branch-action-btn:not([action$="ready_for_review"]) > .btn')) {
return;
}

Expand All @@ -77,9 +82,10 @@ async function addButton(): Promise<void> {

// Draft PRs already have this info on the page
const [outOfDateContainer] = select.all('.completeness-indicator-problem + .status-heading')
.filter(title => (title.textContent!).includes('out-of-date'));
.filter(title => title.textContent!.includes('out-of-date'));
if (outOfDateContainer) {
outOfDateContainer.append(createButton(base, head));
const meta = outOfDateContainer.nextElementSibling!;
meta.after(' ', createButton(base, head));
return;
}

Expand All @@ -88,8 +94,8 @@ async function addButton(): Promise<void> {
return;
}

for (const heading of select.all('.mergeability-details > :not(.js-details-container) .status-heading')) {
heading.append(createButton(base, head));
for (const meta of select.all('.mergeability-details > :not(.js-details-container) .status-meta')) {
meta.after(' ', createButton(base, head));
}
}

Expand All @@ -105,7 +111,7 @@ function init(): void | false {
}

observer = observeElement('.discussion-timeline-actions', addButton)!;
delegate(document, '.rgh-update-pr-from-master', 'click', handler);
delegate(document, '.rgh-update-pr-from-base-branch button', 'click', handler);
}

features.add({
Expand Down