@prisma/cli 3.0.0-dev.57.1 → 3.0.0-dev.58.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/README.md +2 -2
- package/dist/commands/branch/index.js +2 -27
- package/dist/controllers/branch.js +73 -47
- package/dist/presenters/branch.js +29 -101
- package/dist/shell/command-meta.js +3 -23
- package/dist/shell/ui.js +4 -1
- package/dist/use-cases/branch.js +20 -68
- package/dist/use-cases/create-cli-gateways.js +2 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ The beta package exposes `prisma-cli` so it can coexist with the existing
|
|
|
74
74
|
| `auth` | Log in, log out, and inspect the active Prisma account. |
|
|
75
75
|
| `project` | List projects, show the resolved project, and manage project environment variables. |
|
|
76
76
|
| `git` | Connect or disconnect a project from a GitHub repository. |
|
|
77
|
-
| `branch` |
|
|
77
|
+
| `branch` | List Prisma branches for the resolved project. |
|
|
78
78
|
| `app` | Build, run, deploy, inspect, open, stream logs, promote, roll back, and remove apps. |
|
|
79
79
|
|
|
80
80
|
Common examples:
|
|
@@ -83,7 +83,7 @@ Common examples:
|
|
|
83
83
|
npx prisma-cli version
|
|
84
84
|
npx prisma-cli auth whoami
|
|
85
85
|
npx prisma-cli project show
|
|
86
|
-
npx prisma-cli branch
|
|
86
|
+
npx prisma-cli branch list
|
|
87
87
|
npx prisma-cli app deploy --branch feat-login --framework nextjs
|
|
88
88
|
npx prisma-cli app promote <deployment-id>
|
|
89
89
|
```
|
|
@@ -2,16 +2,14 @@ import { attachCommandDescriptor } from "../../shell/command-meta.js";
|
|
|
2
2
|
import { addCompactGlobalFlags, addGlobalFlags } from "../../shell/global-flags.js";
|
|
3
3
|
import { configureRuntimeCommand } from "../../shell/runtime.js";
|
|
4
4
|
import { runCommand } from "../../shell/command-runner.js";
|
|
5
|
-
import { runBranchList
|
|
6
|
-
import { renderBranchList,
|
|
5
|
+
import { runBranchList } from "../../controllers/branch.js";
|
|
6
|
+
import { renderBranchList, serializeBranchList } from "../../presenters/branch.js";
|
|
7
7
|
import { Command } from "commander";
|
|
8
8
|
//#region src/commands/branch/index.ts
|
|
9
9
|
function createBranchCommand(runtime) {
|
|
10
10
|
const branch = attachCommandDescriptor(configureRuntimeCommand(new Command("branch"), runtime), "branch");
|
|
11
11
|
addCompactGlobalFlags(branch);
|
|
12
12
|
branch.addCommand(createBranchListCommand(runtime));
|
|
13
|
-
branch.addCommand(createBranchShowCommand(runtime));
|
|
14
|
-
branch.addCommand(createBranchUseCommand(runtime));
|
|
15
13
|
return branch;
|
|
16
14
|
}
|
|
17
15
|
function createBranchListCommand(runtime) {
|
|
@@ -25,28 +23,5 @@ function createBranchListCommand(runtime) {
|
|
|
25
23
|
});
|
|
26
24
|
return command;
|
|
27
25
|
}
|
|
28
|
-
function createBranchShowCommand(runtime) {
|
|
29
|
-
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("show"), runtime), "branch.show");
|
|
30
|
-
addGlobalFlags(command);
|
|
31
|
-
command.action(async (options) => {
|
|
32
|
-
await runCommand(runtime, "branch.show", options, (context) => runBranchShow(context), {
|
|
33
|
-
renderHuman: (context, descriptor, result) => renderBranchShow(context, descriptor, result),
|
|
34
|
-
renderJson: (result) => serializeBranchShow(result)
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
return command;
|
|
38
|
-
}
|
|
39
|
-
function createBranchUseCommand(runtime) {
|
|
40
|
-
const command = attachCommandDescriptor(configureRuntimeCommand(new Command("use"), runtime), "branch.use");
|
|
41
|
-
command.argument("[name]", "Branch name");
|
|
42
|
-
addGlobalFlags(command);
|
|
43
|
-
command.action(async (branchName, options) => {
|
|
44
|
-
await runCommand(runtime, "branch.use", options, (context) => runBranchUse(context, branchName), {
|
|
45
|
-
renderHuman: (context, descriptor, result) => renderBranchUse(context, descriptor, result),
|
|
46
|
-
renderJson: (result) => serializeBranchShow(result)
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
return command;
|
|
50
|
-
}
|
|
51
26
|
//#endregion
|
|
52
27
|
export { createBranchCommand };
|
|
@@ -1,73 +1,99 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CliError, authRequiredError, workspaceRequiredError } from "../shell/errors.js";
|
|
2
|
+
import { requireComputeAuth } from "../lib/auth/guard.js";
|
|
3
|
+
import { resolveProjectTarget } from "../lib/project/resolution.js";
|
|
3
4
|
import { createCliUseCaseGateways } from "../use-cases/create-cli-gateways.js";
|
|
4
5
|
import { createSelectPromptPort } from "./select-prompt-port.js";
|
|
6
|
+
import { requireAuthenticatedAuthState } from "./auth.js";
|
|
7
|
+
import { listRealWorkspaceProjects } from "./project.js";
|
|
5
8
|
import { createBranchUseCases } from "../use-cases/branch.js";
|
|
6
9
|
//#region src/controllers/branch.ts
|
|
7
|
-
const PREVIEW_BRANCH_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
8
10
|
function isRealMode(context) {
|
|
9
11
|
return !context.runtime.fixturePath && !context.runtime.env.PRISMA_CLI_MOCK_FIXTURE_PATH;
|
|
10
12
|
}
|
|
11
13
|
async function runBranchList(context) {
|
|
12
|
-
if (isRealMode(context))
|
|
13
|
-
return {
|
|
14
|
+
if (isRealMode(context)) return {
|
|
14
15
|
command: "branch.list",
|
|
15
|
-
result: await
|
|
16
|
+
result: await listRealBranches(context),
|
|
16
17
|
warnings: [],
|
|
17
18
|
nextSteps: []
|
|
18
19
|
};
|
|
19
|
-
}
|
|
20
|
-
async function runBranchShow(context) {
|
|
21
|
-
if (isRealMode(context)) throw branchCommandsUnavailableError();
|
|
22
|
-
const result = await createBranchUseCases(createCliUseCaseGateways(context)).show();
|
|
23
20
|
return {
|
|
24
|
-
command: "branch.
|
|
25
|
-
result,
|
|
21
|
+
command: "branch.list",
|
|
22
|
+
result: await createBranchUseCases(createCliUseCaseGateways(context)).list(),
|
|
26
23
|
warnings: [],
|
|
27
|
-
nextSteps:
|
|
24
|
+
nextSteps: []
|
|
28
25
|
};
|
|
29
26
|
}
|
|
30
|
-
async function
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
async function listRealBranches(context) {
|
|
28
|
+
const authState = await requireAuthenticatedAuthState(context);
|
|
29
|
+
const client = await requireComputeAuth(context.runtime.env, context.runtime.signal);
|
|
30
|
+
if (!client) throw authRequiredError(["prisma-cli auth login"]);
|
|
31
|
+
const workspace = authState.workspace;
|
|
32
|
+
if (!workspace) throw workspaceRequiredError();
|
|
33
|
+
const target = await resolveProjectTarget({
|
|
34
|
+
context,
|
|
35
|
+
workspace,
|
|
36
|
+
listProjects: () => listRealWorkspaceProjects(client, workspace, context.runtime.signal),
|
|
37
|
+
prompt: createSelectPromptPort(context),
|
|
38
|
+
remember: true
|
|
39
|
+
});
|
|
40
|
+
const branches = await listBranches(client, target.project.id, context.runtime.signal);
|
|
36
41
|
return {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
nextSteps: result.branch.kind === "preview" && !result.branch.remoteState ? ["prisma-cli branch show", "prisma-cli app deploy"] : ["prisma-cli branch show"]
|
|
42
|
+
projectId: target.project.id,
|
|
43
|
+
projectName: target.project.name,
|
|
44
|
+
branches: sortBranches(branches.map(toBranchSummary))
|
|
41
45
|
};
|
|
42
46
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
choices: result.branches.map((branch) => ({
|
|
50
|
-
label: renderBranchChoiceLabel(branch),
|
|
51
|
-
value: branch.name
|
|
52
|
-
}))
|
|
47
|
+
function sortBranches(branches) {
|
|
48
|
+
return branches.slice().sort((left, right) => {
|
|
49
|
+
const leftRank = branchOrder(left);
|
|
50
|
+
const rightRank = branchOrder(right);
|
|
51
|
+
if (leftRank !== rightRank) return leftRank - rightRank;
|
|
52
|
+
return left.name.localeCompare(right.name);
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
if (branch.active) markers.push("active");
|
|
58
|
-
if (!branch.remoteState) markers.push("not created yet");
|
|
59
|
-
return markers.length > 0 ? `${branch.name} (${markers.join(", ")})` : branch.name;
|
|
55
|
+
function branchOrder(branch) {
|
|
56
|
+
return branch.role === "production" ? 0 : 1;
|
|
60
57
|
}
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
async function listBranches(client, projectId, signal) {
|
|
59
|
+
const collected = [];
|
|
60
|
+
let cursor;
|
|
61
|
+
while (true) {
|
|
62
|
+
const query = {};
|
|
63
|
+
if (cursor !== void 0) query.cursor = cursor;
|
|
64
|
+
const { data, error, response } = await client.GET("/v1/projects/{projectId}/branches", {
|
|
65
|
+
params: {
|
|
66
|
+
path: { projectId },
|
|
67
|
+
query
|
|
68
|
+
},
|
|
69
|
+
signal
|
|
70
|
+
});
|
|
71
|
+
if (error || !data) throw branchApiError("Failed to list branches", response, error);
|
|
72
|
+
collected.push(...data.data);
|
|
73
|
+
if (!data.pagination.hasMore || !data.pagination.nextCursor) break;
|
|
74
|
+
cursor = data.pagination.nextCursor;
|
|
75
|
+
}
|
|
76
|
+
return collected;
|
|
65
77
|
}
|
|
66
|
-
function
|
|
67
|
-
return
|
|
78
|
+
function toBranchSummary(branch) {
|
|
79
|
+
return {
|
|
80
|
+
id: branch.id,
|
|
81
|
+
name: branch.gitName,
|
|
82
|
+
role: branch.role,
|
|
83
|
+
envMap: branch.role
|
|
84
|
+
};
|
|
68
85
|
}
|
|
69
|
-
function
|
|
70
|
-
|
|
86
|
+
function branchApiError(summary, response, error) {
|
|
87
|
+
const status = response?.status ?? 0;
|
|
88
|
+
return new CliError({
|
|
89
|
+
code: error?.error?.code ?? "BRANCH_API_ERROR",
|
|
90
|
+
domain: "branch",
|
|
91
|
+
summary,
|
|
92
|
+
why: error?.error?.message ?? `The Management API returned status ${status || "unknown"}.`,
|
|
93
|
+
fix: error?.error?.hint ?? "Re-run with --trace for the underlying API response details.",
|
|
94
|
+
exitCode: 1,
|
|
95
|
+
nextSteps: []
|
|
96
|
+
});
|
|
71
97
|
}
|
|
72
98
|
//#endregion
|
|
73
|
-
export { runBranchList
|
|
99
|
+
export { runBranchList };
|
|
@@ -1,111 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { formatColumns } from "../shell/ui.js";
|
|
2
|
+
import { formatDescriptorLabel } from "../shell/command-meta.js";
|
|
2
3
|
//#region src/presenters/branch.ts
|
|
3
4
|
function renderBranchList(context, descriptor, result) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
5
|
+
const ui = context.ui;
|
|
6
|
+
const lines = [`${ui.strong(formatDescriptorLabel(descriptor))} ${ui.dim("→")} ${ui.dim("Listing branches for the resolved project.")}`, ""];
|
|
7
|
+
const rail = ui.dim("│");
|
|
8
|
+
lines.push(`${rail} ${ui.accent("project:")} ${result.projectName}`);
|
|
9
|
+
lines.push(rail);
|
|
10
|
+
if (result.branches.length === 0) {
|
|
11
|
+
lines.push(`${rail} ${ui.dim("No branches found.")}`);
|
|
12
|
+
return lines;
|
|
13
|
+
}
|
|
14
|
+
const widths = [
|
|
15
|
+
Math.max(4, ...result.branches.map((branch) => branch.name.length)),
|
|
16
|
+
Math.max(4, ...result.branches.map((branch) => branch.role.length)),
|
|
17
|
+
Math.max(7, ...result.branches.map((branch) => branch.envMap.length))
|
|
18
|
+
];
|
|
19
|
+
lines.push(`${rail} ${ui.accent(formatColumns([
|
|
20
|
+
"Name",
|
|
21
|
+
"Role",
|
|
22
|
+
"Env map"
|
|
23
|
+
], widths))}`);
|
|
24
|
+
for (const branch of result.branches) lines.push(`${rail} ${formatColumns([
|
|
25
|
+
branch.name,
|
|
26
|
+
branch.role,
|
|
27
|
+
branch.envMap
|
|
28
|
+
], widths)}`);
|
|
29
|
+
return lines;
|
|
19
30
|
}
|
|
20
31
|
function serializeBranchList(result) {
|
|
21
|
-
return serializeList({
|
|
22
|
-
context: { project: result.projectName ?? "not resolved" },
|
|
23
|
-
items: result.branches.map((branch) => ({
|
|
24
|
-
noun: "branch",
|
|
25
|
-
label: branch.name,
|
|
26
|
-
id: branch.id,
|
|
27
|
-
status: branch.active ? "active" : null
|
|
28
|
-
}))
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
function serializeBranchShow(result) {
|
|
32
32
|
return {
|
|
33
33
|
projectId: result.projectId,
|
|
34
34
|
projectName: result.projectName,
|
|
35
|
-
|
|
36
|
-
name: result.branch.name,
|
|
37
|
-
kind: result.branch.kind,
|
|
38
|
-
active: result.branch.active,
|
|
39
|
-
remoteState: result.branch.remoteState,
|
|
40
|
-
liveDeployment: result.branch.liveDeployment
|
|
41
|
-
}
|
|
35
|
+
branches: result.branches
|
|
42
36
|
};
|
|
43
37
|
}
|
|
44
|
-
function renderBranchShow(context, descriptor, result) {
|
|
45
|
-
const fields = [
|
|
46
|
-
{
|
|
47
|
-
key: "project",
|
|
48
|
-
value: result.projectName ?? "not resolved",
|
|
49
|
-
tone: result.projectName ? "default" : "dim"
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
key: "branch",
|
|
53
|
-
value: result.branch.name,
|
|
54
|
-
tone: result.branch.active ? "success" : "default"
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
key: "kind",
|
|
58
|
-
value: result.branch.kind
|
|
59
|
-
}
|
|
60
|
-
];
|
|
61
|
-
if (result.branch.liveDeployment) {
|
|
62
|
-
fields.push({
|
|
63
|
-
key: "status",
|
|
64
|
-
value: result.branch.liveDeployment.status,
|
|
65
|
-
tone: toneForDeploymentStatus(result.branch.liveDeployment.status)
|
|
66
|
-
});
|
|
67
|
-
if (result.branch.liveDeployment.url) fields.push({
|
|
68
|
-
key: "url",
|
|
69
|
-
value: result.branch.liveDeployment.url,
|
|
70
|
-
tone: "link"
|
|
71
|
-
});
|
|
72
|
-
} else if (!result.branch.remoteState) fields.push({
|
|
73
|
-
key: "remote state",
|
|
74
|
-
value: "not created yet",
|
|
75
|
-
tone: "dim"
|
|
76
|
-
});
|
|
77
|
-
return renderShow({
|
|
78
|
-
title: "Showing the current active branch context.",
|
|
79
|
-
descriptor,
|
|
80
|
-
fields
|
|
81
|
-
}, context.ui);
|
|
82
|
-
}
|
|
83
|
-
function toneForDeploymentStatus(status) {
|
|
84
|
-
if (status === "ready" || status === "active" || status === "healthy") return "success";
|
|
85
|
-
if (status === "pending" || status === "building" || status === "starting") return "warning";
|
|
86
|
-
if (status === "failed" || status === "error") return "error";
|
|
87
|
-
return "default";
|
|
88
|
-
}
|
|
89
|
-
function renderBranchUse(context, descriptor, result) {
|
|
90
|
-
return renderMutate({
|
|
91
|
-
title: "Changing the local default branch context.",
|
|
92
|
-
descriptor,
|
|
93
|
-
context: [{
|
|
94
|
-
key: "project",
|
|
95
|
-
value: result.projectName ?? "not resolved",
|
|
96
|
-
tone: result.projectName ? "default" : "dim"
|
|
97
|
-
}, {
|
|
98
|
-
key: "branch",
|
|
99
|
-
value: result.branch.name
|
|
100
|
-
}],
|
|
101
|
-
operationDescription: "Applying active branch change",
|
|
102
|
-
operationCount: 1,
|
|
103
|
-
details: ["Active branch updated in local CLI state for this repo."],
|
|
104
|
-
alerts: result.branch.kind === "production" ? [{
|
|
105
|
-
tone: "warning",
|
|
106
|
-
text: "Production is protected and durable. Use with care"
|
|
107
|
-
}] : void 0
|
|
108
|
-
}, context.ui);
|
|
109
|
-
}
|
|
110
38
|
//#endregion
|
|
111
|
-
export { renderBranchList,
|
|
39
|
+
export { renderBranchList, serializeBranchList };
|
|
@@ -69,8 +69,8 @@ const DESCRIPTORS = [
|
|
|
69
69
|
{
|
|
70
70
|
id: "branch",
|
|
71
71
|
path: ["prisma", "branch"],
|
|
72
|
-
description: "View your
|
|
73
|
-
examples: ["prisma-cli branch list"
|
|
72
|
+
description: "View your Platform branches",
|
|
73
|
+
examples: ["prisma-cli branch list"]
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
id: "git",
|
|
@@ -153,29 +153,9 @@ const DESCRIPTORS = [
|
|
|
153
153
|
"branch",
|
|
154
154
|
"list"
|
|
155
155
|
],
|
|
156
|
-
description: "List
|
|
156
|
+
description: "List Platform branches for the resolved project",
|
|
157
157
|
examples: ["prisma-cli branch list", "prisma-cli branch list --json"]
|
|
158
158
|
},
|
|
159
|
-
{
|
|
160
|
-
id: "branch.show",
|
|
161
|
-
path: [
|
|
162
|
-
"prisma",
|
|
163
|
-
"branch",
|
|
164
|
-
"show"
|
|
165
|
-
],
|
|
166
|
-
description: "Show the Platform branch matching your current Git branch",
|
|
167
|
-
examples: ["prisma-cli branch show", "prisma-cli branch show --json"]
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
id: "branch.use",
|
|
171
|
-
path: [
|
|
172
|
-
"prisma",
|
|
173
|
-
"branch",
|
|
174
|
-
"use"
|
|
175
|
-
],
|
|
176
|
-
description: "Change the local default branch context.",
|
|
177
|
-
examples: ["prisma-cli branch use", "prisma-cli branch use production"]
|
|
178
|
-
},
|
|
179
159
|
{
|
|
180
160
|
id: "app.build",
|
|
181
161
|
path: [
|
package/dist/shell/ui.js
CHANGED
|
@@ -48,6 +48,9 @@ function renderNextSteps(steps) {
|
|
|
48
48
|
...steps.map((step) => `- ${step}`)
|
|
49
49
|
];
|
|
50
50
|
}
|
|
51
|
+
function formatColumns(columns, widths) {
|
|
52
|
+
return columns.map((value, index) => padDisplay(value, widths[index])).join(" ").trimEnd();
|
|
53
|
+
}
|
|
51
54
|
function wrapText(text, width, indent = "") {
|
|
52
55
|
return wrapAnsi(text, width, {
|
|
53
56
|
hard: false,
|
|
@@ -74,4 +77,4 @@ function formatHeaderValue(ui, row) {
|
|
|
74
77
|
return value;
|
|
75
78
|
}
|
|
76
79
|
//#endregion
|
|
77
|
-
export { createShellUi, maskValue, padDisplay, renderCommandHeader, renderNextSteps, renderSummaryLine, wrapText };
|
|
80
|
+
export { createShellUi, formatColumns, maskValue, padDisplay, renderCommandHeader, renderNextSteps, renderSummaryLine, wrapText };
|
package/dist/use-cases/branch.js
CHANGED
|
@@ -1,34 +1,19 @@
|
|
|
1
1
|
//#region src/use-cases/branch.ts
|
|
2
2
|
function createBranchUseCases(dependencies) {
|
|
3
|
-
return {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
projectId,
|
|
18
|
-
projectName: resolveProjectName(dependencies.projectGateway, projectId),
|
|
19
|
-
branch: buildBranchDetail(dependencies.branchGateway, projectId, activeBranch)
|
|
20
|
-
};
|
|
21
|
-
},
|
|
22
|
-
use: async (branchName) => {
|
|
23
|
-
await dependencies.branchStateGateway.writeActiveBranch(branchName);
|
|
24
|
-
const projectId = await dependencies.projectStateGateway.readRememberedProjectId();
|
|
25
|
-
return {
|
|
26
|
-
projectId,
|
|
27
|
-
projectName: resolveProjectName(dependencies.projectGateway, projectId),
|
|
28
|
-
branch: buildBranchDetail(dependencies.branchGateway, projectId, branchName)
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
};
|
|
3
|
+
return { list: async () => {
|
|
4
|
+
const projectId = await dependencies.projectStateGateway.readRememberedProjectId();
|
|
5
|
+
if (!projectId) return {
|
|
6
|
+
projectId: "",
|
|
7
|
+
projectName: "not resolved",
|
|
8
|
+
branches: []
|
|
9
|
+
};
|
|
10
|
+
const remoteBranches = await listRemoteBranches(dependencies.branchGateway, projectId);
|
|
11
|
+
return {
|
|
12
|
+
projectId,
|
|
13
|
+
projectName: resolveProjectName(dependencies.projectGateway, projectId) ?? "not resolved",
|
|
14
|
+
branches: buildBranchSummaries(remoteBranches)
|
|
15
|
+
};
|
|
16
|
+
} };
|
|
32
17
|
}
|
|
33
18
|
function resolveProjectName(projectGateway, projectId) {
|
|
34
19
|
if (!projectId) return null;
|
|
@@ -38,38 +23,13 @@ async function listRemoteBranches(branchGateway, projectId) {
|
|
|
38
23
|
if (!projectId) return [];
|
|
39
24
|
return branchGateway.listBranchesForProject(projectId);
|
|
40
25
|
}
|
|
41
|
-
function buildBranchSummaries(
|
|
42
|
-
|
|
43
|
-
for (const branch of remoteBranches) byName.set(branch.name, {
|
|
26
|
+
function buildBranchSummaries(remoteBranches) {
|
|
27
|
+
return sortBranches(remoteBranches.map((branch) => ({
|
|
44
28
|
id: branch.id,
|
|
45
29
|
name: branch.name,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
if (!byName.has(activeBranch)) byName.set(activeBranch, {
|
|
51
|
-
id: activeBranch,
|
|
52
|
-
name: activeBranch,
|
|
53
|
-
kind: toBranchKind(activeBranch),
|
|
54
|
-
active: true,
|
|
55
|
-
remoteState: false
|
|
56
|
-
});
|
|
57
|
-
return sortBranches([...byName.values()]);
|
|
58
|
-
}
|
|
59
|
-
function buildBranchDetail(branchGateway, projectId, branchName) {
|
|
60
|
-
const kind = toBranchKind(branchName);
|
|
61
|
-
const remoteBranch = projectId ? branchGateway.getBranchForProject(projectId, branchName) : void 0;
|
|
62
|
-
return {
|
|
63
|
-
name: branchName,
|
|
64
|
-
kind,
|
|
65
|
-
active: true,
|
|
66
|
-
remoteState: Boolean(remoteBranch),
|
|
67
|
-
liveDeployment: remoteBranch && remoteBranch.currentDeploymentId ? toLiveDeployment(branchGateway.getDeployment(remoteBranch.currentDeploymentId)) : null
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function toBranchKind(name) {
|
|
71
|
-
if (name === "production") return "production";
|
|
72
|
-
return "preview";
|
|
30
|
+
role: branch.role,
|
|
31
|
+
envMap: branch.role
|
|
32
|
+
})));
|
|
73
33
|
}
|
|
74
34
|
function sortBranches(branches) {
|
|
75
35
|
return branches.slice().sort((left, right) => {
|
|
@@ -80,16 +40,8 @@ function sortBranches(branches) {
|
|
|
80
40
|
});
|
|
81
41
|
}
|
|
82
42
|
function branchOrder(branch) {
|
|
83
|
-
if (branch.
|
|
43
|
+
if (branch.role === "production") return 0;
|
|
84
44
|
return 1;
|
|
85
45
|
}
|
|
86
|
-
function toLiveDeployment(deployment) {
|
|
87
|
-
if (!deployment) return null;
|
|
88
|
-
return {
|
|
89
|
-
id: deployment.id,
|
|
90
|
-
status: deployment.status,
|
|
91
|
-
url: deployment.url
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
46
|
//#endregion
|
|
95
47
|
export { createBranchUseCases };
|
|
@@ -29,16 +29,9 @@ function createCliUseCaseGateways(context) {
|
|
|
29
29
|
getProjectForWorkspace: (workspaceId, projectId) => context.api.getProjectForWorkspace(workspaceId, projectId)
|
|
30
30
|
},
|
|
31
31
|
branchGateway: {
|
|
32
|
-
listBranchesForProject: (projectId) => context.api.listBranchesForProject(projectId)
|
|
33
|
-
...branch,
|
|
34
|
-
kind: branch.name === "production" ? "production" : "preview"
|
|
35
|
-
})),
|
|
32
|
+
listBranchesForProject: (projectId) => context.api.listBranchesForProject(projectId),
|
|
36
33
|
getBranchForProject: (projectId, name) => {
|
|
37
|
-
|
|
38
|
-
return branch ? {
|
|
39
|
-
...branch,
|
|
40
|
-
kind: branch.name === "production" ? "production" : "preview"
|
|
41
|
-
} : void 0;
|
|
34
|
+
return context.api.getBranchForProject(projectId, name);
|
|
42
35
|
},
|
|
43
36
|
getDeployment: (deploymentId) => context.api.getDeployment(deploymentId)
|
|
44
37
|
},
|
|
@@ -55,14 +48,6 @@ function createCliUseCaseGateways(context) {
|
|
|
55
48
|
clearAuthSession: async () => {
|
|
56
49
|
await context.stateStore.clearAuthSession();
|
|
57
50
|
}
|
|
58
|
-
},
|
|
59
|
-
branchStateGateway: {
|
|
60
|
-
readActiveBranch: async () => {
|
|
61
|
-
return (await context.stateStore.read()).branch.active;
|
|
62
|
-
},
|
|
63
|
-
writeActiveBranch: async (branchName) => {
|
|
64
|
-
await context.stateStore.setActiveBranch(branchName);
|
|
65
|
-
}
|
|
66
51
|
}
|
|
67
52
|
};
|
|
68
53
|
}
|