Skip to content

Commit 98b0966

Browse files
author
Al Manning
committed
site move tests
1 parent d531dc6 commit 98b0966

File tree

4 files changed

+328
-17
lines changed

4 files changed

+328
-17
lines changed

src/publish/confluence/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export class ConfluenceClient {
110110
}
111111

112112
public deleteContent(content: ContentDelete): Promise<Content> {
113+
trace("deleteContent", content);
113114
return this.delete<Content>(`content/${content.id}`);
114115
}
115116

src/publish/confluence/confluence-helper.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,17 @@ export const buildSpaceChanges = (
313313
? pathList.slice(0, pathList.length - 1).join("/")
314314
: parent?.parent;
315315

316-
const checkCreateParents = () => {
316+
const checkCreateParents = (): SitePage | null => {
317+
console.log("checkCreateParents");
318+
console.log("pathList", pathList);
317319
if (pathList.length < 2) {
318-
return;
320+
return null;
319321
}
320322

323+
let existingSiteParent = null;
324+
321325
const parentsList = pathList.slice(0, pathList.length - 1);
326+
console.log("parentsList", parentsList);
322327

323328
parentsList.forEach((parentFileName, index) => {
324329
const ancestorFilePath = parentsList.slice(0, index).join("/");
@@ -339,7 +344,19 @@ export const buildSpaceChanges = (
339344
}
340345
);
341346

342-
if (!existingParentCreateChange) {
347+
existingSiteParent = existingSite.find((page: SitePage) => {
348+
if (page?.metadata?.fileName) {
349+
return page.metadata.fileName === fileName;
350+
}
351+
return false;
352+
});
353+
354+
// TODO on create, replace nested parent ID
355+
// ancestors: [ { id: "authoring" } ]
356+
console.log("existingSite", existingSite);
357+
console.log("existingSiteParent", existingSiteParent);
358+
359+
if (!existingParentCreateChange && !existingSiteParent) {
343360
spaceChangeList = [
344361
...spaceChangeList,
345362
buildContentCreate(
@@ -358,9 +375,11 @@ export const buildSpaceChanges = (
358375
];
359376
}
360377
});
361-
};
362378

363-
checkCreateParents();
379+
return existingSiteParent;
380+
};
381+
const existingParent: SitePage | null = checkCreateParents();
382+
console.log("existingSiteParent", existingParent);
364383

365384
if (existingPage) {
366385
let useOriginalTitle = false;
@@ -376,7 +395,7 @@ export const buildSpaceChanges = (
376395
useOriginalTitle ? fileMetadata.originalTitle : fileMetadata.title,
377396
fileMetadata.contentBody,
378397
fileMetadata.fileName,
379-
pageParent
398+
existingParent ? existingParent.id : pageParent
380399
),
381400
];
382401
} else {
@@ -401,6 +420,8 @@ export const buildSpaceChanges = (
401420
existingSite
402421
);
403422

423+
console.log("pagesToDelete", pagesToDelete);
424+
404425
// TODO prompt as a sanity check and limiter to prevent any major run-away deletes
405426
const deleteChanges: ContentDelete[] = pagesToDelete.map(
406427
(toDelete: SitePage) => {

src/publish/confluence/confluence.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import {
8181
import { DELETE_DISABLED } from "./constants.ts";
8282
import { logError, trace } from "./confluence-logger.ts";
8383
import { md5Hash } from "../../core/hash.ts";
84+
import { sleep } from "../../core/async.ts";
8485

8586
export const CONFLUENCE_ID = "confluence";
8687

@@ -246,10 +247,14 @@ async function publish(
246247
trace("publish", { parent, server, space });
247248

248249
const uniquifyTitle = async (title: string) => {
250+
console.log("uniquifyTitle", title);
249251
const titleAlreadyExistsInSpace: boolean = await client.isTitleInSpace(
250252
title,
251253
space
252254
);
255+
256+
console.log("titleAlreadyExistsInSpace", titleAlreadyExistsInSpace);
257+
253258
const uuid = globalThis.crypto.randomUUID();
254259
const shortUUID = uuid.split("-")[0] ?? uuid;
255260
const createTitle = titleAlreadyExistsInSpace
@@ -262,7 +267,6 @@ async function publish(
262267
const descendants: any[] =
263268
(await client.getDescendants(parentId))?.results ?? [];
264269

265-
console.log("descendants", descendants);
266270
const contentProperties: ContentProperty[][] = await Promise.all(
267271
descendants.map((page: ContentSummary) =>
268272
client.getContentProperty(page.id ?? "")
@@ -464,8 +468,13 @@ async function publish(
464468
createParent: ConfluenceParent = parent,
465469
fileName: string = ""
466470
): Promise<Content> => {
471+
//TODO check why files are always being uniquified
472+
console.log("create Content");
473+
console.log("titleToCreate");
467474
const createTitle = await uniquifyTitle(titleToCreate);
468475

476+
console.log("createTitle", createTitle);
477+
469478
const attachmentsToUpload: string[] = findAttachments(
470479
body.storage.value,
471480
publishFiles.files,
@@ -554,11 +563,12 @@ async function publish(
554563

555564
trace("publishSite", {
556565
parentId,
557-
existingSite,
558566
publishFiles,
559567
metadataByInput,
560568
});
561569

570+
trace("existingSite", existingSite);
571+
562572
const filteredFiles: string[] = filterFilesForUpdate(publishFiles.files);
563573

564574
trace("filteredFiles", filteredFiles);
@@ -573,7 +583,7 @@ async function publish(
573583
};
574584

575585
const originalTitle = getTitle(fileName, metadataByInput);
576-
const title = await uniquifyTitle(originalTitle);
586+
const title = originalTitle;
577587

578588
const matchingPages = await client.fetchMatchingTitlePages(
579589
originalTitle,
@@ -620,9 +630,11 @@ async function publish(
620630

621631
const doChange = async (change: ConfluenceSpaceChange) => {
622632
if (isContentCreate(change)) {
633+
console.log("DO CREATE");
623634
let ancestorId =
624635
(change?.ancestors && change?.ancestors[0]?.id) ?? null;
625-
636+
console.log("ancestorId", ancestorId);
637+
console.log("pathsToId", pathsToId);
626638
if (ancestorId && pathsToId[ancestorId]) {
627639
ancestorId = pathsToId[ancestorId];
628640
}
@@ -652,6 +664,7 @@ async function publish(
652664

653665
return result;
654666
} else if (isContentUpdate(change)) {
667+
console.log("DO UPDATE");
655668
const update = change as ContentUpdate;
656669
return await updateContent(
657670
publishFiles,
@@ -660,11 +673,13 @@ async function publish(
660673
update.title ?? ""
661674
);
662675
} else if (isContentDelete(change)) {
676+
console.log("DO DELETE", change);
663677
if (DELETE_DISABLED) {
664678
console.warn("DELETE DISABELD");
665679
return null;
666680
}
667681
const result = await client.deleteContent(change);
682+
await sleep(2000); // Consider polling on delete to support uniqify rather than sleep
668683
return result;
669684
} else {
670685
console.error("Space Change not defined");

0 commit comments

Comments
 (0)