Skip to content

Commit 2c9a0ea

Browse files
committed
Remove --location from apphosting:builds:get.
1 parent 0447ce0 commit 2c9a0ea

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

src/commands/apphosting-builds-get.ts

+25-9
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,35 @@ import { Command } from "../command";
44
import { Options } from "../options";
55
import { needProjectId } from "../projectUtils";
66
import { logWarning } from "../utils";
7+
import { FirebaseError } from "../error";
78

89
export const command = new Command("apphosting:builds:get <backendId> <buildId>")
910
.description("get a build for an App Hosting backend")
10-
.option("-l, --location <location>", "specify the region of the backend")
1111
.before(apphosting.ensureApiEnabled)
1212
.action(async (backendId: string, buildId: string, options: Options) => {
13-
if (options.location !== undefined) {
14-
logWarning("--location is being removed in the next major release.");
15-
}
16-
options.location = options.location ?? "us-central";
1713
const projectId = needProjectId(options);
18-
const location = options.location as string;
19-
const build = await apphosting.getBuild(projectId, location, backendId, buildId);
20-
logger.info(JSON.stringify(build, null, 2));
21-
return build;
14+
const builds = await apphosting.listBuilds(projectId, /* location: */ "-", /* backendId */ "-");
15+
const matchingBuilds = builds.builds.filter((b) => {
16+
const parsedBuild = apphosting.parseBuildName(b.name);
17+
if (parsedBuild.backendId === backendId && parsedBuild.buildId === buildId) {
18+
return true;
19+
}
20+
});
21+
if (matchingBuilds.length > 0) {
22+
if (matchingBuilds.length > 1) {
23+
logWarning(
24+
`Detected multiple backends with same backendId (${backendId}) and buildId (${buildId}) within the same global location. ` +
25+
"Please delete and recreate any backends that share an ID with another. Use `apphosting:backends:list` to see all backends.",
26+
);
27+
}
28+
logger.info(JSON.stringify(matchingBuilds[0], null, 2));
29+
return matchingBuilds[0];
30+
}
31+
if (builds.unreachable && builds.unreachable.length !== 0) {
32+
logWarning(
33+
`Backends with the following primary regions are unreachable: ${builds.unreachable}.\n` +
34+
"If your backend is in one of these regions, please try again later.",
35+
);
36+
}
37+
throw new FirebaseError(`No build ${buildId} found for any backend ${backendId}.`);
2238
});

src/gcp/apphosting.ts

+14
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,20 @@ export async function deleteBackend(
357357
return res.body;
358358
}
359359

360+
/**
361+
* Parse a Build name
362+
*/
363+
export function parseBuildName(buildName: string): {
364+
projectName: string;
365+
location: string;
366+
backendId: string;
367+
buildId: string;
368+
} {
369+
// sample value: "projects/<project-name>/locations/us-central1/backends/<backend-id>/builds/<build-id>"
370+
const [, projectName, , location, , backendId, , buildId] = buildName.split("/");
371+
return { projectName, location, backendId, buildId };
372+
}
373+
360374
/**
361375
* Get a Build by Id
362376
*/

0 commit comments

Comments
 (0)