feat: update authored pull branches from mobile (Closes #1360)
This commit is contained in:
1 parent
a9becd079f
commit
b85fe4a0a3
7 files changed
+272
No files matched your search
@@ -800,6 +800,9 @@ textarea { resize: vertical; min-height: 120px; }
|
||||
.ci-check-log { max-width:100%; max-height:42vh; margin:8px 0; padding:10px; overflow-x:auto; overflow-y:auto; border:1px solid #2a496e; border-radius:6px; background:#07101d; color:#dbeafe; font-size:.78rem; white-space:pre; }
|
||||
.ci-check-recovery-actions { position:sticky; bottom:0; display:grid; grid-template-columns:1fr 1fr; gap:8px; padding-top:6px; background:#101b2e; }
|
||||
.ci-check-recovery-actions button { min-height:44px; }
|
||||
.pull-branch-update { max-width:100%; min-width:0; margin:10px 0; padding:12px; border:1px solid #60a5fa; border-radius:10px; overflow-wrap:anywhere; }
|
||||
.pull-branch-update h3 { margin:0 0 6px; }
|
||||
.pull-branch-update button { width:100%; min-height:44px; }
|
||||
.update-sheet { position:fixed; inset:0; z-index:55; display:none; justify-content:flex-end; background:rgba(5,12,21,.72); backdrop-filter:blur(4px); }
|
||||
.update-sheet.open { display:flex; }
|
||||
.update-sheet-panel { width:min(560px,100%); height:100%; overflow:auto; padding:18px; background:#0b1526; border-left:1px solid #2a496e; }
|
||||
|
||||
@@ -1722,6 +1722,11 @@
|
||||
<div id="pull-review-status" class="small" aria-live="polite">Expand to load changed files and merge readiness.</div>
|
||||
<button class="pull-retry" id="pull-review-retry" type="button" hidden>Retry review data</button>
|
||||
<div class="row"><span class="pill" id="pull-ci-state">CI unknown</span><span class="pill" id="pull-merge-state">Review data not loaded</span></div>
|
||||
<section class="pull-branch-update" id="pull-branch-update" aria-labelledby="pull-branch-update-heading" hidden>
|
||||
<h3 id="pull-branch-update-heading">Bring branch up to date</h3>
|
||||
<p class="small" id="pull-branch-update-status" role="status" aria-live="assertive"></p>
|
||||
<button id="update-pull-branch" type="button">Update branch</button>
|
||||
</section>
|
||||
<section class="pull-reviewer-summary" aria-labelledby="pull-reviewer-heading">
|
||||
<h3 id="pull-reviewer-heading">Reviewer status</h3>
|
||||
<div id="pull-reviewer-status" class="small" aria-live="polite">Reviewer status not loaded.</div>
|
||||
|
||||
@@ -231,6 +231,46 @@ function resetReviewRequestControls(doc, detail) {
|
||||
qs('#pull-feedback-status').textContent = '';
|
||||
}
|
||||
|
||||
function resetBranchUpdateControls(doc, detail) {
|
||||
const panel = doc.querySelector('#pull-branch-update');
|
||||
if (!panel) return;
|
||||
const eligible = detail?.capabilities?.authored === true && detail?.state === 'open' &&
|
||||
detail?.draft !== true && detail?.merged !== true && detail?.mergeable === false && detail?.head_sha;
|
||||
panel.hidden = !eligible;
|
||||
doc.querySelector('#update-pull-branch').disabled = false;
|
||||
doc.querySelector('#pull-branch-update-status').textContent = eligible ?
|
||||
'Merge the latest base branch into this pull request. Reviews and checks may run again.' : '';
|
||||
}
|
||||
|
||||
function bindBranchUpdateControls(doc, controller, getSelected, getDetail) {
|
||||
const button = doc.querySelector('#update-pull-branch');
|
||||
if (!button || button.dataset.bound === 'true') return;
|
||||
button.dataset.bound = 'true';
|
||||
button.addEventListener('click', async () => {
|
||||
const item = getSelected?.();
|
||||
const detail = getDetail?.();
|
||||
if (!item || !detail?.head_sha || detail?.capabilities?.authored !== true ||
|
||||
!globalThis.confirm('Update ' + item.key + ' with the latest base branch? Reviews and checks may run again.')) return;
|
||||
button.disabled = true;
|
||||
const status = doc.querySelector('#pull-branch-update-status');
|
||||
status.textContent = 'Updating branch…';
|
||||
try {
|
||||
const result = await controller.updateBranch(item, detail.head_sha);
|
||||
if (getSelected?.() !== item || getDetail?.() !== detail) return;
|
||||
Object.assign(detail, result, { mergeable:null, ci_state:'pending', reviewers:[] });
|
||||
status.textContent = 'Branch updated. Refreshing checks and review state…';
|
||||
doc.querySelector('#pull-review-retry')?.click();
|
||||
status.textContent = 'Branch updated to ' + result.head_sha.slice(0, 8) + '. Review the refreshed checks before merging.';
|
||||
button.hidden = true;
|
||||
doc.querySelector('#refresh-pull-checks')?.focus();
|
||||
} catch (error) {
|
||||
status.textContent = error.message + ' Reload the latest pull request state before retrying.';
|
||||
button.disabled = false;
|
||||
button.focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function bindReviewRequestControls(doc, controller, getSelected, getDetail, getLogin) {
|
||||
const qs = selector => doc.querySelector(selector);
|
||||
const load = qs('#load-pull-reviewers');
|
||||
@@ -238,6 +278,7 @@ function bindReviewRequestControls(doc, controller, getSelected, getDetail, getL
|
||||
load.dataset.reviewRequestBound = 'true';
|
||||
controller.setReviewDetail = detail => {
|
||||
resetReviewRequestControls(doc, detail);
|
||||
resetBranchUpdateControls(doc, detail);
|
||||
applyOwnershipCapabilities(doc, detail?.capabilities);
|
||||
resetLifecycleControls(doc, detail?.saved_at ? null : detail);
|
||||
controller.edit?.setDetail(detail, Boolean(detail?.saved_at));
|
||||
@@ -577,6 +618,7 @@ function bindContextEditor(doc, controller, getSelected, getDetail, getLogin) {
|
||||
|
||||
function bindOwnershipControls(doc, controller, getSelected, finish, getDetail, getLogin) {
|
||||
bindReviewRequestControls(doc, controller, getSelected, getDetail, getLogin);
|
||||
bindBranchUpdateControls(doc, controller, getSelected, getDetail);
|
||||
bindFeedbackControls(doc, controller, getSelected, getDetail, getLogin);
|
||||
bindCheckRecovery(doc, controller, getSelected, getDetail);
|
||||
bindLifecycleControls(doc, controller, getSelected, getDetail, result => controller.onState?.(result));
|
||||
@@ -650,6 +692,7 @@ function createPullSheet({ fetchJson, storage, onState, createConversationPager
|
||||
let mergeRequest = null;
|
||||
let checkRequest = null;
|
||||
let ownershipRequest = null;
|
||||
let branchUpdateRequest = null;
|
||||
let candidateRequest = null;
|
||||
let reviewCandidateRequest = null;
|
||||
let reviewRequestMutation = null;
|
||||
@@ -975,6 +1018,20 @@ function createPullSheet({ fetchJson, storage, onState, createConversationPager
|
||||
}).finally(() => { mergeRequest = null; });
|
||||
return mergeRequest;
|
||||
},
|
||||
updateBranch(item, expectedHeadSha) {
|
||||
if (branchUpdateRequest) return branchUpdateRequest;
|
||||
branchUpdateRequest = fetchJson(pathFor(item) + '/update-branch', {
|
||||
method: 'POST',
|
||||
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ expected_head_sha: expectedHeadSha }),
|
||||
}).then(result => {
|
||||
if (!result?.head_sha || result.head_sha === expectedHeadSha) {
|
||||
throw new Error('Branch update was not confirmed.');
|
||||
}
|
||||
return result;
|
||||
}).finally(() => { branchUpdateRequest = null; });
|
||||
return branchUpdateRequest;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user