feat(desktop,host-service): view, remove, and restore PR links per branch

Merged
MI
4mo ago
+1165-8

What & why

Right-clicking a branch/worktree row in the projects sidebar offers Remove PR Link (shown only when the row has a PR badge). This is because sometimes a PR link sticks around after merging, or multiple PRs are created from the same worktree, and you want to be able to remove them.

Maintainer additions on top of the original single-PR removal (@Kitenite): the host-service now tracks every PR on a workspace's branch, and removals are individually targetable and reversible.

Data model

Clearing a link durably needs more than nulling workspaces.pullRequestId: the refresh sweep re-links a matching PR on every pass and the sidebar polls every 10s. Removal now suppresses the PR in a new workspace_pull_requests junction table (migration 0013, applied automatically at host-service startup) that records every PR the sweep finds for the branch — position (sweep order, most recently updated first) and a suppressed flag. The sweep reconciles rows on every pass; suppressed rows survive reconciliation so dismissals are remembered across restarts.

  • The badge (workspaces.pullRequestId) is the first non-suppressed PR; removing it falls through to the next PR immediately
  • The per-head GitHub query already returned up to 10 PRs — the sweep now keeps all open ones plus the most recent closed/merged one (capped at 5) instead of discarding all but the newest
  • A different PR opened on the same branch still auto-links; an explicit checkout link (gh pr checkout / create-from-PR) clears that PR's suppression
  • Deleting a PR row cascades its junction rows

UI

  • Sidebar badge: with multiple PRs it shows a count chip and click opens a dropdown listing the branch's PRs — click to open on GitHub, hover unlink button to remove one, and a Removed section with a restore button per dismissed PR
  • Sidebar context menu: Remove PR Link (removes the badge PR), plus a Restore PR Link submenu listing dismissed PRs — this also covers the case where every PR was removed and no badge exists
  • Workspace header PR button: the chevron dropdown now always renders, adding the same PR list with per-PR remove/restore and a Remove PR Link item alongside the existing merge actions
  • Undo toast: every removal shows "Removed link to PR #N — Undo"

Plumbing: pullRequests.unlinkFromWorkspace takes an optional pullRequestNumber and returns the removed number (for the undo toast); new pullRequests.relinkToWorkspace clears one PR's suppression. The legacy v1 WorkspaceSidebar is untouched (no stored link, being sunset). The collapsed sidebar keeps its state-colored icon; its context menu has the same remove/restore actions.

How I tested it

  • bun test packages/host-service/src/runtime/pull-requests/ — 36 pass against a real migrated in-memory SQLite DB, including: unlink suppresses and the sweep does not re-link; a different PR still links; two open PRs are both tracked and removing the badge PR falls through to the other immediately; removing a specific non-badge PR keeps the badge; removing every PR leaves no badge across sweeps; relink restores the badge and survives the next sweep; relinking a non-primary PR does not steal the badge; deleting the suppressed PR row cascades; an explicit checkout link clears suppression.
  • bun run lint clean; tsc --noEmit passes for @superset/host-service and @superset/desktop.
  • Verified end-to-end over CDP in the running dev desktop app: migration applies at boot; the live sweep populated junction rows from real GitHub data; badge count chip, dropdown list, per-PR remove, badge fallthrough, undo toast, Removed section restore, and the context-menu Restore submenu were all exercised against a workspace linked to this very PR (with a seeded second PR to simulate the multi-PR state — a bonus finding was watching the real sweep correctly prune the fake PR while preserving the suppressed row).

Checklist

  • PR title follows conventional commits (type(scope): subject)
  • bun run lint and bun run typecheck pass (CI fails on lint warnings too)
  • "Allow edits from maintainers" is checked on fork PRs

Summary by CodeRabbit

  • New Features
    • Added support for multiple pull requests per workspace.
    • Workspace menus now list active and removed pull requests.
    • Added options to remove, restore, and relink individual pull-request associations.
    • Pull-request links can be opened directly from the workspace sidebar.
  • Bug Fixes
    • Removed pull requests remain unlinked during automatic refreshes.
    • Workspace links now update correctly when pull requests are deleted, replaced, or restored.