refactor: modularize session sidebar and add GitHub PR tracking (#610)
* feat: switch sessions sidebar to global paginated loading with archived flow Load sessions via global endpoint with progressive 500-item pagination and legacy fallback Add dedicated archived sidebar section for archived and unassigned sessions Change remove behavior to archive outside archived and hard-delete inside archived * feat: improve archived sessions UX and folder persistence Archive sessions on worktree removal while keeping worktree deletion Streamline archived sidebar actions, icons, metadata, and tooltips Persist session folders to ~/.config/openchamber/sessions-directories.json with startup hydration * fix: align archived session actions and clean empty archived folders Apply archived dropdown behavior consistently for folder-contained sessions Remove archived-only folder actions while keeping standard folder behavior elsewhere Auto-prune empty archived folders during session cleanup and persistence sync * refactor: modularize session sidebar and stabilize behavior Split monolithic sidebar logic into focused hooks and components Kept session, archive, folder, and project interactions working with cleaner state persistence Added sidebar DOCUMENTATION.md summarizing file roles and refactor outcomes * fix: improve fork PR detection and smart remote tracking Added centralized PR status store for shared polling and refresh Auto-selects the remote that has an existing PR when current remote has none Stops periodic polling for closed or merged PRs to reduce unnecessary requests * fix: make chat and toast corners follow active theme radius Toast corners now use theme radius tokens instead of hardcoded rounding User message bubble now uses theme-configured max radius with preserved tail corner Square-corner themes now consistently affect both toasts and chat bubbles * feat: show live PR status across git view and session sidebar Added a shared GitHub PR status store with adaptive background polling and terminal-state pause Improved fork remote detection and auto-selection so existing PRs are found more reliably Updated session group headers to show clickable PR number with branch and state-colored branch icon * feat: centralize GitHub PR tracking and enrich session sidebar PR details Moved PR status polling to a single global pipeline keyed by directory and branch Improved fork-aware PR resolution and reduced duplicate GitHub status fetches across views Added richer session sidebar PR display with clickable number, state-aware styling, and structured tooltip details * fix: adjust PR indicator icon vertical alignment Fine-tuned PR indicator icon vertical alignment in session sidebar Reduced icon translate-y from 2px to 0.5px for better visual balance * feat: improve session sidebar status display * feat: enhance session display logic for minimal mode and improve dropdown menu accessibility * feat: refactor session row to include tooltip for minimal display mode
This commit is contained in:
committed by
GitHub
parent
d54e1199df
commit
a7f11121e8
@@ -9806,36 +9806,40 @@ async function main(options = {}) {
|
||||
return res.json({ connected: true, repo: null, branch, pr: null, checks: null, canMerge: false });
|
||||
}
|
||||
|
||||
// Determine the head owner for PR search
|
||||
// Priority: 1) tracking branch remote, 2) origin (if different from target), 3) target repo owner
|
||||
let headOwnerForSearch = null;
|
||||
|
||||
// First, check the branch's tracking info to see which remote it's on
|
||||
let originRepo = null;
|
||||
if (remote !== 'origin') {
|
||||
const originResolved = await resolveGitHubRepoFromDirectory(directory, 'origin').catch(() => ({ repo: null }));
|
||||
originRepo = originResolved?.repo || null;
|
||||
}
|
||||
|
||||
const candidateHeadOwners = [];
|
||||
const pushHeadOwner = (owner) => {
|
||||
if (typeof owner !== 'string') return;
|
||||
const normalized = owner.trim();
|
||||
if (!normalized) return;
|
||||
if (candidateHeadOwners.includes(normalized)) return;
|
||||
candidateHeadOwners.push(normalized);
|
||||
};
|
||||
|
||||
// First, use branch tracking remote owner (where branch is usually pushed).
|
||||
const { getStatus } = await import('./lib/git/index.js');
|
||||
const status = await getStatus(directory).catch(() => null);
|
||||
if (status?.tracking) {
|
||||
const trackingRemote = status.tracking.split('/')[0];
|
||||
if (trackingRemote && trackingRemote !== remote) {
|
||||
// Branch is tracked on a different remote - get that remote's owner
|
||||
const { repo: trackingRepo } = await resolveGitHubRepoFromDirectory(directory, trackingRemote);
|
||||
if (trackingRepo && trackingRepo.owner !== repo.owner) {
|
||||
headOwnerForSearch = trackingRepo.owner;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: if targeting non-origin, check if origin has a different owner (fork scenario)
|
||||
if (!headOwnerForSearch && remote !== 'origin') {
|
||||
const { repo: originRepo } = await resolveGitHubRepoFromDirectory(directory, 'origin');
|
||||
if (originRepo && originRepo.owner !== repo.owner) {
|
||||
headOwnerForSearch = originRepo.owner;
|
||||
if (trackingRemote) {
|
||||
const trackingResolved = await resolveGitHubRepoFromDirectory(directory, trackingRemote).catch(() => ({ repo: null }));
|
||||
pushHeadOwner(trackingResolved?.repo?.owner);
|
||||
}
|
||||
}
|
||||
|
||||
const listByHead = async (state, headOwner = repo.owner) => {
|
||||
// Then same-repo and origin fallback owners.
|
||||
pushHeadOwner(repo.owner);
|
||||
pushHeadOwner(originRepo?.owner);
|
||||
|
||||
const listByHead = async (targetRepo, state, headOwner) => {
|
||||
const resp = await octokit.rest.pulls.list({
|
||||
owner: repo.owner,
|
||||
repo: repo.repo,
|
||||
owner: targetRepo.owner,
|
||||
repo: targetRepo.repo,
|
||||
state,
|
||||
head: `${headOwner}:${branch}`,
|
||||
per_page: 10,
|
||||
@@ -9843,10 +9847,10 @@ async function main(options = {}) {
|
||||
return Array.isArray(resp?.data) ? resp.data[0] : null;
|
||||
};
|
||||
|
||||
const listByHeadRef = async (state) => {
|
||||
const listByHeadRef = async (targetRepo, state) => {
|
||||
const resp = await octokit.rest.pulls.list({
|
||||
owner: repo.owner,
|
||||
repo: repo.repo,
|
||||
owner: targetRepo.owner,
|
||||
repo: targetRepo.repo,
|
||||
state,
|
||||
per_page: 100,
|
||||
});
|
||||
@@ -9856,34 +9860,41 @@ async function main(options = {}) {
|
||||
return matches[0] ?? null;
|
||||
};
|
||||
|
||||
// PR status by branch:
|
||||
// - Prefer open PRs.
|
||||
// - If none, also surface closed/merged PRs.
|
||||
// - For cross-repo PRs: first try with head owner, then fall back to target owner, then ref match.
|
||||
let first = null;
|
||||
|
||||
// For cross-repo workflows, try head owner first
|
||||
if (headOwnerForSearch) {
|
||||
first = await listByHead('open', headOwnerForSearch);
|
||||
if (!first) first = await listByHead('closed', headOwnerForSearch);
|
||||
const tryFindPr = async (targetRepo) => {
|
||||
let found = null;
|
||||
for (const owner of candidateHeadOwners) {
|
||||
found = await listByHead(targetRepo, 'open', owner);
|
||||
if (found) return found;
|
||||
found = await listByHead(targetRepo, 'closed', owner);
|
||||
if (found) return found;
|
||||
}
|
||||
found = await listByHeadRef(targetRepo, 'open');
|
||||
if (found) return found;
|
||||
return listByHeadRef(targetRepo, 'closed');
|
||||
};
|
||||
|
||||
// Try requested remote target repo first, then origin target repo fallback for fork flows.
|
||||
let searchRepo = repo;
|
||||
let first = await tryFindPr(searchRepo);
|
||||
if (!first && originRepo) {
|
||||
const isDifferentRepo = originRepo.owner !== repo.owner || originRepo.repo !== repo.repo;
|
||||
if (isDifferentRepo) {
|
||||
const originMatch = await tryFindPr(originRepo);
|
||||
if (originMatch) {
|
||||
first = originMatch;
|
||||
searchRepo = originRepo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try with target repo owner (same-repo PRs)
|
||||
if (!first) first = await listByHead('open');
|
||||
if (!first) first = await listByHead('closed');
|
||||
|
||||
// Fall back to matching head.ref directly (handles edge cases)
|
||||
if (!first) first = await listByHeadRef('open');
|
||||
if (!first) first = await listByHeadRef('closed');
|
||||
if (!first) {
|
||||
return res.json({ connected: true, repo, branch, pr: null, checks: null, canMerge: false });
|
||||
return res.json({ connected: true, repo: searchRepo, branch, pr: null, checks: null, canMerge: false });
|
||||
}
|
||||
|
||||
// Enrich with mergeability fields
|
||||
const prFull = await octokit.rest.pulls.get({ owner: repo.owner, repo: repo.repo, pull_number: first.number });
|
||||
const prFull = await octokit.rest.pulls.get({ owner: searchRepo.owner, repo: searchRepo.repo, pull_number: first.number });
|
||||
const prData = prFull?.data;
|
||||
if (!prData) {
|
||||
return res.json({ connected: true, repo, branch, pr: null, checks: null, canMerge: false });
|
||||
return res.json({ connected: true, repo: searchRepo, branch, pr: null, checks: null, canMerge: false });
|
||||
}
|
||||
|
||||
// Checks summary: prefer check-runs (Actions), fallback to classic statuses.
|
||||
@@ -9892,8 +9903,8 @@ async function main(options = {}) {
|
||||
if (sha) {
|
||||
try {
|
||||
const runs = await octokit.rest.checks.listForRef({
|
||||
owner: repo.owner,
|
||||
repo: repo.repo,
|
||||
owner: searchRepo.owner,
|
||||
repo: searchRepo.repo,
|
||||
ref: sha,
|
||||
per_page: 100,
|
||||
});
|
||||
@@ -9930,8 +9941,8 @@ async function main(options = {}) {
|
||||
if (!checks) {
|
||||
try {
|
||||
const combined = await octokit.rest.repos.getCombinedStatusForRef({
|
||||
owner: repo.owner,
|
||||
repo: repo.repo,
|
||||
owner: searchRepo.owner,
|
||||
repo: searchRepo.repo,
|
||||
ref: sha,
|
||||
});
|
||||
const statuses = Array.isArray(combined?.data?.statuses) ? combined.data.statuses : [];
|
||||
@@ -9959,8 +9970,8 @@ async function main(options = {}) {
|
||||
const username = auth?.user?.login;
|
||||
if (username) {
|
||||
const perm = await octokit.rest.repos.getCollaboratorPermissionLevel({
|
||||
owner: repo.owner,
|
||||
repo: repo.repo,
|
||||
owner: searchRepo.owner,
|
||||
repo: searchRepo.repo,
|
||||
username,
|
||||
});
|
||||
const level = perm?.data?.permission;
|
||||
@@ -9975,7 +9986,7 @@ async function main(options = {}) {
|
||||
|
||||
return res.json({
|
||||
connected: true,
|
||||
repo,
|
||||
repo: searchRepo,
|
||||
branch,
|
||||
pr: {
|
||||
number: prData.number,
|
||||
|
||||
Reference in New Issue
Block a user