Skip to content

Commit 10a305a

Browse files
committed
fix(release-list): apply smart env default for explicit org/project targets
The production environment auto-default only ran in the auto-detect override, not for explicit targets like sentry/cli. Move the env resolution into func() via resolveEnvForParsedTarget so it applies to explicit mode too. Shows "Environment: production (use -e to change)" hint when auto-defaulting.
1 parent 27d139c commit 10a305a

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

src/commands/release/list.ts

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import {
1414
listReleasesPaginated,
1515
type ReleaseSortValue,
1616
} from "../../lib/api-client.js";
17-
import { parseOrgProjectArg } from "../../lib/arg-parsing.js";
17+
import {
18+
type ParsedOrgProject,
19+
parseOrgProjectArg,
20+
} from "../../lib/arg-parsing.js";
1821
import {
1922
colorTag,
2023
escapeMarkdownInline,
@@ -520,7 +523,7 @@ async function handleAutoDetectWithProject(
520523
};
521524
}
522525

523-
/** Apply smart production env default from the primary target. */
526+
/** Apply smart production env default from a resolved target. */
524527
async function applySmartEnvDefault(
525528
extra: ExtraApiOptions,
526529
primary?: ResolvedTarget
@@ -532,6 +535,27 @@ async function applySmartEnvDefault(
532535
return env ? { ...extra, environment: env } : extra;
533536
}
534537

538+
/**
539+
* Apply smart production env default from the parsed target argument.
540+
*
541+
* For explicit targets (`org/project`), resolves the environment immediately.
542+
* For auto-detect, the override handler applies its own default.
543+
* For org-all and project-search, skipped (no reliable project to check).
544+
*/
545+
async function resolveEnvForParsedTarget(
546+
extra: ExtraApiOptions,
547+
parsed: ParsedOrgProject
548+
): Promise<ExtraApiOptions> {
549+
if (extra.environment) {
550+
return extra;
551+
}
552+
if (parsed.type === "explicit") {
553+
const env = await resolveDefaultEnvironment(parsed.org, parsed.project);
554+
return env ? { ...extra, environment: env } : extra;
555+
}
556+
return extra;
557+
}
558+
535559
// ---------------------------------------------------------------------------
536560
// Flags
537561
// ---------------------------------------------------------------------------
@@ -668,7 +692,12 @@ export const listCommand = buildListCommand("release", {
668692
statsPeriod: flags.period,
669693
status: flags.status,
670694
};
671-
const config = buildReleaseListConfig(extra);
695+
696+
// Smart env default: when no -e given and we know the project, check
697+
// if "production"/"prod" exists and auto-select it. Applies to explicit
698+
// (org/project), project-search (bare slug), and auto-detect modes.
699+
const resolvedExtra = await resolveEnvForParsedTarget(extra, parsed);
700+
const config = buildReleaseListConfig(resolvedExtra);
672701
const result = await dispatchOrgScopedList({
673702
config,
674703
cwd,
@@ -677,11 +706,23 @@ export const listCommand = buildListCommand("release", {
677706
orgSlugMatchBehavior: "redirect",
678707
overrides: {
679708
"auto-detect": (ctx: HandlerContext<"auto-detect">) =>
680-
handleAutoDetectWithProject(extra, ctx),
709+
handleAutoDetectWithProject(resolvedExtra, ctx),
681710
},
682711
});
683712
yield new CommandOutput(result);
684-
const hint = result.items.length > 0 ? result.hint : undefined;
713+
const hintParts: string[] = [];
714+
if (result.hint) {
715+
hintParts.push(result.hint);
716+
}
717+
if (resolvedExtra.environment && !envFilter) {
718+
hintParts.push(
719+
`Environment: ${resolvedExtra.environment.join(", ")} (use -e to change)`
720+
);
721+
}
722+
const hint =
723+
result.items.length > 0 && hintParts.length > 0
724+
? hintParts.join("\n")
725+
: undefined;
685726
return { hint };
686727
},
687728
});

0 commit comments

Comments
 (0)