From c3b794c65b217096fa1a806452567fe0b54e17f6 Mon Sep 17 00:00:00 2001
From: Tim Jaacks <tim.jaacks@seco.com>
Date: Mon, 23 Oct 2023 11:21:29 +0200
Subject: [PATCH] Confluence: enforce fixed page width on creation

On page creation via the API, the page always seems to be created with
full width, even if "full_width=False" is set. Update the page right
after creating it in order to correctly set it to fixed width.
---
 scripts/confluence_create_or_update_page.py | 24 +++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/scripts/confluence_create_or_update_page.py b/scripts/confluence_create_or_update_page.py
index 486ae825..29c0c355 100755
--- a/scripts/confluence_create_or_update_page.py
+++ b/scripts/confluence_create_or_update_page.py
@@ -92,14 +92,34 @@ def main():
         if type(page) is dict:
             # Update existing page
             page = confluence.update_page(
-                page["id"], args.page_name, content, args.parent_id
+                page["id"], args.page_name, content, args.parent_id, full_width=False
             )
             print("Updated existing Confluence page:")
 
         else:
             # Create new page
             page = confluence.create_page(
-                args.space_id, args.page_name, content, args.parent_id
+                args.space_id,
+                args.page_name,
+                content,
+                args.parent_id,
+                representation="storage",
+                type="page",
+                editor="v2",
+                full_width=False,
+            )
+            # Update it immediately with the same contents because sometimes the
+            # "full_width=False" argument does not work, see:
+            # https://community.developer.atlassian.com/t/how-to-set-fixed-width-when-creating-new-page-with-rest-call/53591
+            page = confluence.update_page(
+                page["id"],
+                args.page_name,
+                content,
+                args.parent_id,
+                representation="storage",
+                type="page",
+                full_width=False,
+                minor_edit=True,
             )
             print("Created new Confluence page:")
 
-- 
GitLab