Returns True if the commit only touched "documentation files".
(commit: Commit)
| 111 | |
| 112 | |
| 113 | def is_doc_only_commit(commit: Commit) -> bool: |
| 114 | """Returns True if the commit only touched "documentation files".""" |
| 115 | |
| 116 | def is_doc_file(path: str) -> bool: |
| 117 | """Returns true if the path is considered to be a "documentation file".""" |
| 118 | return ( |
| 119 | # Everything under docs, regardless of the file type. |
| 120 | path.startswith("docs/") |
| 121 | # Any markdown or RST file in the repo. |
| 122 | or path.endswith(".md") |
| 123 | or path.endswith(".rst") |
| 124 | ) |
| 125 | |
| 126 | # The first line is the full hash, and the rest are the files modified by |
| 127 | # the commit, relative to the root of the repo. |
| 128 | lines = run_git(["diff-tree", "--name-only", "-r", commit.hash]) |
| 129 | all_files = frozenset(lines[1:]) |
| 130 | doc_files = frozenset(filter(is_doc_file, all_files)) |
| 131 | non_doc_files = all_files - doc_files |
| 132 | is_doc_only = (all_files == doc_files) and len(all_files) > 0 |
| 133 | |
| 134 | if verbosity > 0 and not is_doc_only: |
| 135 | debug_log( |
| 136 | f"{repr(commit)} touches {len(non_doc_files)} non-doc files, " |
| 137 | + f"like '{sorted(non_doc_files)[0]}'." |
| 138 | ) |
| 139 | |
| 140 | return is_doc_only |
| 141 | |
| 142 | |
| 143 | def print_wrapped(text: str, width: int = 80) -> None: |