From 2e8f641260e44b996272905ae48b61182d1e983b Mon Sep 17 00:00:00 2001 From: Pawel Sikora Date: Wed, 5 May 2021 06:28:07 +0200 Subject: [PATCH] fix obtaining parents ids --- mkdocs_with_confluence/plugin.py | 40 +++++++++++--------------------- setup.py | 2 +- tests/test.py | 2 +- 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/mkdocs_with_confluence/plugin.py b/mkdocs_with_confluence/plugin.py index c03ef7a..71417f8 100644 --- a/mkdocs_with_confluence/plugin.py +++ b/mkdocs_with_confluence/plugin.py @@ -144,26 +144,13 @@ class MkdocsWithConfluence(BasePlugin): print("WARN: No images found in markdown. Proceed..") new_markdown = re.sub( - r'', '"/>

', new_markdown) confluence_body = self.confluence_mistune(new_markdown) - confluence_body = re.sub( - r"RFSW_FEATURE-(\d+)", - 'JIRADC ONE(EE Jira 7.6)key,summary,type,created,updated,due,assignee,' - + "reporter,priority,status,resolutionab49870f-b66d-38ea-800d-1f3d4b744bbd' - + 'RFSW_FEATURE-\1', - confluence_body, - ) - confluence_body = re.sub( - r"RFSW_-(\d+)", "RFSW_FEATURE-\1

", confluence_body - ) f.write(confluence_body) - print(confluence_body) + if self.config["debug"]: + print(confluence_body) page_name = page.title new_name = "confluence_page_" + page_name.replace(" ", "_") + ".html" shutil.copy(f.name, new_name) @@ -205,9 +192,9 @@ class MkdocsWithConfluence(BasePlugin): # if self.config['debug']: print(f"PAGE: {page.title}, PARENT0: {parent}, PARENT1: {parent1}, MAIN PARENT: {main_parent}") parent_id = self.find_page_id(parent) - self.wait_until(parent_id, 1, 10) + self.wait_until(parent_id, 1, 20) second_parent_id = self.find_page_id(parent1) - self.wait_until(second_parent_id, 1, 10) + self.wait_until(second_parent_id, 1, 20) main_parent_id = self.find_page_id(main_parent) if not parent_id: if not second_parent_id: @@ -217,7 +204,7 @@ class MkdocsWithConfluence(BasePlugin): return markdown # if self.config['debug']: - print(f"ADD page '{parent1}' to main parent({main_parent}) ID: {main_parent_id}") + print(f"Trying to ADD page '{parent1}' to main parent({main_parent}) ID: {main_parent_id}") body = TEMPLATE_BODY.replace("TEMPLATE", parent1) self.add_page(parent1, main_parent_id, body) for i in MkdocsWithConfluence.tab_nav: @@ -227,7 +214,7 @@ class MkdocsWithConfluence(BasePlugin): time.sleep(1) # if self.config['debug']: - print(f"ADD page '{parent}' to parent1({parent1}) ID: {second_parent_id}") + print(f"Trying to ADD page '{parent}' to parent1({parent1}) ID: {second_parent_id}") body = TEMPLATE_BODY.replace("TEMPLATE", parent) self.add_page(parent, second_parent_id, body) for i in MkdocsWithConfluence.tab_nav: @@ -237,7 +224,7 @@ class MkdocsWithConfluence(BasePlugin): time.sleep(1) # if self.config['debug']: - print(f"ADD page '{page.title}' to parent0({parent}) ID: {parent_id}") + print(f"Trying to ADD page '{page.title}' to parent0({parent}) ID: {parent_id}") self.add_page(page.title, parent_id, confluence_body) for i in MkdocsWithConfluence.tab_nav: if page.title in i: @@ -350,8 +337,8 @@ class MkdocsWithConfluence(BasePlugin): def update_page(self, page_name, page_content_in_storage_format): page_id = self.find_page_id(page_name) - # if self.config['verbose']: - # print(f"INFO - * Mkdocs With Confluence: {page_name} - *UPDATE*") + if self.config["verbose"]: + print(f"INFO - * Mkdocs With Confluence: {page_name} - *UPDATE*") if self.config["debug"]: print(f" * Mkdocs With Confluence: Update PAGE ID: {page_id}, PAGE NAME: {page_name}") if page_id: @@ -362,11 +349,12 @@ class MkdocsWithConfluence(BasePlugin): print(f"URL: {url}") headers = {"Content-Type": "application/json"} auth = (self.user, self.pw) + space = self.config["space"] data = { "id": page_id, "title": page_name, "type": "page", - "space": {"key": "RFSW"}, + "space": {"key": space}, "body": {"storage": {"value": page_content_in_storage_format, "representation": "storage"}}, "version": {"number": page_version}, } @@ -415,8 +403,8 @@ class MkdocsWithConfluence(BasePlugin): response_json = r.json() if response_json: if self.config["debug"]: - print(f"PARENT NAME: {response_json['ancestors'][0]['title']}") - return response_json["ancestors"][0]["title"] + print(f"PARENT NAME: {response_json['ancestors'][-1]['title']}") + return response_json["ancestors"][-1]["title"] else: if self.config["debug"]: print("PAGE DOES NOT HAVE PARENT") diff --git a/setup.py b/setup.py index 8640cc0..32f56d5 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name="mkdocs-with-confluence", - version="0.2.0", + version="0.2.1", description="MkDocs plugin for uploading markdown documentation to Confluence via Confluence REST API", keywords="mkdocs markdown confluence documentation rest python", url="https://github.com/pawelsikora/mkdocs-with-confluence/", diff --git a/tests/test.py b/tests/test.py index 4854865..429aca1 100644 --- a/tests/test.py +++ b/tests/test.py @@ -133,5 +133,5 @@ def find_page_version(name): # update_page("Test Page") # find_page_version("Test Page") # find_parent_name_of_page("Test Parent Page") -# find_page_id("Test page", "Test parent page") +# find_page_id("Test Page") # upload_attachment()