Skip to content

Commit e3e6509

Browse files
committed
WIP
1 parent c97d246 commit e3e6509

3 files changed

Lines changed: 54 additions & 11 deletions

File tree

apps/webapp/app/models/runtimeEnvironment.server.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ export async function findEnvironmentByApiKey(
9999
...authIncludeBase,
100100
childEnvironments: branchName
101101
? {
102-
where: {
103-
branchName: sanitizeBranchName(branchName),
104-
archivedAt: null,
105-
},
106-
}
102+
where: {
103+
branchName: sanitizeBranchName(branchName),
104+
archivedAt: null,
105+
},
106+
}
107107
: undefined,
108108
} satisfies Prisma.RuntimeEnvironmentInclude;
109109

@@ -162,6 +162,25 @@ export async function findEnvironmentByApiKey(
162162
return null;
163163
}
164164

165+
// If there is no branch name (or "default"), then fall back to regular behavior, return root env
166+
if (environment.type === "DEVELOPMENT" && branchName !== undefined && branchName !== "default") {
167+
const childEnvironment = environment.childEnvironments.at(0);
168+
169+
if (childEnvironment) {
170+
return toAuthenticated({
171+
...childEnvironment,
172+
apiKey: environment.apiKey,
173+
orgMember: environment.orgMember,
174+
organization: environment.organization,
175+
project: environment.project,
176+
});
177+
}
178+
179+
//A branch was specified but no child environment was found
180+
return null;
181+
182+
}
183+
165184
return toAuthenticated(environment);
166185
}
167186

packages/cli-v3/src/commands/dev.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const DevCommandOptions = CommonCommandOptions.extend({
3232
debugOtel: z.boolean().default(false),
3333
config: z.string().optional(),
3434
projectRef: z.string().optional(),
35+
branch: z.string().optional().default("branch"),
3536
skipUpdateCheck: z.boolean().default(false),
3637
skipPlatformNotifications: z.boolean().default(false),
3738
envFile: z.string().optional(),
@@ -57,6 +58,11 @@ export function configureDevCommand(program: Command) {
5758
"-p, --project-ref <project ref>",
5859
"The project ref. Required if there is no config file."
5960
)
61+
.option(
62+
"-b, --branch <branch>",
63+
"The dev branch to use. If not provided, we'll use the default branch."
64+
"default",
65+
)
6066
.option(
6167
"--env-file <env file>",
6268
"Path to the .env file to use for the dev session. Defaults to .env in the project directory."
@@ -164,8 +170,7 @@ export async function devCommand(options: DevCommandOptions) {
164170
);
165171
} else {
166172
logger.log(
167-
`${chalkError("X Error:")} You must login first. Use the \`login\` CLI command.\n\n${
168-
authorization.error
173+
`${chalkError("X Error:")} You must login first. Use the \`login\` CLI command.\n\n${authorization.error
169174
}`
170175
);
171176
}
@@ -201,9 +206,9 @@ async function startDev(options: StartDevOptions) {
201206
const notificationPromise = options.skipPlatformNotifications
202207
? undefined
203208
: fetchPlatformNotification({
204-
apiClient: new CliApiClient(options.login.auth.apiUrl, options.login.auth.accessToken),
205-
projectRef: options.projectRef,
206-
});
209+
apiClient: new CliApiClient(options.login.auth.apiUrl, options.login.auth.accessToken),
210+
projectRef: options.projectRef,
211+
});
207212

208213
await printStandloneInitialBanner(true, options.profile);
209214

@@ -274,7 +279,7 @@ async function startDev(options: StartDevOptions) {
274279

275280
devInstance = await bootDevSession(watcher.config);
276281

277-
const waitUntilExit = async () => {};
282+
const waitUntilExit = async () => { };
278283

279284
return {
280285
watcher,

packages/core/src/v3/apiClient/getBranch.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,22 @@ export function getBranch({
3131

3232
return undefined;
3333
}
34+
35+
export function getDevBranch({
36+
specified,
37+
}: {
38+
specified?: string;
39+
}): string {
40+
if (specified) {
41+
return specified;
42+
}
43+
44+
// not specified, so detect our variable from process.env
45+
const envVar = getEnvVar("TRIGGER_DEV_BRANCH");
46+
if (envVar) {
47+
return envVar;
48+
}
49+
50+
// For development we don't look at git/Vercel
51+
return "default";
52+
}

0 commit comments

Comments
 (0)