feat: add --skip-subtrees-wo-markdown option to prune non-documentation subtrees#144
Open
geopanther wants to merge 4 commits into
Open
feat: add --skip-subtrees-wo-markdown option to prune non-documentation subtrees#144geopanther wants to merge 4 commits into
geopanther wants to merge 4 commits into
Conversation
…traversal Add _subtree_has_markdown() helper that walks a directory tree checking for .md files while respecting gitignore rules. Add skip_subtrees_wo_markdown parameter to get_pages_from_directory() that prunes directories in-place during os.walk to skip subtrees containing no markdown files.
Add the --skip-subtrees-wo-markdown flag to the directory arguments group and wire it through collect_pages_to_upload() to get_pages_from_directory().
Add 5 tests covering: basic subtree pruning, deeply nested markdown, root-level markdown with pruned subtrees, all-empty directory case, and flag-disabled behavior comparison.
Add a new section under 'Directory arguments' with a description and collapsible example showing how subtrees without markdown are pruned.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
--skip-subtrees-wo-markdownCLI option that, when uploading a directory, skips any subtree that doesn't contain markdown files. This avoids creating empty Confluence pages for non-documentation directories likeimages/,data/, orconfig/.Motivation
When using md2cf to upload a project folder, directories containing only non-markdown assets (images, configs, data files) are traversed and produce empty folder pages in Confluence. There's currently no way to prune these automatically —
--skip-emptyand--collapse-emptyonly handle folders without direct children, not entire subtrees. This option provides a clean way to focus uploads on documentation content only.Changes
Core logic (
md2cf/document.py)_subtree_has_markdown(path, git_repo)helper that recursively checks whether a directory tree contains any.mdfiles, respecting.gitignorerulesskip_subtrees_wo_markdownparameter onget_pages_from_directory()that prunesdirectories[:]in-place duringos.walk, preventing descent into subtrees without markdownCLI wiring (
md2cf/__main__.py)--skip-subtrees-wo-markdownflag in the directory arguments groupcollect_pages_to_upload()→get_pages_from_directory()Tests (
test_package/unit/test_document.py)Five new test cases using
pyfakefs:test_..._skip_subtrees_wo_markdown.mdfiles are removedtest_..._nestedtest_..._root_has_md.mdfiles kept; child subtrees without markdown prunedtest_..._all_emptytest_..._disabledDocumentation (
README.md)Design decisions
os.walklevel by modifyingdirectories[:]in-place, which preventsos.walkfrom descending into pruned subtrees at all — no wasted I/O