Skip to content

Commit 5bca9b5

Browse files
authored
Svn main 001 rem (#6492)
* Change name from stack to backend * Change name from stack to backend * changed file names * changed file names in experiments * changed name * lower case backend * Changed stack to backend * change stack to backend in index file * List stacks in table * Backends for project message * resolve merge conflicts * removed linter errors * changed table head color to green * test method stack to backend * Changed stack to backend (#6488) * Changed stack to backend * change stack to backend in index file * List stacks in table * Backends for project message * Changed file names * removed linter errors * change file names from stack to backend * changed table head color to green * test method stack to backend * changed file name * Change Stack objects to Backend (#6490) * Change Stack objects to Backend * formatted files
1 parent 77bb790 commit 5bca9b5

File tree

4 files changed

+92
-80
lines changed

4 files changed

+92
-80
lines changed

src/gcp/frameworks.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ interface Codebase {
1616
rootDirectory: string;
1717
}
1818

19-
/** A Stack, the primary resource of Frameworks. */
20-
export interface Stack {
19+
/** A Backend, the primary resource of Frameworks. */
20+
export interface Backend {
2121
name: string;
2222
mode?: string;
2323
codebase: Codebase;
@@ -27,7 +27,7 @@ export interface Stack {
2727
uri: string;
2828
}
2929

30-
export type StackOutputOnlyFields = "name" | "createTime" | "updateTime" | "uri";
30+
export type BackendOutputOnlyFields = "name" | "createTime" | "updateTime" | "uri";
3131

3232
export interface Build {
3333
name: string;
@@ -82,21 +82,21 @@ export interface Operation {
8282
}
8383

8484
export interface ListBackendsResponse {
85-
backends: Stack[];
85+
backends: Backend[];
8686
}
8787

8888
/**
89-
* Creates a new Stack in a given project and location.
89+
* Creates a new Backend in a given project and location.
9090
*/
91-
export async function createStack(
91+
export async function createBackend(
9292
projectId: string,
9393
location: string,
94-
stackReqBoby: Omit<Stack, StackOutputOnlyFields>,
94+
backendReqBoby: Omit<Backend, BackendOutputOnlyFields>,
9595
backendId: string
9696
): Promise<Operation> {
97-
const res = await client.post<Omit<Stack, StackOutputOnlyFields>, Operation>(
97+
const res = await client.post<Omit<Backend, BackendOutputOnlyFields>, Operation>(
9898
`projects/${projectId}/locations/${location}/backends`,
99-
stackReqBoby,
99+
backendReqBoby,
100100
{ queryParams: { backendId } }
101101
);
102102

@@ -110,9 +110,9 @@ export async function getBackend(
110110
projectId: string,
111111
location: string,
112112
backendId: string
113-
): Promise<Stack> {
113+
): Promise<Backend> {
114114
const name = `projects/${projectId}/locations/${location}/backends/${backendId}`;
115-
const res = await client.get<Stack>(name);
115+
const res = await client.get<Backend>(name);
116116

117117
return res.body;
118118
}
@@ -150,12 +150,12 @@ export async function deleteBackend(
150150
export async function createBuild(
151151
projectId: string,
152152
location: string,
153-
stackId: string,
153+
backendId: string,
154154
buildInput: Omit<Build, BuildOutputOnlyFields>
155155
): Promise<Operation> {
156156
const buildId = buildInput.name;
157157
const res = await client.post<Omit<Build, BuildOutputOnlyFields>, Operation>(
158-
`projects/${projectId}/locations/${location}/backends/${stackId}/builds`,
158+
`projects/${projectId}/locations/${location}/backends/${backendId}/builds`,
159159
buildInput,
160160
{ queryParams: { buildId } }
161161
);

src/init/features/frameworks/index.ts

+44-32
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
ALLOWED_DEPLOY_METHODS,
1010
} from "./constants";
1111
import * as repo from "./repo";
12-
import { Stack, StackOutputOnlyFields } from "../../../gcp/frameworks";
12+
import { Backend, BackendOutputOnlyFields } from "../../../gcp/frameworks";
1313
import { Repository } from "../../../gcp/cloudbuild";
1414
import * as poller from "../../../operation-poller";
1515
import { frameworksOrigin } from "../../../api";
@@ -70,13 +70,13 @@ export async function doSetup(setup: any, projectId: string): Promise<void> {
7070
setup.frameworks
7171
);
7272

73-
const stack: Stack | undefined = await getOrCreateStack(projectId, setup);
74-
if (stack) {
75-
utils.logSuccess(`Successfully created a stack: ${stack.name}`);
73+
const backend: Backend | undefined = await getOrCreateBackend(projectId, setup);
74+
if (backend) {
75+
utils.logSuccess(`Successfully created a backend: ${backend.name}`);
7676
}
7777
}
7878

79-
function toStack(cloudBuildConnRepo: Repository): Omit<Stack, StackOutputOnlyFields> {
79+
function toBackend(cloudBuildConnRepo: Repository): Omit<Backend, BackendOutputOnlyFields> {
8080
return {
8181
codebase: {
8282
repository: `${cloudBuildConnRepo.name}`,
@@ -87,48 +87,60 @@ function toStack(cloudBuildConnRepo: Repository): Omit<Stack, StackOutputOnlyFie
8787
}
8888

8989
/**
90-
* Creates stack if it doesn't exist.
90+
* Creates backend if it doesn't exist.
9191
*/
92-
export async function getOrCreateStack(projectId: string, setup: any): Promise<Stack | undefined> {
92+
export async function getOrCreateBackend(
93+
projectId: string,
94+
setup: any
95+
): Promise<Backend | undefined> {
9396
const location: string = setup.frameworks.region;
9497
const deployMethod: string = setup.frameworks.deployMethod;
9598
try {
96-
return await getExistingStack(projectId, setup, location);
99+
return await getExistingBackend(projectId, setup, location);
97100
} catch (err: unknown) {
98101
if ((err as FirebaseError).status === 404) {
99-
logger.info("Creating new stack.");
102+
logger.info("Creating new backend.");
100103
if (deployMethod === "github") {
101104
const cloudBuildConnRepo = await repo.linkGitHubRepository(projectId, location);
102-
const stackDetails = toStack(cloudBuildConnRepo);
103-
return await createStack(projectId, location, stackDetails, setup.frameworks.serviceName);
105+
const backendDetails = toBackend(cloudBuildConnRepo);
106+
return await createBackend(
107+
projectId,
108+
location,
109+
backendDetails,
110+
setup.frameworks.serviceName
111+
);
104112
}
105113
} else {
106114
throw new FirebaseError(
107-
`Failed to get or create a stack using the given initialization details: ${err}`
115+
`Failed to get or create a backend using the given initialization details: ${err}`
108116
);
109117
}
110118
}
111119

112120
return undefined;
113121
}
114122

115-
async function getExistingStack(projectId: string, setup: any, location: string): Promise<Stack> {
116-
let stack = await gcp.getBackend(projectId, location, setup.frameworks.serviceName);
117-
while (stack) {
123+
async function getExistingBackend(
124+
projectId: string,
125+
setup: any,
126+
location: string
127+
): Promise<Backend> {
128+
let backend = await gcp.getBackend(projectId, location, setup.frameworks.serviceName);
129+
while (backend) {
118130
setup.frameworks.serviceName = undefined;
119131
await promptOnce(
120132
{
121-
name: "existingStack",
133+
name: "existingBackend",
122134
type: "confirm",
123135
default: true,
124136
message:
125-
"A stack already exists for the given serviceName, do you want to use existing stack? (yes/no)",
137+
"A backend already exists for the given serviceName, do you want to use existing backend? (yes/no)",
126138
},
127139
setup.frameworks
128140
);
129-
if (setup.frameworks.existingStack) {
130-
logger.info("Using the existing stack.");
131-
return stack;
141+
if (setup.frameworks.existingBackend) {
142+
logger.info("Using the existing backend.");
143+
return backend;
132144
}
133145
await promptOnce(
134146
{
@@ -139,28 +151,28 @@ async function getExistingStack(projectId: string, setup: any, location: string)
139151
},
140152
setup.frameworks
141153
);
142-
stack = await gcp.getBackend(projectId, location, setup.frameworks.serviceName);
143-
setup.frameworks.existingStack = undefined;
154+
backend = await gcp.getBackend(projectId, location, setup.frameworks.serviceName);
155+
setup.frameworks.existingBackend = undefined;
144156
}
145157

146-
return stack;
158+
return backend;
147159
}
148160

149161
/**
150-
* Creates Stack object from long running operations.
162+
* Creates backend object from long running operations.
151163
*/
152-
export async function createStack(
164+
export async function createBackend(
153165
projectId: string,
154166
location: string,
155-
stackReqBoby: Omit<Stack, StackOutputOnlyFields>,
156-
stackId: string
157-
): Promise<Stack> {
158-
const op = await gcp.createStack(projectId, location, stackReqBoby, stackId);
159-
const stack = await poller.pollOperation<Stack>({
167+
backendReqBoby: Omit<Backend, BackendOutputOnlyFields>,
168+
backendId: string
169+
): Promise<Backend> {
170+
const op = await gcp.createBackend(projectId, location, backendReqBoby, backendId);
171+
const backend = await poller.pollOperation<Backend>({
160172
...frameworksPollerOptions,
161-
pollerName: `create-${projectId}-${location}-${stackId}`,
173+
pollerName: `create-${projectId}-${location}-${backendId}`,
162174
operationResourceName: op.name,
163175
});
164176

165-
return stack;
177+
return backend;
166178
}

src/init/features/frameworks/repo.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function generateConnectionId(location: string): string {
4545
}
4646

4747
/**
48-
* Prompts the user to link their stack to a GitHub repository.
48+
* Prompts the user to link their backend to a GitHub repository.
4949
*/
5050
export async function linkGitHubRepository(
5151
projectId: string,

src/test/init/frameworks/index.spec.ts

+34-34
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ import { expect } from "chai";
44
import * as gcp from "../../../gcp/frameworks";
55
import * as repo from "../../../init/features/frameworks/repo";
66
import * as poller from "../../../operation-poller";
7-
import { createStack, getOrCreateStack } from "../../../init/features/frameworks/index";
7+
import { createBackend, getOrCreateBackend } from "../../../init/features/frameworks/index";
88
import { FirebaseError } from "../../../error";
99

1010
describe("operationsConverter", () => {
1111
const sandbox: sinon.SinonSandbox = sinon.createSandbox();
1212

1313
let pollOperationStub: sinon.SinonStub;
14-
let createStackStub: sinon.SinonStub;
15-
let getStackStub: sinon.SinonStub;
14+
let createBackendStub: sinon.SinonStub;
15+
let getBackendStub: sinon.SinonStub;
1616
let linkGitHubRepositoryStub: sinon.SinonStub;
1717

1818
beforeEach(() => {
1919
pollOperationStub = sandbox
2020
.stub(poller, "pollOperation")
2121
.throws("Unexpected pollOperation call");
22-
createStackStub = sandbox.stub(gcp, "createStack").throws("Unexpected createStack call");
23-
getStackStub = sandbox.stub(gcp, "getBackend").throws("Unexpected getBackend call");
22+
createBackendStub = sandbox.stub(gcp, "createBackend").throws("Unexpected createBackend call");
23+
getBackendStub = sandbox.stub(gcp, "getBackend").throws("Unexpected getBackend call");
2424
linkGitHubRepositoryStub = sandbox
2525
.stub(repo, "linkGitHubRepository")
2626
.throws("Unexpected getBackend call");
@@ -30,16 +30,16 @@ describe("operationsConverter", () => {
3030
sandbox.verifyAndRestore();
3131
});
3232

33-
describe("createStack", () => {
33+
describe("createBackend", () => {
3434
const projectId = "projectId";
3535
const location = "us-central1";
36-
const stackId = "stackId";
36+
const backendId = "backendId";
3737
const op = {
38-
name: `projects/${projectId}/locations/${location}/stacks/${stackId}`,
38+
name: `projects/${projectId}/locations/${location}/backends/${backendId}`,
3939
done: true,
4040
};
41-
const completeStack = {
42-
name: `projects/${projectId}/locations/${location}/stacks/${stackId}`,
41+
const completeBackend = {
42+
name: `projects/${projectId}/locations/${location}/backends/${backendId}`,
4343
labels: {},
4444
createTime: "0",
4545
updateTime: "1",
@@ -48,8 +48,8 @@ describe("operationsConverter", () => {
4848
const setup = {
4949
frameworks: {
5050
region: location,
51-
serviceName: stackId,
52-
existingStack: true,
51+
serviceName: backendId,
52+
existingBackend: true,
5353
deployMethod: "github",
5454
},
5555
};
@@ -59,46 +59,46 @@ describe("operationsConverter", () => {
5959
createTime: "0",
6060
updateTime: "1",
6161
};
62-
const stackInput = {
62+
const backendInput = {
6363
codebase: {
6464
repository: cloudBuildConnRepo.name,
6565
rootDirectory: "/",
6666
},
6767
labels: {},
6868
};
69-
it("should createStack", async () => {
70-
createStackStub.resolves(op);
71-
pollOperationStub.resolves(completeStack);
69+
it("should createBackend", async () => {
70+
createBackendStub.resolves(op);
71+
pollOperationStub.resolves(completeBackend);
7272

73-
await createStack(projectId, location, stackInput, stackId);
73+
await createBackend(projectId, location, backendInput, backendId);
7474

75-
expect(createStackStub).to.be.calledWith(projectId, location, stackInput);
75+
expect(createBackendStub).to.be.calledWith(projectId, location, backendInput);
7676
});
7777

78-
it("should return a stack, if user wants use the exiting stack", async () => {
79-
getStackStub.resolves(completeStack);
78+
it("should return a backend, if user wants use the exiting backend", async () => {
79+
getBackendStub.resolves(completeBackend);
8080

81-
const result = await getOrCreateStack("projectId", setup);
81+
const result = await getOrCreateBackend("projectId", setup);
8282

83-
expect(result).to.deep.equal(completeStack);
84-
expect(getStackStub.calledOnceWithExactly(projectId, location, stackId)).to.be.true;
83+
expect(result).to.deep.equal(completeBackend);
84+
expect(getBackendStub.calledOnceWithExactly(projectId, location, backendId)).to.be.true;
8585
});
8686

87-
it("should create a new stack, if stack doesn't exist", async () => {
88-
const newStackId = "newStackId";
89-
const newPath = `projects/${projectId}/locations/${location}/stacks/${newStackId}`;
90-
setup.frameworks.serviceName = newStackId;
87+
it("should create a new backend, if backend doesn't exist", async () => {
88+
const newBackendId = "newBackendId";
89+
const newPath = `projects/${projectId}/locations/${location}/backends/${newBackendId}`;
90+
setup.frameworks.serviceName = newBackendId;
9191
op.name = newPath;
92-
completeStack.name = newPath;
93-
getStackStub.throws(new FirebaseError("error", { status: 404 }));
92+
completeBackend.name = newPath;
93+
getBackendStub.throws(new FirebaseError("error", { status: 404 }));
9494
linkGitHubRepositoryStub.resolves(cloudBuildConnRepo);
95-
createStackStub.resolves(op);
96-
pollOperationStub.resolves(completeStack);
95+
createBackendStub.resolves(op);
96+
pollOperationStub.resolves(completeBackend);
9797

98-
const result = await getOrCreateStack(projectId, setup);
98+
const result = await getOrCreateBackend(projectId, setup);
9999

100-
expect(result).to.deep.equal(completeStack);
101-
expect(createStackStub).to.be.calledWith(projectId, location, stackInput);
100+
expect(result).to.deep.equal(completeBackend);
101+
expect(createBackendStub).to.be.calledWith(projectId, location, backendInput);
102102
});
103103
});
104104
});

0 commit comments

Comments
 (0)