Skip to content

Commit f14728d

Browse files
authored
fix(config): reconcile stale org/repo scope references (#122)
## Summary - `selectedOrgs` could retain logins no longer returned by `fetchOrgs()` (revoked/removed access), inflating the "N of M selected" counter past its live total — fixed by paginating `fetchOrgs()` fully and pruning stale entries with a notification - `customTabs[].orgScope`/`repoScope` had the same missing-reconciliation bug as `monitoredRepos` (which already prunes correctly) — `updateConfig()` now prunes both when `selectedRepos` shrinks - Empty custom tab scope now means "match nothing" instead of silently "match all repos", with a warning icon (TabBar + Settings) so an unscoped tab is never a silent state
1 parent 0399062 commit f14728d

16 files changed

Lines changed: 460 additions & 36 deletions

File tree

‎src/app/components/dashboard/DashboardPage.tsx‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import IssuesTab from "./IssuesTab";
88
import PullRequestsTab from "./PullRequestsTab";
99
import TrackedTab from "./TrackedTab";
1010
import PersonalSummaryStrip from "./PersonalSummaryStrip";
11-
import { config, setConfig, getCustomTab, isBuiltinTab, isActionsBasedTab, updateJiraConfig, type TrackedUser } from "../../stores/config";
11+
import { config, setConfig, getCustomTab, isBuiltinTab, isActionsBasedTab, isTabUnscoped, updateJiraConfig, type TrackedUser } from "../../stores/config";
1212
import { viewState, updateViewState, setSortPreference, pruneClosedTrackedItems, removeCustomTabState, untrackJiraItem, setTabFilter, IssueFiltersSchema, PullRequestFiltersSchema, ActionsFiltersSchema } from "../../stores/view";
1313
import DependenciesTab from "./DependenciesTab";
1414
import { isDependencyPr, expandBotLogins, needsBodyFallback, parseRenovateBody, type VersionInfo } from "../../lib/dependency-detection";
@@ -54,14 +54,18 @@ const ISSUE_FILTER_DEFAULTS = IssueFiltersSchema.parse({});
5454
const PR_FILTER_DEFAULTS = PullRequestFiltersSchema.parse({});
5555
const ACTIONS_FILTER_DEFAULTS = ActionsFiltersSchema.parse({});
5656

57-
/** Build a scope matcher for a custom tab's org/repo scope. Shared between customTabData and tabCounts. */
57+
/**
58+
* Build a scope matcher for a custom tab's org/repo scope. Shared between
59+
* customTabData and tabCounts. An empty scope (no orgs, no repos) matches
60+
* nothing — see isTabUnscoped, which flags this state for the UI.
61+
*/
5862
function buildTabScopeMatcher(tab: CustomTab): (repoFullName: string) => boolean {
5963
const orgSet = tab.orgScope.length > 0 ? new Set(tab.orgScope.map((o) => o.toLowerCase())) : null;
6064
const repoSet = tab.repoScope.length > 0 ? new Set(tab.repoScope.map((r) => r.fullName.toLowerCase())) : null;
6165
return (repoFullName: string) => {
6266
if (repoSet && repoSet.has(repoFullName.toLowerCase())) return true;
6367
if (orgSet && orgSet.has(repoFullName.split("/")[0].toLowerCase())) return true;
64-
return !orgSet && !repoSet;
68+
return false;
6569
};
6670
}
6771

@@ -1270,7 +1274,7 @@ export default function DashboardPage() {
12701274
enableActions={config.enableActions}
12711275
enableJira={!!config.jira?.enabled}
12721276
enableDependencies={enableDependencies()}
1273-
customTabs={config.customTabs.filter((t) => config.enableActions || t.baseType !== "actions").map((t) => ({ id: t.id, name: t.name }))}
1277+
customTabs={config.customTabs.filter((t) => config.enableActions || t.baseType !== "actions").map((t) => ({ id: t.id, name: t.name, isUnscoped: isTabUnscoped(t) }))}
12741278
onAddTab={() => setShowCustomTabModal(true)}
12751279
onEditTab={(id) => { setEditingTabId(id); setShowCustomTabModal(true); }}
12761280
/>

‎src/app/components/layout/TabBar.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface TabBarProps {
1414
enableActions?: boolean;
1515
enableJira?: boolean;
1616
enableDependencies?: boolean;
17-
customTabs?: Array<{ id: string; name: string }>;
17+
customTabs?: Array<{ id: string; name: string; isUnscoped?: boolean }>;
1818
onAddTab?: () => void;
1919
onEditTab?: (id: string) => void;
2020
}
@@ -77,6 +77,13 @@ export default function TabBar(props: TabBarProps) {
7777
{(tab) => (
7878
<div class="relative group/tab flex items-center">
7979
<Tabs.Trigger value={tab.id} class="tab compact:tab-sm data-[selected]:tab-active">
80+
<Show when={tab.isUnscoped}>
81+
<Tooltip content="Unscoped — this tab won't match any repos until you add scope">
82+
<svg class="h-3.5 w-3.5 text-warning mr-1" fill="currentColor" viewBox="0 0 20 20" aria-label="Unscoped tab" role="img">
83+
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l6.28 11.163c.75 1.333-.213 2.987-1.742 2.987H3.72c-1.53 0-2.492-1.654-1.743-2.987L8.257 3.1zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
84+
</svg>
85+
</Tooltip>
86+
</Show>
8087
{tab.name}
8188
<Show when={props.counts?.[tab.id] !== undefined}>
8289
<span class="badge badge-sm badge-neutral ml-1">{props.counts?.[tab.id]}</span>

‎src/app/components/onboarding/OrgSelector.tsx‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { createSignal, createResource, For, Show } from "solid-js";
1+
import { createSignal, createResource, createEffect, untrack, For, Show } from "solid-js";
22
import { fetchOrgs, OrgEntry } from "../../services/api";
33
import { getClient } from "../../services/github";
4+
import { pushNotification } from "../../lib/errors";
45
import LoadingSpinner from "../shared/LoadingSpinner";
56
import FilterInput from "../shared/FilterInput";
67

@@ -25,6 +26,26 @@ export default function OrgSelector(props: OrgSelectorProps) {
2526
return all.filter((o) => o.login.toLowerCase().includes(q));
2627
};
2728

29+
// Prune selectedOrgs entries no longer present in a fresh, fully-paginated
30+
// fetchOrgs() result — e.g. revoked/removed org access. Without this, a
31+
// stale login would inflate the "N selected" counters below past the live
32+
// total (selected.length could exceed orgs().length).
33+
createEffect(() => {
34+
const list = orgs();
35+
if (orgs.loading || orgs.error || !list) return;
36+
const liveLogins = new Set(list.map((o) => o.login.toLowerCase()));
37+
const current = untrack(() => props.selected);
38+
const stale = current.filter((login) => !liveLogins.has(login.toLowerCase()));
39+
if (stale.length === 0) return;
40+
const pruned = current.filter((login) => liveLogins.has(login.toLowerCase()));
41+
untrack(() => props.onChange(pruned));
42+
pushNotification(
43+
"org-prune",
44+
`Removed ${stale.length} organization${stale.length !== 1 ? "s" : ""} you no longer have access to (${stale.join(", ")})`,
45+
"warning"
46+
);
47+
});
48+
2849
const isSelected = (login: string) => props.selected.includes(login);
2950

3051
function toggleOrg(login: string) {

‎src/app/components/settings/CustomTabsSection.tsx‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createSignal, createMemo, For, Show } from "solid-js";
2-
import { config, removeCustomTab, reorderCustomTab } from "../../stores/config";
2+
import { config, removeCustomTab, reorderCustomTab, isTabUnscoped } from "../../stores/config";
33
import type { CustomTab } from "../../stores/config";
44
import type { RepoRef } from "../../services/api";
55
import CustomTabModal from "../shared/CustomTabModal";
@@ -82,7 +82,18 @@ export default function CustomTabsSection(props: CustomTabsSectionProps) {
8282
{baseTypeLabel(tab.baseType)}
8383
</span>
8484
</td>
85-
<td class="text-xs text-base-content/70">{formatScopeSummary(tab.orgScope.length, tab.repoScope.length, true)}</td>
85+
<td class="text-xs text-base-content/70">
86+
<span class="flex items-center gap-1">
87+
<Show when={isTabUnscoped(tab)}>
88+
<Tooltip content="Unscoped — this tab won't match any repos until you add scope">
89+
<svg class="h-3.5 w-3.5 text-warning shrink-0" fill="currentColor" viewBox="0 0 20 20" aria-label="Unscoped tab" role="img">
90+
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l6.28 11.163c.75 1.333-.213 2.987-1.742 2.987H3.72c-1.53 0-2.492-1.654-1.743-2.987L8.257 3.1zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
91+
</svg>
92+
</Tooltip>
93+
</Show>
94+
{formatScopeSummary(tab.orgScope.length, tab.repoScope.length, true)}
95+
</span>
96+
</td>
8697
<td class="text-center">
8798
{tab.exclusive ? (
8899
<svg class="h-4 w-4 text-success inline" fill="currentColor" viewBox="0 0 20 20" aria-label="Exclusive" role="img">

‎src/app/components/shared/CustomTabModal.tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ export default function CustomTabModal(props: CustomTabModalProps) {
6868

6969
const nameValid = createMemo(() => name().trim().length > 0 && name().trim().length <= 30);
7070

71+
const scopeIsEmpty = createMemo(() => selectedOrgs().size === 0 && selectedRepos().size === 0);
72+
7173
// User field group — dynamic, includes tracked user logins
7274
const userFieldGroup = createMemo((): FilterChipGroupDef => ({
7375
label: "User",
@@ -258,15 +260,20 @@ export default function CustomTabModal(props: CustomTabModalProps) {
258260
onClick={() => setScopeOpen((v) => !v)}
259261
>
260262
<span>Scope</span>
261-
<span class="text-base-content/50 text-xs">
263+
<span class="text-base-content/50 text-xs flex items-center gap-1">
264+
<Show when={scopeIsEmpty()}>
265+
<svg class="h-3.5 w-3.5 text-warning" fill="currentColor" viewBox="0 0 20 20" aria-label="Unscoped — matches no repos" role="img">
266+
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l6.28 11.163c.75 1.333-.213 2.987-1.742 2.987H3.72c-1.53 0-2.492-1.654-1.743-2.987L8.257 3.1zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
267+
</svg>
268+
</Show>
262269
{formatScopeSummary(selectedOrgs().size, selectedRepos().size)}
263270
<span class="ml-2">{scopeOpen() ? "▲" : "▼"}</span>
264271
</span>
265272
</button>
266273
<Show when={scopeOpen()}>
267274
<div id="custom-tab-scope-panel" class="p-3 space-y-3">
268275
<p class="text-xs text-base-content/50">
269-
Leave empty to include all repos. Org selection includes all repos in that org.
276+
Leave empty to match no repos — the tab will show a warning icon until scoped. Org selection includes all repos in that org.
270277
</p>
271278
<Show
272279
when={props.availableOrgs.length > 0}

‎src/app/lib/format.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function rateLimitCssClass(remaining: number, limit: number): string {
2222

2323
/** Format scope counts as "N org(s), M repo(s)". When elideZero is true, omit zero-count segments. */
2424
export function formatScopeSummary(orgCount: number, repoCount: number, elideZero = false): string {
25-
if (orgCount === 0 && repoCount === 0) return "All repos";
25+
if (orgCount === 0 && repoCount === 0) return "No repos selected";
2626
if (elideZero) {
2727
const parts: string[] = [];
2828
if (orgCount > 0) parts.push(`${orgCount} org${orgCount !== 1 ? "s" : ""}`);

‎src/app/services/api.ts‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,32 +1553,36 @@ function mapReviewDecision(
15531553

15541554
/**
15551555
* Returns orgs and the personal user account. Personal account is first.
1556+
* Fully paginates GET /user/orgs — a single-page fetch would silently
1557+
* truncate at 100 orgs for heavily-affiliated accounts.
15561558
*/
15571559
export async function fetchOrgs(
15581560
octokit: ReturnType<typeof getClient>
15591561
): Promise<OrgEntry[]> {
15601562
if (!octokit) throw new Error("No GitHub client available");
15611563

1562-
const [userResult, orgsResult] = await Promise.all([
1563-
cachedRequest(octokit, "orgs:user", "GET /user"),
1564-
cachedRequest(octokit, "orgs:all", "GET /user/orgs", { per_page: 100 }),
1565-
]);
1564+
const userPromise = cachedRequest(octokit, "orgs:user", "GET /user");
1565+
1566+
const orgEntries: OrgEntry[] = [];
1567+
const ORG_CAP = 1000;
1568+
for await (const response of octokit.paginate.iterator("GET /user/orgs", {
1569+
per_page: 100,
1570+
})) {
1571+
for (const org of response.data as RawOrg[]) {
1572+
orgEntries.push({ login: org.login, avatarUrl: org.avatar_url, type: "org" });
1573+
}
1574+
if (orgEntries.length >= ORG_CAP) break;
1575+
}
15661576

1577+
const userResult = await userPromise;
15671578
const user = userResult.data as RawUser;
1568-
const orgs = orgsResult.data as RawOrg[];
15691579

15701580
const personal: OrgEntry = {
15711581
login: user.login,
15721582
avatarUrl: user.avatar_url,
15731583
type: "user",
15741584
};
15751585

1576-
const orgEntries: OrgEntry[] = orgs.map((o) => ({
1577-
login: o.login,
1578-
avatarUrl: o.avatar_url,
1579-
type: "org",
1580-
}));
1581-
15821586
return [personal, ...orgEntries];
15831587
}
15841588

‎src/app/stores/config.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { z } from "zod";
99
// ── Re-exports from shared/schemas (backward compat for existing importers) ───
1010
export {
1111
ConfigSchema, RepoRefSchema, TrackedUserSchema, THEME_OPTIONS,
12-
CustomTabSchema, BUILTIN_TAB_IDS, isBuiltinTab, isActionsBasedTab,
12+
CustomTabSchema, BUILTIN_TAB_IDS, isBuiltinTab, isActionsBasedTab, isTabUnscoped,
1313
type Config, type TrackedUser, type ThemeId, type CustomTab, type BuiltinTabId,
1414
type JiraConfig,
1515
} from "../../shared/schemas";
@@ -82,6 +82,19 @@ export function updateConfig(partial: Partial<Config>): void {
8282
if ("selectedRepos" in partial) {
8383
const selectedSet = new Set(draft.selectedRepos.map((r) => r.fullName));
8484
draft.monitoredRepos = draft.monitoredRepos.filter((r) => selectedSet.has(r.fullName));
85+
86+
// customTabs scope is derived from selectedRepos (see CustomTabModal's
87+
// availableOrgs/availableRepos props) — prune scope entries that no
88+
// longer correspond to a tracked repo, same as monitoredRepos above.
89+
const ownerSet = new Set(draft.selectedRepos.map((r) => r.owner.toLowerCase()));
90+
draft.customTabs = draft.customTabs.map((tab) => {
91+
const filteredOrgScope = tab.orgScope.filter((o) => ownerSet.has(o.toLowerCase()));
92+
const filteredRepoScope = tab.repoScope.filter((r) => selectedSet.has(r.fullName));
93+
if (filteredOrgScope.length === tab.orgScope.length && filteredRepoScope.length === tab.repoScope.length) {
94+
return tab;
95+
}
96+
return { ...tab, orgScope: filteredOrgScope, repoScope: filteredRepoScope };
97+
});
8598
}
8699
})
87100
);

‎src/shared/schemas.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export function isActionsBasedTab(id: string, customTabs: readonly CustomTab[]):
5454
return id === "actions" || (!isBuiltinTab(id) && customTabs.some((t) => t.id === id && t.baseType === "actions"));
5555
}
5656

57+
/** A tab with no orgScope and no repoScope matches no repos — see buildTabScopeMatcher in DashboardPage.tsx. */
58+
export function isTabUnscoped(tab: Pick<CustomTab, "orgScope" | "repoScope">): boolean {
59+
return tab.orgScope.length === 0 && tab.repoScope.length === 0;
60+
}
61+
5762
export const JiraAuthMethodSchema = z.enum(["oauth", "token"]).default("oauth");
5863

5964
export const JiraCustomFieldSchema = z.object({

‎tests/components/DashboardPage.test.tsx‎

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,12 +1050,12 @@ describe("DashboardPage — tracked tab", () => {
10501050

10511051
describe("DashboardPage — exclusive custom tabs", () => {
10521052
it("exclusive issues tab removes claimed items from the builtin Issues badge", async () => {
1053-
// Add an exclusive issues custom tab that claims all repos
1053+
// Add an exclusive issues custom tab scoped to the fixture's default owner
10541054
configStore.addCustomTab({
10551055
id: "excl01",
10561056
name: "My Issues",
10571057
baseType: "issues",
1058-
orgScope: [],
1058+
orgScope: ["owner"],
10591059
repoScope: [],
10601060
filterPreset: {},
10611061
exclusive: true,
@@ -1083,7 +1083,7 @@ describe("DashboardPage — exclusive custom tabs", () => {
10831083
id: "excl02",
10841084
name: "Exclusive PRs",
10851085
baseType: "pullRequests",
1086-
orgScope: [],
1086+
orgScope: ["owner"],
10871087
repoScope: [],
10881088
filterPreset: {},
10891089
exclusive: true,
@@ -1144,7 +1144,7 @@ describe("DashboardPage — exclusive custom tabs", () => {
11441144
id: "first01",
11451145
name: "First Exclusive",
11461146
baseType: "issues",
1147-
orgScope: [],
1147+
orgScope: ["owner"],
11481148
repoScope: [],
11491149
filterPreset: {},
11501150
exclusive: true,
@@ -1153,7 +1153,7 @@ describe("DashboardPage — exclusive custom tabs", () => {
11531153
id: "second01",
11541154
name: "Second Exclusive",
11551155
baseType: "issues",
1156-
orgScope: [],
1156+
orgScope: ["owner"],
11571157
repoScope: [],
11581158
filterPreset: {},
11591159
exclusive: true,
@@ -1183,7 +1183,7 @@ describe("DashboardPage — exclusive custom tabs", () => {
11831183
id: "exclact01",
11841184
name: "My Actions",
11851185
baseType: "actions",
1186-
orgScope: [],
1186+
orgScope: ["owner"],
11871187
repoScope: [],
11881188
filterPreset: {},
11891189
exclusive: true,
@@ -1380,6 +1380,37 @@ describe("DashboardPage — custom tab scoping", () => {
13801380
expect(customTab.textContent?.replace(/\D+/g, "")).toBe("1");
13811381
});
13821382
});
1383+
1384+
it("a tab with empty orgScope and repoScope matches no items and shows the unscoped icon", async () => {
1385+
configStore.addCustomTab({
1386+
id: "unscoped01",
1387+
name: "Unscoped Tab",
1388+
baseType: "issues",
1389+
orgScope: [],
1390+
repoScope: [],
1391+
filterPreset: { scope: "all" },
1392+
exclusive: false,
1393+
});
1394+
vi.mocked(pollService.fetchAllData).mockResolvedValue({
1395+
issues: [
1396+
makeIssue({ id: 60, title: "Some issue", repoFullName: "owner/repo" }),
1397+
],
1398+
pullRequests: [],
1399+
workflowRuns: [],
1400+
errors: [],
1401+
});
1402+
1403+
render(() => <DashboardPage />);
1404+
await waitFor(() => {
1405+
// Empty scope now matches nothing — not "all repos" as it did previously.
1406+
const customTab = screen.getByRole("tab", { name: /Unscoped Tab/ });
1407+
expect(customTab.textContent?.replace(/\D+/g, "")).toBe("0");
1408+
// The builtin Issues tab is unaffected — it still shows the item.
1409+
const issuesTab = screen.getByRole("tab", { name: /^Issues/ });
1410+
expect(issuesTab.textContent?.replace(/\D+/g, "")).toBe("1");
1411+
expect(screen.getByLabelText("Unscoped tab")).toBeDefined();
1412+
});
1413+
});
13831414
});
13841415

13851416
// ── resolveInitialTab stale custom tab fallback ──────────────────────────────
@@ -1535,7 +1566,7 @@ describe("DashboardPage — tabCounts applies filterPreset", () => {
15351566
id: "selfuser",
15361567
name: "My Items",
15371568
baseType: "issues",
1538-
orgScope: [],
1569+
orgScope: ["owner"],
15391570
repoScope: [],
15401571
filterPreset: { scope: "all", user: "_self" },
15411572
exclusive: false,
@@ -1567,7 +1598,7 @@ describe("DashboardPage — tabCounts applies filterPreset", () => {
15671598
id: "failures",
15681599
name: "Failed Runs",
15691600
baseType: "actions",
1570-
orgScope: [],
1601+
orgScope: ["owner"],
15711602
repoScope: [],
15721603
filterPreset: { conclusion: "failure" },
15731604
exclusive: false,

0 commit comments

Comments
 (0)