Skip to content

Commit 5b23e50

Browse files
author
Allen Manning
authored
Merge pull request #4067 from quarto-dev/bug/delete-page-update
Confluence: Bug/delete page update of manually orphaned folder
2 parents a985b34 + cfb65e7 commit 5b23e50

File tree

2 files changed

+69
-5
lines changed

2 files changed

+69
-5
lines changed

src/publish/confluence/confluence-helper.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
ContentAncestor,
1919
ContentBody,
2020
ContentBodyRepresentation,
21+
ContentChange,
2122
ContentChangeType,
2223
ContentCreate,
2324
ContentDelete,
@@ -338,7 +339,6 @@ export const buildSpaceChanges = (
338339

339340
let existingSiteParent = null;
340341

341-
//TODO update with deno paths after tests are in place
342342
const parentsList = pathList.slice(0, pathList.length - 1);
343343

344344
parentsList.forEach((parentFileName, index) => {
@@ -438,18 +438,39 @@ export const buildSpaceChanges = (
438438
existingSite
439439
);
440440

441-
// TODO prompt as a sanity check and limiter to prevent any major run-away deletes
442441
const deleteChanges: ContentDelete[] = pagesToDelete.map(
443442
(toDelete: SitePage) => {
444443
return { contentChangeType: ContentChangeType.delete, id: toDelete.id };
445444
}
446445
);
447446

448-
const spaceChanges: ConfluenceSpaceChange[] = fileMetadataList.reduce(
447+
let spaceChanges: ConfluenceSpaceChange[] = fileMetadataList.reduce(
449448
spaceChangesCallback,
450449
deleteChanges
451450
);
452451

452+
const activeAncestorIds = spaceChanges.reduce(
453+
(accumulator: any, change: any) => {
454+
if (change?.ancestors?.length) {
455+
const idList = change.ancestors.map(
456+
(ancestor: ContentAncestor) => ancestor?.id ?? ""
457+
);
458+
459+
return [...accumulator, ...idList];
460+
}
461+
462+
return accumulator;
463+
},
464+
[]
465+
);
466+
467+
spaceChanges = spaceChanges.filter((change: ConfluenceSpaceChange) => {
468+
if (isContentDelete(change) && activeAncestorIds.includes(change.id)) {
469+
return false;
470+
}
471+
return true;
472+
});
473+
453474
return spaceChanges;
454475
};
455476

tests/unit/confluence.test.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,49 @@ const runSpaceCreatesWithNesting = () => {
14041404
assertEquals(expected, actual);
14051405
});
14061406

1407+
test(suiteLabel("one_nested_file_add_back_empty_parent"), async () => {
1408+
const fileMetadataList: SiteFileMetadata[] = [fakeNestedFile];
1409+
const existingSite: SitePage[] = [
1410+
{
1411+
id: "fake-parent-id",
1412+
title: "Fake-parent",
1413+
metadata: { fileName: "fake-parent" },
1414+
},
1415+
];
1416+
const expected: ConfluenceSpaceChange[] = [
1417+
{
1418+
contentChangeType: ContentChangeType.create,
1419+
ancestors: [
1420+
{
1421+
id: "fake-parent-id",
1422+
},
1423+
],
1424+
body: {
1425+
storage: {
1426+
representation: "storage",
1427+
value: "fake-value",
1428+
},
1429+
},
1430+
fileName: "fake-parent/fake-file-name",
1431+
space: {
1432+
key: "fake-space-key",
1433+
id: "fake-space-id",
1434+
homepage: buildFakeContent(),
1435+
},
1436+
status: "current",
1437+
title: "fake-title",
1438+
type: "page",
1439+
},
1440+
];
1441+
const actual: ConfluenceSpaceChange[] = buildSpaceChanges(
1442+
fileMetadataList,
1443+
FAKE_PARENT,
1444+
fakeSpace,
1445+
existingSite
1446+
);
1447+
assertEquals(expected, actual);
1448+
});
1449+
14071450
test(suiteLabel("one_multi_nested_file"), async () => {
14081451
const fileMetadataList: SiteFileMetadata[] = [fakeMultiNestedFile];
14091452
const expected: ConfluenceSpaceChange[] = [
@@ -2390,7 +2433,7 @@ const runSpaceUpdatesWithNesting = () => {
23902433
assertEquals(expected, actual);
23912434
});
23922435

2393-
otest(suiteLabel("one_multi-nested_file_update_win"), async () => {
2436+
test(suiteLabel("one_multi-nested_file_update_win"), async () => {
23942437
const fileMetadataList: SiteFileMetadata[] = [fakeMultiNestedFileWin];
23952438

23962439
const existingSite = [
@@ -3758,5 +3801,5 @@ if (RUN_ALL_TESTS) {
37583801
runUpdateImagePathsForContentBody();
37593802
runCapFirstLetter();
37603803
} else {
3761-
runSpaceUpdatesWithNesting();
3804+
runSpaceCreatesWithNesting();
37623805
}

0 commit comments

Comments
 (0)