Skip to content

Commit 2a9c4b5

Browse files
authored
when deploying, update titles when linking to existing projects (#1317)
1 parent 74732be commit 2a9c4b5

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/deploy.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ export async function deploy(
180180

181181
deployTarget ??= await promptDeployTarget(effects, apiClient, config, currentUser);
182182

183-
const previousProjectId = deployConfig?.projectId;
184183
let targetDescription: string;
185184
let buildFilePaths: string[] | null = null;
186185
let doBuild = force === "build";
@@ -254,8 +253,7 @@ export async function deploy(
254253
// Check last deployed state. If it's not the same project, ask the user if
255254
// they want to continue anyways. In non-interactive mode just cancel.
256255
targetDescription = `${deployTarget.project.title} (@${deployTarget.workspace.login}/${deployTarget.project.slug})`;
257-
const previousProjectId = deployConfig.projectId;
258-
if (previousProjectId && previousProjectId !== deployTarget.project.id) {
256+
if (deployConfig.projectId && deployConfig.projectId !== deployTarget.project.id) {
259257
clack.log.warn(
260258
`The \`projectId\` in your deploy.json does not match. Continuing will overwrite ${bold(targetDescription)}.`
261259
);
@@ -274,7 +272,7 @@ export async function deploy(
274272
} else {
275273
throw new CliError("Cancelling deploy due to misconfiguration.");
276274
}
277-
} else if (previousProjectId) {
275+
} else if (deployConfig.projectId) {
278276
clack.log.info(`Deploying to ${bold(targetDescription)}.`);
279277
} else {
280278
clack.log.warn(
@@ -296,6 +294,10 @@ export async function deploy(
296294
throw new CliError("Running non-interactively, cancelling due to conflictg");
297295
}
298296
}
297+
298+
if (deployTarget.project.title !== config.title) {
299+
projectUpdates.title = config.title;
300+
}
299301
}
300302

301303
if (message === undefined) {
@@ -451,7 +453,7 @@ export async function deploy(
451453
if (!deployInfo) throw new CliError("Deploy failed to process on server");
452454

453455
// Update project title if necessary
454-
if (previousProjectId && previousProjectId === deployTarget.project.id && typeof projectUpdates?.title === "string") {
456+
if (typeof projectUpdates?.title === "string") {
455457
await apiClient.postEditProject(deployTarget.project.id, projectUpdates as PostEditProjectRequest);
456458
}
457459
clack.outro(`Deployed project now visible at ${link(deployInfo.url)}`);

test/deploy-test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,41 @@ describe("deploy", () => {
227227
effects.close();
228228
});
229229

230+
it("updates title if needed when deploy config doesn't exist but the project does", async () => {
231+
const deployId = "deploy456";
232+
const oldTitle = `${TEST_CONFIG.title!} old`;
233+
getCurrentObservableApi()
234+
.handleGetCurrentUser()
235+
.handleGetWorkspaceProjects({
236+
workspaceLogin: DEPLOY_CONFIG.workspaceLogin,
237+
projects: [{id: DEPLOY_CONFIG.projectId, slug: DEPLOY_CONFIG.projectSlug, title: oldTitle}]
238+
})
239+
.handlePostDeploy({projectId: DEPLOY_CONFIG.projectId, deployId})
240+
.expectFileUpload({deployId, path: "index.html"})
241+
.expectFileUpload({deployId, path: "_observablehq/theme-air,near-midnight.css"})
242+
.expectFileUpload({deployId, path: "_observablehq/client.js"})
243+
.expectFileUpload({deployId, path: "_observablehq/runtime.js"})
244+
.expectFileUpload({deployId, path: "_observablehq/stdlib.js"})
245+
.handlePostDeployUploaded({deployId})
246+
.handleGetDeploy({deployId})
247+
.handleUpdateProject({projectId: DEPLOY_CONFIG.projectId, title: TEST_CONFIG.title!})
248+
.start();
249+
250+
const effects = new MockDeployEffects({
251+
deployConfig: null,
252+
fixedInputStatTime: new Date("2024-03-09"),
253+
fixedOutputStatTime: new Date("2024-03-10")
254+
});
255+
effects.clack.inputs.push(
256+
DEPLOY_CONFIG.projectSlug, // which project do you want to use?
257+
true, // Do you want to continue? (and overwrite the project)
258+
"change project title" // "what changed?"
259+
);
260+
await deploy(TEST_OPTIONS, effects);
261+
262+
effects.close();
263+
});
264+
230265
it("does not prompt for a message when one is supplied on the command line", async () => {
231266
const deployConfig = DEPLOY_CONFIG;
232267
const deployId = "deploy456";

0 commit comments

Comments
 (0)