@prisma/cli 3.0.0-dev.90.1 → 3.0.0-dev.91.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/controllers/app.js +10 -4
- package/dist/lib/app/read-branch.js +30 -0
- package/package.json +1 -1
package/dist/controllers/app.js
CHANGED
|
@@ -22,6 +22,7 @@ import { createDeployProgress, createDeployProgressState, createPromoteProgress
|
|
|
22
22
|
import { formatDomainFailureFix } from "../lib/app/domain-guidance.js";
|
|
23
23
|
import { DEFAULT_LOCAL_DEV_PORT, runLocalApp } from "../lib/app/local-dev.js";
|
|
24
24
|
import { enforceProductionDeployGate } from "../lib/app/production-deploy-gate.js";
|
|
25
|
+
import { resolveReadBranch } from "../lib/app/read-branch.js";
|
|
25
26
|
import { requireComputeAuth } from "../lib/auth/guard.js";
|
|
26
27
|
import { readAuthState } from "../lib/auth/auth-ops.js";
|
|
27
28
|
import { readLocalGitBranch } from "../lib/git/local-branch.js";
|
|
@@ -1584,13 +1585,18 @@ async function resolveProjectContext(context, client, explicitProject, options)
|
|
|
1584
1585
|
});
|
|
1585
1586
|
if (resolvedResult.isErr()) throw projectResolutionErrorToCliError(resolvedResult.error);
|
|
1586
1587
|
const resolved = resolvedResult.value;
|
|
1587
|
-
const
|
|
1588
|
+
const requested = options?.branch ?? await resolveDeployBranch(context, void 0);
|
|
1589
|
+
const remoteBranch = options?.branch ? null : await resolveReadBranch(client, {
|
|
1590
|
+
projectId: resolved.project.id,
|
|
1591
|
+
branchName: requested.name,
|
|
1592
|
+
signal: context.runtime.signal
|
|
1593
|
+
});
|
|
1588
1594
|
return {
|
|
1589
1595
|
...resolved,
|
|
1590
|
-
branch: {
|
|
1596
|
+
branch: remoteBranch ?? {
|
|
1591
1597
|
id: null,
|
|
1592
|
-
name:
|
|
1593
|
-
kind: toBranchKind(
|
|
1598
|
+
name: requested.name,
|
|
1599
|
+
kind: toBranchKind(requested.name)
|
|
1594
1600
|
}
|
|
1595
1601
|
};
|
|
1596
1602
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/lib/app/read-branch.ts
|
|
2
|
+
/**
|
|
3
|
+
* Resolves the branch an app management command should read from, without ever
|
|
4
|
+
* creating one. Returns the branch whose `gitName` matches `branchName`, else
|
|
5
|
+
* the project's default branch, else null when the project has no branches.
|
|
6
|
+
*/
|
|
7
|
+
async function resolveReadBranch(client, options) {
|
|
8
|
+
const branches = [];
|
|
9
|
+
let cursor;
|
|
10
|
+
do {
|
|
11
|
+
const result = await client.GET("/v1/projects/{projectId}/branches", {
|
|
12
|
+
params: {
|
|
13
|
+
path: { projectId: options.projectId },
|
|
14
|
+
query: { cursor }
|
|
15
|
+
},
|
|
16
|
+
signal: options.signal
|
|
17
|
+
});
|
|
18
|
+
if (result.error || !result.data) throw new Error(`Failed to list branches for project ${options.projectId}: ${JSON.stringify(result.error)}`);
|
|
19
|
+
branches.push(...result.data.data);
|
|
20
|
+
cursor = result.data.pagination.hasMore ? result.data.pagination.nextCursor ?? void 0 : void 0;
|
|
21
|
+
} while (cursor);
|
|
22
|
+
const chosen = branches.find((branch) => branch.gitName === options.branchName) ?? branches.find((branch) => branch.isDefault) ?? null;
|
|
23
|
+
return chosen ? {
|
|
24
|
+
id: chosen.id,
|
|
25
|
+
name: chosen.gitName,
|
|
26
|
+
kind: chosen.role
|
|
27
|
+
} : null;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { resolveReadBranch };
|