From 8da87ed00cc4e33a7b750ca5200455230392eec5 Mon Sep 17 00:00:00 2001 From: gmarraff Date: Fri, 19 Jan 2024 16:36:54 +0100 Subject: [PATCH 01/11] parse string --- mark2confluence/main.py | 21 +++++++++++++++++++++ tests/test_main.py | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/mark2confluence/main.py b/mark2confluence/main.py index be9d917..11eb88f 100755 --- a/mark2confluence/main.py +++ b/mark2confluence/main.py @@ -181,6 +181,27 @@ def check_header_template(header_template: str): logger.error(f"Setup error, HEADER_TEMPLATE: {e}") exit(1) +def _parse_parents_string(parents_string: str) -> Tuple[str, str, List[str]]: + dir_separator = "=" + spaces_separator = "->" + try: + parents_string_regex = re.compile(rf".+=.+({spaces_separator}.+)*") + if not parents_string_regex.match(parents_string) or parents_string.endswith(spaces_separator): + raise ValueError + directory, space_and_parents = parents_string.split(dir_separator) + space_and_parents_splitted = space_and_parents.split(spaces_separator) + space = space_and_parents_splitted[0] + parents = space_and_parents_splitted[1::] + + if not directory or not space: + raise ValueError + + + return directory, space, parents + except ValueError: + msg = f"default_parents must follow the format DIR=SPACE[->PARENT1->PARENT2], provided: {parents_string}" + logger.error(msg) + raise ValueError(msg) def main()->int: global cfg diff --git a/tests/test_main.py b/tests/test_main.py index 0a705ae..f064012 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -66,3 +66,24 @@ def test_inject_header(file, expected_index, raises): lines, injected_at_index = main.inject_header_before_first_line_of_content(temp_path, header) assert injected_at_index == expected_index assert lines[injected_at_index] == header +@pytest.mark.parametrize( + "string,expected_dir,expected_space,expected_parents,raises", + [ + ("tools/=foo->bar->baz", "tools/", "foo", ["bar", "baz"], False), + ("tools/=foo->bar", "tools/", "foo", ["bar"], False), + ("tools/=foo", "tools/", "foo", [], False), + ("tools/=", "tools/", "", [], True), + ("tools/", "", "", [], True), + ("tools/=foo->", "tools/", "foo", [], True), + ("=foo", "tools/", "foo", [], True), + ] +) +def test__parse_parents_string(string, expected_dir, expected_space, expected_parents, raises): + if raises: + with pytest.raises(ValueError, match=r"^default_parents.+"): + main._parse_parents_string(string) + else: + directory, space, parents = main._parse_parents_string(string) + assert directory == expected_dir + assert space == expected_space + assert parents == expected_parents From 732d496a623f803c1d184200f8bbd6d39a709d37 Mon Sep 17 00:00:00 2001 From: gmarraff Date: Fri, 19 Jan 2024 16:58:19 +0100 Subject: [PATCH 02/11] Handle multiple parents string --- mark2confluence/main.py | 28 ++++++++++++++++++++++------ tests/test_main.py | 17 +++++++++++++++-- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/mark2confluence/main.py b/mark2confluence/main.py index 11eb88f..a07cbe8 100755 --- a/mark2confluence/main.py +++ b/mark2confluence/main.py @@ -9,6 +9,7 @@ from loguru import logger from supermutes import dot from pprint import pformat +from dataclasses import dataclass ACTION_PUBLISH = "publish" ACTION_DRY_RUN = "dry-run" @@ -181,14 +182,20 @@ def check_header_template(header_template: str): logger.error(f"Setup error, HEADER_TEMPLATE: {e}") exit(1) -def _parse_parents_string(parents_string: str) -> Tuple[str, str, List[str]]: +@dataclass +class DefaultParents(): + directory: str + space: str + parents: List[str] + +def _parse_parent_string(parent_string: str) -> Tuple[str, str, List[str]]: dir_separator = "=" spaces_separator = "->" try: - parents_string_regex = re.compile(rf".+=.+({spaces_separator}.+)*") - if not parents_string_regex.match(parents_string) or parents_string.endswith(spaces_separator): + parent_string_regex = re.compile(rf".+=.+({spaces_separator}.+)*") + if not parent_string_regex.match(parent_string) or parent_string.endswith(spaces_separator): raise ValueError - directory, space_and_parents = parents_string.split(dir_separator) + directory, space_and_parents = parent_string.split(dir_separator) space_and_parents_splitted = space_and_parents.split(spaces_separator) space = space_and_parents_splitted[0] parents = space_and_parents_splitted[1::] @@ -199,10 +206,19 @@ def _parse_parents_string(parents_string: str) -> Tuple[str, str, List[str]]: return directory, space, parents except ValueError: - msg = f"default_parents must follow the format DIR=SPACE[->PARENT1->PARENT2], provided: {parents_string}" + msg = f"default_parents must follow the format DIR=SPACE[->PARENT1->PARENT2], provided: {parent_string}" logger.error(msg) raise ValueError(msg) +def get_default_parents(parents_string: str) -> List[DefaultParents]: + if not parents_string: + return [] + default_parents = list() + for parent_string in parents_string.split("\n"): + directory, space, parents = _parse_parent_string(parent_string) + default_parents.append(DefaultParents(directory, space, parents)) + return default_parents + def main()->int: global cfg load_vars() @@ -220,7 +236,7 @@ def main()->int: logger.info(f"Files to be processed: {', '.join(files)}") - + default_parents = get_default_parents(cfg.inputs.default_parents) status = {} for path in files: if path[-3:] == '.md' and has_mark_headers(path): diff --git a/tests/test_main.py b/tests/test_main.py index f064012..e67d229 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -81,9 +81,22 @@ def test_inject_header(file, expected_index, raises): def test__parse_parents_string(string, expected_dir, expected_space, expected_parents, raises): if raises: with pytest.raises(ValueError, match=r"^default_parents.+"): - main._parse_parents_string(string) + main._parse_parent_string(string) else: - directory, space, parents = main._parse_parents_string(string) + directory, space, parents = main._parse_parent_string(string) assert directory == expected_dir assert space == expected_space assert parents == expected_parents + +@pytest.mark.parametrize( + "string,expected_parents_count", + [ + ("tools/=foo", 1), + ("tools/=foo\ntools/=foo", 2), + ("", 0), + (None, 0) + ] +) +def test_get_default_parents(string, expected_parents_count): + parents = main.get_default_parents(string) + assert len(parents) == expected_parents_count From 2038e3b0dd9408b3a748b7c863d98076f4cbb6ef Mon Sep 17 00:00:00 2001 From: gmarraff Date: Fri, 19 Jan 2024 17:11:37 +0100 Subject: [PATCH 03/11] Build default header --- mark2confluence/main.py | 12 +++++++++--- tests/test_main.py | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/mark2confluence/main.py b/mark2confluence/main.py index a07cbe8..24cfa4b 100755 --- a/mark2confluence/main.py +++ b/mark2confluence/main.py @@ -183,11 +183,17 @@ def check_header_template(header_template: str): exit(1) @dataclass -class DefaultParents(): +class ParentCfg(): directory: str space: str parents: List[str] + def get_header(self) -> str: + header = f"\n" + for parent in self.parents: + header += f"\n" + return header + def _parse_parent_string(parent_string: str) -> Tuple[str, str, List[str]]: dir_separator = "=" spaces_separator = "->" @@ -210,13 +216,13 @@ def _parse_parent_string(parent_string: str) -> Tuple[str, str, List[str]]: logger.error(msg) raise ValueError(msg) -def get_default_parents(parents_string: str) -> List[DefaultParents]: +def get_default_parents(parents_string: str) -> List[ParentCfg]: if not parents_string: return [] default_parents = list() for parent_string in parents_string.split("\n"): directory, space, parents = _parse_parent_string(parent_string) - default_parents.append(DefaultParents(directory, space, parents)) + default_parents.append(ParentCfg(directory, space, parents)) return default_parents def main()->int: diff --git a/tests/test_main.py b/tests/test_main.py index e67d229..467df7e 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -100,3 +100,23 @@ def test__parse_parents_string(string, expected_dir, expected_space, expected_pa def test_get_default_parents(string, expected_parents_count): parents = main.get_default_parents(string) assert len(parents) == expected_parents_count + +@pytest.mark.parametrize( + "cfg,expected_header", + [ + ( + main.ParentCfg(directory="test",space="FOO",parents=["BAR", "BAZ"]), + "\n\n\n", + ), + ( + main.ParentCfg(directory="test",space="BAR",parents=["FOO"]), + "\n\n", + ), + ( + main.ParentCfg(directory="test",space="FOO",parents=[]), + "\n", + ), + ] +) +def test_ParentCfg_get_header(cfg: main.ParentCfg, expected_header): + assert cfg.get_header() == expected_header From eb090ab611f9678326bd56c7ec1c73d21f7151e8 Mon Sep 17 00:00:00 2001 From: gmarraff Date: Fri, 19 Jan 2024 17:43:21 +0100 Subject: [PATCH 04/11] inject default parents --- mark2confluence/main.py | 17 +++++++++++++- .../test_inject_default_parents/0-input.md | 1 + .../test_inject_default_parents/0-output.md | 3 +++ tests/test_main.py | 23 +++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/resources/markdown/test_inject_default_parents/0-input.md create mode 100644 tests/resources/markdown/test_inject_default_parents/0-output.md diff --git a/mark2confluence/main.py b/mark2confluence/main.py index 24cfa4b..530af26 100755 --- a/mark2confluence/main.py +++ b/mark2confluence/main.py @@ -225,6 +225,20 @@ def get_default_parents(parents_string: str) -> List[ParentCfg]: default_parents.append(ParentCfg(directory, space, parents)) return default_parents +def inject_default_parents(path: str, default_parents_cfg: List[ParentCfg]): + global cfg + file_dir = f"{os.path.dirname(os.path.relpath(path))}/" + for parent_cfg in default_parents_cfg: + cfg_abs_dir = f"{cfg.github.WORKSPACE}/{parent_cfg.directory}" + if os.path.isdir(cfg_abs_dir) and os.path.samefile(file_dir, cfg_abs_dir): + header = parent_cfg.get_header() + with open(path, 'r') as f: + file_content = f.read() + file_content = f"{header}{file_content}" + with open(path, "w") as f: + f.write(file_content) + + def main()->int: global cfg load_vars() @@ -247,9 +261,10 @@ def main()->int: for path in files: if path[-3:] == '.md' and has_mark_headers(path): logger.info(f"Processing file {path}") + inject_default_parents(path, default_parents) + source_link = f"{ cfg.github.SERVER_URL }/{ cfg.github.REPOSITORY }/blob/{ cfg.github.REF_NAME }/{ path.replace(cfg.github.WORKSPACE, '') }" header = tpl.render(source_link=source_link) - inject_header_before_first_line_of_content(path, header) status[path] = publish(path) diff --git a/tests/resources/markdown/test_inject_default_parents/0-input.md b/tests/resources/markdown/test_inject_default_parents/0-input.md new file mode 100644 index 0000000..b6ded31 --- /dev/null +++ b/tests/resources/markdown/test_inject_default_parents/0-input.md @@ -0,0 +1 @@ + diff --git a/tests/resources/markdown/test_inject_default_parents/0-output.md b/tests/resources/markdown/test_inject_default_parents/0-output.md new file mode 100644 index 0000000..cab0c27 --- /dev/null +++ b/tests/resources/markdown/test_inject_default_parents/0-output.md @@ -0,0 +1,3 @@ + + + diff --git a/tests/test_main.py b/tests/test_main.py index 467df7e..9bd389c 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -120,3 +120,26 @@ def test_get_default_parents(string, expected_parents_count): ) def test_ParentCfg_get_header(cfg: main.ParentCfg, expected_header): assert cfg.get_header() == expected_header + +def test_inject_default_parents(): + base_dir = f"{RESOURCE_DIR}/markdown/test_inject_default_parents" + source_file_path = f"{base_dir}/0-input.md" + expected_file_path = f"{base_dir}/0-output.md" + parsed_file_path = "tests/parsed_file.md" + cfgs = [ + main.ParentCfg(directory="tests/", space="FOO", parents=["BAR"]), + main.ParentCfg(directory="mark2confluence/", space="BOZ", parents=["BIZ"]), + ] + + shutil.copy(source_file_path, parsed_file_path) + main.inject_default_parents(parsed_file_path, cfgs) + + with open(parsed_file_path, "r") as f: + parsed_file_content = f.read() + with open(expected_file_path, "r") as f: + expected_file_content = f.read() + + try: + assert parsed_file_content == expected_file_content + finally: + os.remove(parsed_file_path) From bbc14bf47809c0fdfbd71483c70139e7f7925241 Mon Sep 17 00:00:00 2001 From: gmarraff Date: Fri, 19 Jan 2024 17:52:37 +0100 Subject: [PATCH 05/11] Add documentation --- README.md | 25 +++++++++++++++++++++++++ action.yml | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/README.md b/README.md index 1d61c98..0222bf5 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,33 @@ FILES: "" # space separated list of file to upload (relative to the repo root di # if FILES is defined; DOC_DIR, DOC_DIR_PATTERN and MODIFIED_INTERVAL are ignored HEADER_TEMPLATE: "---\n\n**WARNING**: This page is automatically generated from [this source code]({{source_link}})\n\n---\n\n\n" # This is a jinja template used as header, source_link is automatically resolved as github source url of the current file MERMAID_PROVIDER: "" # Defines the mermaid provider to use. Supported options are: cloudscript, mermaid-go +default_parents: "" # Automatically inject space and parents headers for the files under the specified directory, format: DIR=SPACE->PARENT1->PARENT2, each definition is separated by a newline ``` +### Automatically creating space and parent headers + +If you want to avoid to copy and paste the same space and parents for every MD file, you can use the `default_parents` input. +Based on the content of the file it will automatically prepend headers before pushing the file onto confluence. +Only the file with `mark` headers will be modified. + +Let's take this example: + +```yaml +default_headers: | + tests/=FOO->Tests + mark2confluence/=FOO->Code +``` + +Every `markdawn` file under the `tests` directory that already contains mark headers will be prepended the following headers: +```markdown + + + + +``` + +The directive is only valid for the specified directory, in the example above files places under `tests/integration/` will not have the headers appended. + ## Example workflow diff --git a/action.yml b/action.yml index acb79af..8679531 100644 --- a/action.yml +++ b/action.yml @@ -37,6 +37,10 @@ inputs: description: "Defines the mermaid provider to use. Supported options are: cloudscript, mermaid-go" required: false default: "" + default_parents: + description: "Automatically inject space and parents headers for the files under the specified directory, format: DIR=SPACE->PARENT1->PARENT2, each definition is separated by a newline" + required: false + default: "" runs: using: "docker" image: Dockerfile From 38c71b29f42916d652bdd3950ecc4a172a484324 Mon Sep 17 00:00:00 2001 From: gmarraff Date: Mon, 22 Jan 2024 12:00:38 +0100 Subject: [PATCH 06/11] Handle glob matching --- README.md | 10 +++++++++- mark2confluence/main.py | 15 ++++++++++++--- tests/test_main.py | 17 +++++++++++++---- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0222bf5..d4c1bdc 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,15 @@ Every `markdawn` file under the `tests` directory that already contains mark hea ``` -The directive is only valid for the specified directory, in the example above files places under `tests/integration/` will not have the headers appended. +The directive supports glob matching and prioritize the longest directory first, for example: + +```yaml +default_headers: | + tests/**=FOO->Tests + tests/resources/**=FOO->Tests->Resources +``` + +Files under `tests/resources/` will have `FOO->Tests->Resources` as headers, while files under `tests/other-dir` will have `FOO->Tests`. ## Example workflow diff --git a/mark2confluence/main.py b/mark2confluence/main.py index 530af26..bfc05e8 100755 --- a/mark2confluence/main.py +++ b/mark2confluence/main.py @@ -4,6 +4,7 @@ import re import subprocess from datetime import datetime,timedelta +from fnmatch import fnmatch from typing import List, Tuple import jinja2 from loguru import logger @@ -194,6 +195,13 @@ def get_header(self) -> str: header += f"\n" return header + def is_directory_included(self, directory: str) -> bool: + global cfg + sanitized_dir = directory.replace(f"{cfg.github.WORKSPACE}/", "") + if not sanitized_dir.endswith("/"): + sanitized_dir += "/" + return fnmatch(sanitized_dir, self.directory) + def _parse_parent_string(parent_string: str) -> Tuple[str, str, List[str]]: dir_separator = "=" spaces_separator = "->" @@ -223,20 +231,21 @@ def get_default_parents(parents_string: str) -> List[ParentCfg]: for parent_string in parents_string.split("\n"): directory, space, parents = _parse_parent_string(parent_string) default_parents.append(ParentCfg(directory, space, parents)) + default_parents.sort(key=lambda cfg: len(cfg.directory), reverse=True) return default_parents def inject_default_parents(path: str, default_parents_cfg: List[ParentCfg]): global cfg - file_dir = f"{os.path.dirname(os.path.relpath(path))}/" + file_dir = f"{os.path.dirname(os.path.abspath(path))}" for parent_cfg in default_parents_cfg: - cfg_abs_dir = f"{cfg.github.WORKSPACE}/{parent_cfg.directory}" - if os.path.isdir(cfg_abs_dir) and os.path.samefile(file_dir, cfg_abs_dir): + if parent_cfg.is_directory_included(file_dir): header = parent_cfg.get_header() with open(path, 'r') as f: file_content = f.read() file_content = f"{header}{file_content}" with open(path, "w") as f: f.write(file_content) + return def main()->int: diff --git a/tests/test_main.py b/tests/test_main.py index 9bd389c..d656e0a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,10 +1,12 @@ import os import pytest import shutil +from supermutes import dot import mark2confluence.main as main RESOURCE_DIR = f"{os.path.dirname(os.path.abspath(__file__))}/resources" +WORKSPACE = os.path.realpath(f"{os.path.dirname(os.path.abspath(__file__))}/..") def clean_github_environment_variables(): if(os.getenv("CI", False)): @@ -121,17 +123,24 @@ def test_get_default_parents(string, expected_parents_count): def test_ParentCfg_get_header(cfg: main.ParentCfg, expected_header): assert cfg.get_header() == expected_header -def test_inject_default_parents(): +def test_inject_default_parents(monkeypatch): + monkeypatch.setattr('mark2confluence.main.cfg', dot.dotify({"github": {"WORKSPACE": WORKSPACE}})) + base_dir = f"{RESOURCE_DIR}/markdown/test_inject_default_parents" source_file_path = f"{base_dir}/0-input.md" expected_file_path = f"{base_dir}/0-output.md" - parsed_file_path = "tests/parsed_file.md" + parsed_file_dir = f"{WORKSPACE}/tests/foo" + parsed_file_path = f"{parsed_file_dir}/parsed_file.md" cfgs = [ - main.ParentCfg(directory="tests/", space="FOO", parents=["BAR"]), + main.ParentCfg(directory="tests/foo/bar", space="FOO", parents=["BAZ"]), + main.ParentCfg(directory="tests/foo/*", space="FOO", parents=["BAR"]), + main.ParentCfg(directory="tests/*", space="FOO", parents=["BAZ"]), main.ParentCfg(directory="mark2confluence/", space="BOZ", parents=["BIZ"]), ] + os.makedirs(parsed_file_dir, exist_ok=True) shutil.copy(source_file_path, parsed_file_path) + main.inject_default_parents(parsed_file_path, cfgs) with open(parsed_file_path, "r") as f: @@ -142,4 +151,4 @@ def test_inject_default_parents(): try: assert parsed_file_content == expected_file_content finally: - os.remove(parsed_file_path) + shutil.rmtree(parsed_file_dir) From b1f334bc8caa993cc14115c4c8c8e0c6e2ef4376 Mon Sep 17 00:00:00 2001 From: gmarraff Date: Mon, 22 Jan 2024 12:15:17 +0100 Subject: [PATCH 07/11] Fix key --- mark2confluence/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mark2confluence/main.py b/mark2confluence/main.py index bfc05e8..9f6507c 100755 --- a/mark2confluence/main.py +++ b/mark2confluence/main.py @@ -265,7 +265,7 @@ def main()->int: logger.info(f"Files to be processed: {', '.join(files)}") - default_parents = get_default_parents(cfg.inputs.default_parents) + default_parents = get_default_parents(cfg.inputs.DEFAULT_PARENTS) status = {} for path in files: if path[-3:] == '.md' and has_mark_headers(path): From 87812d3e33d8a9208913c81acc4473d984cec7b5 Mon Sep 17 00:00:00 2001 From: gmarraff Date: Mon, 22 Jan 2024 12:21:17 +0100 Subject: [PATCH 08/11] Handle dangling newlines --- mark2confluence/main.py | 4 +++- tests/test_main.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mark2confluence/main.py b/mark2confluence/main.py index 9f6507c..f5e6769 100755 --- a/mark2confluence/main.py +++ b/mark2confluence/main.py @@ -228,7 +228,9 @@ def get_default_parents(parents_string: str) -> List[ParentCfg]: if not parents_string: return [] default_parents = list() - for parent_string in parents_string.split("\n"): + parents_string_array = parents_string.split("\n") + parents_string_array = list(filter(lambda x: x, parents_string_array)) + for parent_string in parents_string_array: directory, space, parents = _parse_parent_string(parent_string) default_parents.append(ParentCfg(directory, space, parents)) default_parents.sort(key=lambda cfg: len(cfg.directory), reverse=True) diff --git a/tests/test_main.py b/tests/test_main.py index d656e0a..11f9042 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -94,6 +94,7 @@ def test__parse_parents_string(string, expected_dir, expected_space, expected_pa "string,expected_parents_count", [ ("tools/=foo", 1), + ("tools/=foo\n", 1), ("tools/=foo\ntools/=foo", 2), ("", 0), (None, 0) From 35f2e45656409b18d063d8f54eb9fb82e7317138 Mon Sep 17 00:00:00 2001 From: gmarraff Date: Mon, 22 Jan 2024 12:28:20 +0100 Subject: [PATCH 09/11] Allow different headers in check --- mark2confluence/main.py | 2 +- .../test_has_mark_headers/with_mark_parent_header.md | 5 +++++ .../{with_mark_headers.md => with_mark_space_header.md} | 0 .../markdown/test_has_mark_headers/with_mark_title_header.md | 3 +++ tests/test_main.py | 4 +++- 5 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tests/resources/markdown/test_has_mark_headers/with_mark_parent_header.md rename tests/resources/markdown/test_has_mark_headers/{with_mark_headers.md => with_mark_space_header.md} (100%) create mode 100644 tests/resources/markdown/test_has_mark_headers/with_mark_title_header.md diff --git a/mark2confluence/main.py b/mark2confluence/main.py index f5e6769..545cf87 100755 --- a/mark2confluence/main.py +++ b/mark2confluence/main.py @@ -100,7 +100,7 @@ def publish(path: str)-> tuple: def has_mark_headers(path: str) -> bool: - space_re = re.compile("", re.MULTILINE) + space_re = re.compile("", re.IGNORECASE) with open(path, 'r+') as f: data = f.read().split("\n") for line in data: diff --git a/tests/resources/markdown/test_has_mark_headers/with_mark_parent_header.md b/tests/resources/markdown/test_has_mark_headers/with_mark_parent_header.md new file mode 100644 index 0000000..9e38125 --- /dev/null +++ b/tests/resources/markdown/test_has_mark_headers/with_mark_parent_header.md @@ -0,0 +1,5 @@ + + + + +And you don't. diff --git a/tests/resources/markdown/test_has_mark_headers/with_mark_headers.md b/tests/resources/markdown/test_has_mark_headers/with_mark_space_header.md similarity index 100% rename from tests/resources/markdown/test_has_mark_headers/with_mark_headers.md rename to tests/resources/markdown/test_has_mark_headers/with_mark_space_header.md diff --git a/tests/resources/markdown/test_has_mark_headers/with_mark_title_header.md b/tests/resources/markdown/test_has_mark_headers/with_mark_title_header.md new file mode 100644 index 0000000..bc60a3f --- /dev/null +++ b/tests/resources/markdown/test_has_mark_headers/with_mark_title_header.md @@ -0,0 +1,3 @@ + + +And you don't. diff --git a/tests/test_main.py b/tests/test_main.py index 11f9042..ddfeff4 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -34,7 +34,9 @@ def test_load_env_prefixes(): def test_has_mark_headers(): resource_directory = f"{RESOURCE_DIR}/markdown/test_has_mark_headers" - assert main.has_mark_headers(f"{resource_directory}/with_mark_headers.md") + assert main.has_mark_headers(f"{resource_directory}/with_mark_space_header.md") + assert main.has_mark_headers(f"{resource_directory}/with_mark_parent_header.md") + assert main.has_mark_headers(f"{resource_directory}/with_mark_title_header.md") assert not main.has_mark_headers(f"{resource_directory}/without_mark_headers.md") def test_check_header_template(): From 9549f27c6e35115fc946bf47a25c377292f695e4 Mon Sep 17 00:00:00 2001 From: gmarraff Date: Mon, 22 Jan 2024 16:44:20 +0100 Subject: [PATCH 10/11] Remove unneeded global cfg --- mark2confluence/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mark2confluence/main.py b/mark2confluence/main.py index 545cf87..afcbc91 100755 --- a/mark2confluence/main.py +++ b/mark2confluence/main.py @@ -237,7 +237,6 @@ def get_default_parents(parents_string: str) -> List[ParentCfg]: return default_parents def inject_default_parents(path: str, default_parents_cfg: List[ParentCfg]): - global cfg file_dir = f"{os.path.dirname(os.path.abspath(path))}" for parent_cfg in default_parents_cfg: if parent_cfg.is_directory_included(file_dir): From f8fbabb278b9f42136d1b6d62056bb8980715a93 Mon Sep 17 00:00:00 2001 From: gmarraff Date: Mon, 22 Jan 2024 18:41:28 +0100 Subject: [PATCH 11/11] Update default --- mark2confluence/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mark2confluence/main.py b/mark2confluence/main.py index afcbc91..ad67c19 100755 --- a/mark2confluence/main.py +++ b/mark2confluence/main.py @@ -36,6 +36,7 @@ "CONFLUENCE_USERNAME": "", "CONFLUENCE_BASE_URL": "", "MERMAID_PROVIDER": "", + "DEFAULT_PARENTS": "", } DEFAULT_GITHUB = {