fix pages deploy callers to pass owner param, flatten org/repo dir names

Update all pagesDeployer.deploy() and getDeployPath() call sites to
pass the owner name, matching the updated signature. Flatten org/repo
names with slashes for mononoke config directory paths.
Anton Kaminsky23d agob5baf6d98967parent 77ad681
4 files changed+22-11
api/src/routes/canopy.ts
@@ -232,7 +232,7 @@
232232 if (!runner) {
233233 return reply.code(503).send({ error: "Canopy not enabled" });
234234 }
235 const { repo } = request.params;
235 const { owner, repo } = request.params;
236236 const { ref } = (request.body as any) ?? {};
237237 const branch = ref || "main";
238238 const bridgeUrl =
@@ -259,7 +259,7 @@
259259 // Deploy pages if applicable
260260 const pagesDeployer = (app as any).pagesDeployer;
261261 if (pagesDeployer) {
262 void pagesDeployer.deploy(repo, branch).catch((err: any) => {
262 void pagesDeployer.deploy(owner, repo, branch).catch((err: any) => {
263263 app.log.error({ err, repo, branch }, "Pages deployment failed (manual trigger)");
264264 });
265265 }
266266
api/src/routes/repos.ts
@@ -475,7 +475,7 @@
475475
476476 // Undeploy old deploy path if pages disabled or domain changed
477477 const pagesDeployer = (app as any).pagesDeployer;
478 const oldDeployInfo = pagesDeployer?.getDeployPath(repoRow.name);
478 const oldDeployInfo = pagesDeployer?.getDeployPath(repoRow.owner_name, repoRow.name);
479479 if (pagesDeployer && oldDeployInfo) {
480480 if (updates.pages_enabled === false ||
481481 (updates.pages_domain !== undefined && updates.pages_domain !== repoRow.pages_domain)) {
@@ -487,7 +487,7 @@
487487
488488 // Trigger pages deploy if enabled
489489 if (pagesDeployer && (updates.pages_enabled === true || updates.pages_domain !== undefined)) {
490 void pagesDeployer.deploy(repoRow.name, repoRow.default_branch ?? "main").catch(
490 void pagesDeployer.deploy(repoRow.owner_name, repoRow.name, repoRow.default_branch ?? "main").catch(
491491 (err: any) => app.log.error({ err, repo: repoRow.name }, "Initial pages deploy failed")
492492 );
493493 }
494494
api/src/services/canopy-poller.ts
@@ -109,10 +109,14 @@
109109 // Deploy pages if applicable
110110 if (this.pagesDeployer) {
111111 const repo = this.db
112 .prepare(`SELECT default_branch FROM repos WHERE name = ? AND pages_enabled = 1`)
112 .prepare(
113 `SELECT r.default_branch, rwo.owner_name FROM repos r
114 JOIN repos_with_owner rwo ON rwo.id = r.id
115 WHERE r.name = ? AND r.pages_enabled = 1`
116 )
113117 .get(repoName) as any;
114118 if (repo && bookmark.name === (repo.default_branch ?? "main")) {
115 void this.pagesDeployer.deploy(repoName, bookmark.name).catch((err) => {
119 void this.pagesDeployer.deploy(repo.owner_name, repoName, bookmark.name).catch((err) => {
116120 this.logger.error(
117121 { err, repo: repoName, branch: bookmark.name },
118122 "Pages deployment failed"
119123
api/src/services/mononoke-provisioner.ts
@@ -51,6 +51,11 @@
5151delta_chunk_size = 1000000
5252`;
5353
54/** Flatten org/repo names to a single directory component (e.g. "letterpress-labs/site" → "letterpress-labs__site") */
55function repoDirName(repoName: string): string {
56 return repoName.replace(/\//g, "__");
57}
58
5459export class MononokeProvisioner {
5560 constructor(
5661 private configPath: string,
@@ -104,9 +109,10 @@
104109 */
105110 provisionRepo(repoName: string): number {
106111 const repoId = this.getNextRepoId();
112 const dirName = repoDirName(repoName);
107113
108 const repoDefDir = join(this.configPath, "repo_definitions", repoName);
109 const repoCfgDir = join(this.configPath, "repos", repoName);
114 const repoDefDir = join(this.configPath, "repo_definitions", dirName);
115 const repoCfgDir = join(this.configPath, "repos", dirName);
110116
111117 mkdirSync(repoDefDir, { recursive: true });
112118 mkdirSync(repoCfgDir, { recursive: true });
@@ -116,7 +122,7 @@
116122 [
117123 `repo_id = ${repoId}`,
118124 `repo_name = "${repoName}"`,
119 `repo_config = "${repoName}"`,
125 `repo_config = "${dirName}"`,
120126 `enabled = true`,
121127 `hipster_acl = "default"`,
122128 "",
@@ -134,8 +140,9 @@
134140 * Does not clean up blobstore data (would need Mononoke internals).
135141 */
136142 deprovisionRepo(repoName: string): void {
137 const repoDefDir = join(this.configPath, "repo_definitions", repoName);
138 const repoCfgDir = join(this.configPath, "repos", repoName);
143 const dirName = repoDirName(repoName);
144 const repoDefDir = join(this.configPath, "repo_definitions", dirName);
145 const repoCfgDir = join(this.configPath, "repos", dirName);
139146
140147 rmSync(repoDefDir, { recursive: true, force: true });
141148 rmSync(repoCfgDir, { recursive: true, force: true });
142149