Skip to content

Commit 8c75f52

Browse files
committed
rm getProjectEnvironment calls
1 parent c9effe0 commit 8c75f52

File tree

4 files changed

+29
-71
lines changed

4 files changed

+29
-71
lines changed

src/deploy.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import type {
2323
DeployManifestFile,
2424
GetCurrentUserResponse,
2525
GetDeployResponse,
26-
GetProjectEnvironmentResponse,
2726
GetProjectResponse,
2827
WorkspaceResponse
2928
} from "./observableApiClient.js";
@@ -94,7 +93,6 @@ type DeployTargetInfo =
9493
create: false;
9594
workspace: {id: string; login: string};
9695
project: GetProjectResponse;
97-
environment: GetProjectEnvironmentResponse;
9896
};
9997

10098
/** Deploy a project to Observable */
@@ -241,7 +239,7 @@ class Deployer {
241239
throw new Error("Incorrect deployTarget state");
242240
}
243241
if (!this.effects.isTty) return false;
244-
if (deployTarget.environment.build_environment_id && deployTarget.environment.source) {
242+
if (deployTarget.project.build_environment_id && deployTarget.project.source) {
245243
// can do cloud build
246244
return true;
247245
} else {
@@ -259,7 +257,7 @@ class Deployer {
259257
const branch = (
260258
await promisify(exec)("git rev-parse --abbrev-ref HEAD", {cwd: this.deployOptions.config.root})
261259
).stdout;
262-
let authedRepo = (await this.apiClient.getGitHubRepository(repoName));
260+
let authedRepo = await this.apiClient.getGitHubRepository(repoName);
263261
if (!authedRepo) {
264262
// repo not auth’ed; link to auth page and poll for auth
265263
// TODO: link to internal page that bookends the flow and handles the no-oauth-token case more gracefully
@@ -277,7 +275,7 @@ class Deployer {
277275
spinner.stop("Waiting for repository to be authorized timed out.");
278276
throw new CliError("Repository authorization failed");
279277
}
280-
authedRepo = (await this.apiClient.getGitHubRepository(repoName));
278+
authedRepo = await this.apiClient.getGitHubRepository(repoName);
281279
if (authedRepo) spinner.stop("Repository authorized.");
282280
}
283281
}
@@ -397,8 +395,7 @@ class Deployer {
397395
workspaceLogin: deployConfig.workspaceLogin,
398396
projectSlug: deployConfig.projectSlug
399397
});
400-
const environment = await this.apiClient.getProjectEnvironment({id: project.id});
401-
deployTarget = {create: false, workspace: project.owner, project, environment};
398+
deployTarget = {create: false, workspace: project.owner, project};
402399
} catch (error) {
403400
if (!isHttpError(error) || error.statusCode !== 404) {
404401
throw error;
@@ -479,13 +476,7 @@ class Deployer {
479476
deployTarget = {
480477
create: false,
481478
workspace: deployTarget.workspace,
482-
project,
483-
// TODO: In the future we may have a default environment
484-
environment: {
485-
automatic_builds_enabled: null,
486-
build_environment_id: null,
487-
source: null
488-
}
479+
project
489480
};
490481
} catch (error) {
491482
if (isApiError(error) && error.details.errors.some((e) => e.code === "TOO_MANY_PROJECTS")) {
@@ -908,12 +899,7 @@ export async function promptDeployTarget(
908899
return {
909900
create: false,
910901
workspace,
911-
project: existingProjects.find((p) => p.slug === chosenProject)!,
912-
environment: {
913-
automatic_builds_enabled: null,
914-
build_environment_id: null,
915-
source: null
916-
}
902+
project: existingProjects.find((p) => p.slug === chosenProject)!
917903
};
918904
}
919905
} else {

src/observableApiClient.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ export class ObservableApiClient {
126126
return await this._fetch<GetProjectResponse>(url, {method: "GET"});
127127
}
128128

129-
async getProjectEnvironment({id}: {id: string}): Promise<GetProjectEnvironmentResponse> {
130-
const url = new URL(`/cli/project/${id}/environment`, this._apiOrigin);
131-
return await this._fetch<GetProjectEnvironmentResponse>(url, {method: "GET"});
132-
}
133-
134129
async getGitHubRepository(repoName): Promise<GetGitHubRepositoryResponse | null> {
135130
const [owner, repo] = repoName.split("/");
136131
const url = new URL(`/cli/github/repository?owner=${owner}&repo=${repo}`, this._apiOrigin);
@@ -141,9 +136,9 @@ export class ObservableApiClient {
141136
}
142137
}
143138

144-
async postProjectEnvironment(id, body): Promise<GetProjectEnvironmentResponse> {
139+
async postProjectEnvironment(id, body): Promise<PostProjectEnvironmentResponse> {
145140
const url = new URL(`/cli/project/${id}/environment`, this._apiOrigin);
146-
return await this._fetch<GetProjectEnvironmentResponse>(url, {
141+
return await this._fetch<PostProjectEnvironmentResponse>(url, {
147142
method: "POST",
148143
headers: {"Content-Type": "application/json"},
149144
body: JSON.stringify(body)
@@ -295,11 +290,19 @@ export interface GetProjectResponse {
295290
owner: {id: string; login: string};
296291
creator: {id: string; login: string};
297292
latestCreatedDeployId: string | null;
293+
automatic_builds_enabled: boolean | null;
294+
build_environment_id: string | null;
295+
source: null | {
296+
provider: string;
297+
provider_id: string;
298+
url: string;
299+
branch: string | null;
300+
};
298301
// Available fields that we don't use
299302
// servingRoot: string | null;
300303
}
301304

302-
export interface GetProjectEnvironmentResponse {
305+
export interface PostProjectEnvironmentResponse {
303306
automatic_builds_enabled: boolean | null;
304307
build_environment_id: string | null;
305308
source: null | {

test/deploy-test.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ const DEPLOY_CONFIG: DeployConfig & {projectId: string; projectSlug: string; wor
193193
workspaceLogin: "mock-user-ws",
194194
continuousDeployment: false
195195
};
196-
const DEFAULT_ENVIRONMENT = {automatic_builds_enabled: null, build_environment_id: null, source: null};
197196

198197
describe("deploy", () => {
199198
before(() => setCurrentDate(new Date("2024-01-10T16:00:00")));
@@ -205,7 +204,6 @@ describe("deploy", () => {
205204
getCurrentObservableApi()
206205
.handleGetCurrentUser()
207206
.handleGetProject(DEPLOY_CONFIG)
208-
.handleGetProjectEnvironment({projectId: DEPLOY_CONFIG.projectId, environment: DEFAULT_ENVIRONMENT})
209207
.handlePostDeploy({projectId: DEPLOY_CONFIG.projectId, deployId})
210208
.expectStandardFiles({deployId})
211209
.handlePostDeployUploaded({deployId})
@@ -296,7 +294,6 @@ describe("deploy", () => {
296294
getCurrentObservableApi()
297295
.handleGetCurrentUser()
298296
.handleGetProject({...DEPLOY_CONFIG, title: oldTitle})
299-
.handleGetProjectEnvironment({projectId: DEPLOY_CONFIG.projectId, environment: DEFAULT_ENVIRONMENT})
300297
.handlePostDeploy({projectId: DEPLOY_CONFIG.projectId, deployId})
301298
.expectStandardFiles({deployId})
302299
.handlePostDeployUploaded({deployId})
@@ -351,7 +348,6 @@ describe("deploy", () => {
351348
getCurrentObservableApi()
352349
.handleGetCurrentUser()
353350
.handleGetProject(deployConfig)
354-
.handleGetProjectEnvironment({projectId: DEPLOY_CONFIG.projectId, environment: DEFAULT_ENVIRONMENT})
355351
.handlePostDeploy({projectId: deployConfig.projectId, deployId})
356352
.expectStandardFiles({deployId})
357353
.handlePostDeployUploaded({deployId})
@@ -575,7 +571,6 @@ describe("deploy", () => {
575571
getCurrentObservableApi()
576572
.handleGetCurrentUser()
577573
.handleGetProject({...DEPLOY_CONFIG})
578-
.handleGetProjectEnvironment({projectId: DEPLOY_CONFIG.projectId, environment: DEFAULT_ENVIRONMENT})
579574
.handlePostDeploy({projectId: DEPLOY_CONFIG.projectId, deployId, status: 500})
580575
.start();
581576
const effects = new MockDeployEffects({deployConfig: DEPLOY_CONFIG});
@@ -600,7 +595,6 @@ describe("deploy", () => {
600595
getCurrentObservableApi()
601596
.handleGetCurrentUser()
602597
.handleGetProject(DEPLOY_CONFIG)
603-
.handleGetProjectEnvironment({projectId: DEPLOY_CONFIG.projectId, environment: DEFAULT_ENVIRONMENT})
604598
.handlePostDeploy({projectId: DEPLOY_CONFIG.projectId, deployId})
605599
.handlePostDeployManifest({deployId, files: [{deployId, path: "index.html", action: "upload"}]})
606600
.handlePostDeployFile({deployId, status: 500})
@@ -625,7 +619,6 @@ describe("deploy", () => {
625619
getCurrentObservableApi()
626620
.handleGetCurrentUser()
627621
.handleGetProject(DEPLOY_CONFIG)
628-
.handleGetProjectEnvironment({projectId: DEPLOY_CONFIG.projectId, environment: DEFAULT_ENVIRONMENT})
629622
.handlePostDeploy({projectId: DEPLOY_CONFIG.projectId, deployId})
630623
.expectStandardFiles({deployId})
631624
.handlePostDeployUploaded({deployId, status: 500})
@@ -734,7 +727,6 @@ describe("deploy", () => {
734727
getCurrentObservableApi()
735728
.handleGetCurrentUser()
736729
.handleGetProject(DEPLOY_CONFIG)
737-
.handleGetProjectEnvironment({projectId: DEPLOY_CONFIG.projectId, environment: DEFAULT_ENVIRONMENT})
738730
.handlePostDeploy({projectId: DEPLOY_CONFIG.projectId, deployId})
739731
.expectStandardFiles({deployId})
740732
.handlePostDeployUploaded({
@@ -769,7 +761,6 @@ describe("deploy", () => {
769761
getCurrentObservableApi()
770762
.handleGetCurrentUser()
771763
.handleGetProject({...DEPLOY_CONFIG, projectId: newProjectId})
772-
.handleGetProjectEnvironment({projectId: newProjectId, environment: DEFAULT_ENVIRONMENT})
773764
.handlePostDeploy({projectId: newProjectId, deployId})
774765
.expectStandardFiles({deployId})
775766
.handlePostDeployUploaded({deployId})
@@ -788,7 +779,6 @@ describe("deploy", () => {
788779
getCurrentObservableApi()
789780
.handleGetCurrentUser()
790781
.handleGetProject({...DEPLOY_CONFIG, projectId: newProjectId})
791-
.handleGetProjectEnvironment({projectId: newProjectId, environment: DEFAULT_ENVIRONMENT})
792782
.start();
793783
const effects = new MockDeployEffects({deployConfig: oldDeployConfig, isTty: true});
794784
effects.clack.inputs.push(false); // State doesn't match do you want to continue deploying?
@@ -811,7 +801,6 @@ describe("deploy", () => {
811801
...DEPLOY_CONFIG,
812802
projectId: newProjectId
813803
})
814-
.handleGetProjectEnvironment({projectId: newProjectId, environment: DEFAULT_ENVIRONMENT})
815804
.start();
816805
const effects = new MockDeployEffects({deployConfig: oldDeployConfig, isTty: false, debug: true});
817806
try {
@@ -833,7 +822,6 @@ describe("deploy", () => {
833822
...DEPLOY_CONFIG,
834823
projectId: newProjectId
835824
})
836-
.handleGetProjectEnvironment({projectId: newProjectId, environment: DEFAULT_ENVIRONMENT})
837825
.start();
838826
const effects = new MockDeployEffects({deployConfig, isTty: true});
839827
effects.clack.inputs.push(false);
@@ -854,7 +842,6 @@ describe("deploy", () => {
854842
.handlePostAuthRequestPoll("accepted")
855843
.handleGetCurrentUser()
856844
.handleGetProject(DEPLOY_CONFIG)
857-
.handleGetProjectEnvironment({projectId: DEPLOY_CONFIG.projectId, environment: DEFAULT_ENVIRONMENT})
858845
.handlePostDeploy({projectId: DEPLOY_CONFIG.projectId, deployId})
859846
.expectStandardFiles({deployId})
860847
.handlePostDeployUploaded({deployId})
@@ -876,7 +863,6 @@ describe("deploy", () => {
876863
getCurrentObservableApi()
877864
.handleGetCurrentUser()
878865
.handleGetProject(DEPLOY_CONFIG)
879-
.handleGetProjectEnvironment({projectId: DEPLOY_CONFIG.projectId, environment: DEFAULT_ENVIRONMENT})
880866
.handlePostDeploy({projectId: DEPLOY_CONFIG.projectId, deployId})
881867
.expectStandardFiles({deployId})
882868
.handlePostDeployUploaded({deployId})
@@ -904,7 +890,6 @@ describe("deploy", () => {
904890
getCurrentObservableApi()
905891
.handleGetCurrentUser()
906892
.handleGetProject(DEPLOY_CONFIG)
907-
.handleGetProjectEnvironment({projectId: DEPLOY_CONFIG.projectId, environment: DEFAULT_ENVIRONMENT})
908893
.start();
909894
const effects = new MockDeployEffects({
910895
deployConfig: DEPLOY_CONFIG,
@@ -923,7 +908,6 @@ describe("deploy", () => {
923908
getCurrentObservableApi()
924909
.handleGetCurrentUser()
925910
.handleGetProject(DEPLOY_CONFIG)
926-
.handleGetProjectEnvironment({projectId: DEPLOY_CONFIG.projectId, environment: DEFAULT_ENVIRONMENT})
927911
.start();
928912
const effects = new MockDeployEffects({
929913
deployConfig: DEPLOY_CONFIG,
@@ -945,7 +929,6 @@ describe("deploy", () => {
945929
getCurrentObservableApi()
946930
.handleGetCurrentUser()
947931
.handleGetProject(DEPLOY_CONFIG)
948-
.handleGetProjectEnvironment({projectId: DEPLOY_CONFIG.projectId, environment: DEFAULT_ENVIRONMENT})
949932
.start();
950933
const effects = new MockDeployEffects({
951934
deployConfig: DEPLOY_CONFIG,
@@ -967,7 +950,6 @@ describe("deploy", () => {
967950
getCurrentObservableApi()
968951
.handleGetCurrentUser()
969952
.handleGetProject(DEPLOY_CONFIG)
970-
.handleGetProjectEnvironment({projectId: DEPLOY_CONFIG.projectId, environment: DEFAULT_ENVIRONMENT})
971953
.start();
972954
const effects = new MockDeployEffects({
973955
deployConfig: DEPLOY_CONFIG,
@@ -994,7 +976,6 @@ describe("deploy", () => {
994976
getCurrentObservableApi()
995977
.handleGetCurrentUser()
996978
.handleGetProject(DEPLOY_CONFIG)
997-
.handleGetProjectEnvironment({projectId: DEPLOY_CONFIG.projectId, environment: DEFAULT_ENVIRONMENT})
998979
.handlePostDeploy({projectId: DEPLOY_CONFIG.projectId, deployId})
999980
.expectStandardFiles({deployId})
1000981
.handlePostDeployUploaded({deployId})
@@ -1026,7 +1007,6 @@ describe("deploy", () => {
10261007
getCurrentObservableApi()
10271008
.handleGetCurrentUser()
10281009
.handleGetProject(DEPLOY_CONFIG)
1029-
.handleGetProjectEnvironment({projectId: DEPLOY_CONFIG.projectId, environment: DEFAULT_ENVIRONMENT})
10301010
.handlePostDeploy({projectId: DEPLOY_CONFIG.projectId, deployId})
10311011
.expectFileUpload({deployId, path: "index.html", action: "upload"})
10321012
.expectFileUpload({deployId, path: "_observablehq/client.00000001.js", action: "skip"})

test/mocks/observableApi.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import PendingInterceptorsFormatter from "undici/lib/mock/pending-interceptors-f
44
import type {BuildManifest} from "../../src/build.js";
55
import type {
66
GetCurrentUserResponse,
7-
GetProjectEnvironmentResponse,
87
GetProjectResponse,
98
PaginatedList,
109
PostAuthRequestPollResponse,
@@ -168,7 +167,10 @@ class ObservableApiMock {
168167
title,
169168
creator: {id: "user-id", login: "user-login"},
170169
owner: {id: "workspace-id", login: "workspace-login"},
171-
latestCreatedDeployId: null
170+
latestCreatedDeployId: null,
171+
automatic_builds_enabled: null,
172+
build_environment_id: null,
173+
source: null
172174
} satisfies GetProjectResponse)
173175
: emptyErrorBody;
174176
const headers = authorizationHeader(status !== 401 && status !== 403);
@@ -206,7 +208,10 @@ class ObservableApiMock {
206208
title: "Mock Project",
207209
owner,
208210
creator,
209-
latestCreatedDeployId: null
211+
latestCreatedDeployId: null,
212+
automatic_builds_enabled: null,
213+
build_environment_id: null,
214+
source: null
210215
} satisfies GetProjectResponse)
211216
: emptyErrorBody;
212217
const headers = authorizationHeader(status !== 403);
@@ -239,7 +244,10 @@ class ObservableApiMock {
239244
owner,
240245
title: p.title ?? "Mock Title",
241246
accessLevel: p.accessLevel ?? "private",
242-
latestCreatedDeployId: null
247+
latestCreatedDeployId: null,
248+
automatic_builds_enabled: null,
249+
build_environment_id: null,
250+
source: null
243251
}))
244252
} satisfies PaginatedList<GetProjectResponse>)
245253
: emptyErrorBody;
@@ -267,25 +275,6 @@ class ObservableApiMock {
267275
return this;
268276
}
269277

270-
handleGetProjectEnvironment({
271-
projectId,
272-
environment,
273-
status = 200
274-
}: {
275-
projectId: string;
276-
environment?: GetProjectEnvironmentResponse;
277-
status?: number;
278-
}): ObservableApiMock {
279-
const response = status == 200 ? JSON.stringify(environment) : emptyErrorBody;
280-
const headers = authorizationHeader(status !== 403);
281-
this.addHandler((pool) =>
282-
pool
283-
.intercept({path: `/cli/project/${projectId}/environment`, method: "GET", headers: headersMatcher(headers)})
284-
.reply(status, response, {headers: {"content-type": "application/json"}})
285-
);
286-
return this;
287-
}
288-
289278
expectStandardFiles(options: Omit<ExpectedFileSpec, "path">) {
290279
return this.expectFileUpload({...options, path: "index.html"})
291280
.expectFileUpload({...options, path: "_observablehq/client.00000001.js"})

0 commit comments

Comments
 (0)