Skip to content

Commit b04ef40

Browse files
betegonclaude
andcommitted
refactor(alert): route org-all through handleResolvedOrgs in metrics list
Removes the separate handleOrgAllMetricAlerts handler and routes all 4 modes (including org-all) through handleResolvedOrgs. org-all resolves all projects in the specified org, deduplicates to unique orgs (just the one), then uses fetchWithBudget with compound cursor — same path as auto-detect/explicit/project-search. This makes the structure identical to alert issues list and supports multi-org results from DSN detection consistently across all modes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e816ecc commit b04ef40

File tree

1 file changed

+8
-84
lines changed

1 file changed

+8
-84
lines changed

src/commands/alert/metrics/list.ts

Lines changed: 8 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { parseOrgProjectArg } from "../../../lib/arg-parsing.js";
2121
import { openInBrowser } from "../../../lib/browser.js";
2222
import {
2323
advancePaginationState,
24-
buildOrgContextKey,
2524
buildPaginationContextKey,
2625
CURSOR_SEP,
2726
decodeCompoundCursor,
@@ -42,7 +41,6 @@ import {
4241
buildListLimitFlag,
4342
LIST_BASE_ALIASES,
4443
LIST_TARGET_POSITIONAL,
45-
paginationHint,
4644
parseCursorFlag,
4745
targetPatternExplanation,
4846
} from "../../../lib/list-command.js";
@@ -519,85 +517,6 @@ async function handleResolvedOrgs(
519517
};
520518
}
521519

522-
/**
523-
* Handle org-all mode: cursor-paginated listing of all metric alert rules in an org.
524-
*
525-
* Metric alerts are org-scoped, so this uses a single org-level cursor (not
526-
* compound) with full bidirectional navigation.
527-
*/
528-
async function handleOrgAllMetricAlerts(
529-
org: string,
530-
flags: ListFlags
531-
): Promise<MetricAlertListResult> {
532-
const contextKey = buildOrgContextKey(org);
533-
const { cursor: startCursor, direction } = resolveCursor(
534-
flags.cursor,
535-
PAGINATION_KEY,
536-
contextKey
537-
);
538-
539-
const fetchResult = await withProgress(
540-
{ message: `Fetching metric alert rules for ${org}...`, json: flags.json },
541-
() => fetchRulesForOrg(org, { limit: flags.limit, startCursor })
542-
);
543-
544-
if (!fetchResult.success) {
545-
throw fetchResult.error;
546-
}
547-
548-
const { rules, nextCursor } = fetchResult.data;
549-
550-
advancePaginationState(PAGINATION_KEY, contextKey, direction, nextCursor);
551-
const hasPrev = hasPreviousPage(PAGINATION_KEY, contextKey);
552-
553-
const filteredRows: MetricAlertRow[] = flags.query
554-
? rules
555-
.filter((rule) =>
556-
rule.name.toLowerCase().includes(flags.query?.toLowerCase() ?? "")
557-
)
558-
.map((rule) => ({ rule, orgSlug: org }))
559-
: rules.map((rule) => ({ rule, orgSlug: org }));
560-
561-
const nav = paginationHint({
562-
hasPrev,
563-
hasMore: !!nextCursor,
564-
prevHint: `sentry alert metrics list ${org}/ -c prev`,
565-
nextHint: `sentry alert metrics list ${org}/ -c next`,
566-
});
567-
568-
if (filteredRows.length === 0) {
569-
const hintParts: string[] = [`No metric alert rules found in '${org}'.`];
570-
if (nav) {
571-
hintParts.push(nav);
572-
}
573-
return {
574-
items: [],
575-
hasMore: !!nextCursor,
576-
hasPrev,
577-
hint: hintParts.join("\n"),
578-
};
579-
}
580-
581-
const hintParts: string[] = [
582-
`Showing ${filteredRows.length} rule(s)${nextCursor ? " (more available)" : ""}.`,
583-
`Metric alerts: ${buildMetricAlertsUrl(org)}`,
584-
];
585-
if (nav) {
586-
hintParts.push(nav);
587-
}
588-
589-
return {
590-
items: filteredRows.map((r) => r.rule),
591-
displayRows: filteredRows,
592-
hasMore: !!nextCursor,
593-
hasPrev,
594-
nextCursor,
595-
title: `Metric alert rules in ${org}`,
596-
footerMode: "single",
597-
hint: hintParts.join("\n"),
598-
};
599-
}
600-
601520
// ---------------------------------------------------------------------------
602521
// Human output
603522
// ---------------------------------------------------------------------------
@@ -739,13 +658,18 @@ export const listCommand = buildListCommand("alert", {
739658
flags,
740659
parsed,
741660
orgSlugMatchBehavior: "redirect",
742-
// Multi-org modes handle compound cursor pagination via handleResolvedOrgs
743-
allowCursorInModes: ["auto-detect", "explicit", "project-search"],
661+
// All modes use per-org fetching with compound cursor support
662+
allowCursorInModes: [
663+
"auto-detect",
664+
"explicit",
665+
"project-search",
666+
"org-all",
667+
],
744668
overrides: {
745669
"auto-detect": resolveAndHandle,
746670
explicit: resolveAndHandle,
747671
"project-search": resolveAndHandle,
748-
"org-all": (ctx) => handleOrgAllMetricAlerts(ctx.parsed.org, flags),
672+
"org-all": resolveAndHandle,
749673
},
750674
})) as MetricAlertListResult;
751675

0 commit comments

Comments
 (0)