Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mark2confluence): Skip files beginning with Space header when injecting default parents #19

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mark2confluence/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def begins_with_mark_headers(path: str, headers: List[str] = ["Space", "Parent",
return True
return False

def begins_with_mark_space_header(path: str):
return begins_with_mark_headers(path, ["Space"])

class MultilineCommentIsOpenException(Exception):
pass

Expand Down Expand Up @@ -240,7 +243,7 @@ def get_default_parents(parents_string: str) -> List[ParentCfg]:
def inject_default_parents(path: str, default_parents_cfg: List[ParentCfg]):
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):
if parent_cfg.is_directory_included(file_dir) and not begins_with_mark_space_header(path):
header = parent_cfg.get_header()
with open(path, 'r') as f:
file_content = f.read()
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<!-- Parent: BAZ -->
<!-- Title: BIM -->
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- Space: FOO -->
<!-- Parent: BAR -->
<!-- Parent: BAZ -->
<!-- Title: BIM -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- Space: BAR -->
<!-- Parent: BARED -->
<!-- Title: BORED -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- Space: BAR -->
<!-- Parent: BARED -->
<!-- Title: BORED -->
18 changes: 13 additions & 5 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,22 @@ 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(monkeypatch):
@pytest.mark.parametrize(
ids=("skip file with space mark header", "properly inject default headers"),
argnames="tested_file_name, expected_file_name",
argvalues=[
("0-input.md", "0-output.md"),
("1-input.md", "1-output.md"),
],
)
def test_inject_default_parents(monkeypatch, tested_file_name, expected_file_name):
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_dir = f"{WORKSPACE}/tests/foo"
parsed_file_path = f"{parsed_file_dir}/parsed_file.md"
source_file_path = os.path.join(base_dir, tested_file_name)
expected_file_path = os.path.join(base_dir, expected_file_name)
parsed_file_dir = os.path.join(WORKSPACE, "tests", "foo")
parsed_file_path = os.path.join(parsed_file_dir, "parsed_file.md")
cfgs = [
main.ParentCfg(directory="tests/foo/bar", space="FOO", parents=["BAZ"]),
main.ParentCfg(directory="tests/foo/*", space="FOO", parents=["BAR"]),
Expand Down
Loading