diff --git a/scripts/lint-filenames.py b/scripts/lint-filenames.py index 79f6368..1bf7077 100755 --- a/scripts/lint-filenames.py +++ b/scripts/lint-filenames.py @@ -23,22 +23,20 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -import re from pathlib import Path +from srawn_utils import ISSUE_FILENAME_PATTERN, YEAR_FOLDER_PATTERN + status = True print("Verifying minutes filenames.") repo = Path(".") -filename_regex = re.compile("^20\d{2}-\d{2}-\d{2}-srawn-\d{2}\.md$") -folder_regex = re.compile("^SR20\d{2}$") - year_folders = [f for f in repo.iterdir() if f.is_dir()] for folder in year_folders: - result = re.match(folder_regex, folder.name) + result = YEAR_FOLDER_PATTERN.match(folder.name) if result is not None: print(f"Found valid folder name: {folder.name}") @@ -52,7 +50,7 @@ # Verify file name - file_result = re.match(filename_regex, f.name) + file_result = ISSUE_FILENAME_PATTERN.match(f.name) if file_result is None: print(f"\tFound bad file name: {f.name}") diff --git a/scripts/srawn_utils.py b/scripts/srawn_utils.py index c4da817..4adb5a4 100644 --- a/scripts/srawn_utils.py +++ b/scripts/srawn_utils.py @@ -5,6 +5,9 @@ from collections.abc import Iterator from pathlib import Path +YEAR_FOLDER_PATTERN = re.compile(r"^(SR20\d{2})$") +ISSUE_FILENAME_PATTERN = re.compile(r"^(20\d{2}-\d{2}-\d{2})-srawn-(\d{2}).md$") + class InvalidPath(ValueError): pass @@ -27,20 +30,14 @@ def date_text(self) -> str: def parse_path(path: Path) -> ParsedIssuePath: - filename_match = re.match( - r"^(20\d{2}-\d{2}-\d{2})-srawn-(\d{2})$", - path.stem, - ) + filename_match = ISSUE_FILENAME_PATTERN.match(path.name) if not filename_match: raise InvalidPath( - f"{path.stem!r} does not match format. Run the linter.", + f"{path.name!r} does not match format. Run the linter.", ) date, issue_number = filename_match.groups() - folder_match = re.match( - r"^(SR20\d{2})$", - path.parent.name, - ) + folder_match = YEAR_FOLDER_PATTERN.match(path.parent.name) if not folder_match: raise InvalidPath( f"{path.parent.name!r} does not match format. Run the linter.",