Skip to content

Commit

Permalink
[fragment] Add a check for suffix of fragments files
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Dec 5, 2022
1 parent 91be79d commit 13ad92e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
File renamed without changes.
28 changes: 28 additions & 0 deletions script/check_newsfragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from __future__ import annotations

import argparse
import difflib
import re
import sys
from pathlib import Path
Expand All @@ -20,6 +21,21 @@
"Follow-up in",
"Fixes part of",
]
VALID_FILE_TYPE = frozenset(
[
"breaking",
"user_action",
"feature",
"new_check",
"removed_check",
"extension",
"false_positive",
"false_negative",
"bugfix",
"other",
"internal",
]
)
ISSUES_KEYWORDS = "|".join(VALID_ISSUES_KEYWORDS)
VALID_CHANGELOG_PATTERN = rf"(?P<description>(.*\n)*(.*\.\n))\n(?P<ref>({ISSUES_KEYWORDS}) (PyCQA/astroid)?#(?P<issue>\d+))"
VALID_CHANGELOG_COMPILED_PATTERN: Pattern[str] = re.compile(
Expand Down Expand Up @@ -55,6 +71,18 @@ def check_file(file: Path, verbose: bool) -> bool:
f"{file} must be named '{issue}.<fragmenttype>', after the issue it references."
)
return False
if not any(file.suffix.endswith(t) for t in VALID_FILE_TYPE):
suggestions = difflib.get_close_matches(file.suffix, VALID_FILE_TYPE)
if suggestions:
multiple_suggestions = "', '".join(f"{issue}.{s}" for s in suggestions)
suggestion = f"should probably be named '{multiple_suggestions}'"
else:
multiple_suggestions = "', '".join(
f"{issue}.{s}" for s in VALID_FILE_TYPE
)
suggestion = f"must be named one of '{multiple_suggestions}'"
echo(f"{file} {suggestion} instead.")
return False
if verbose:
echo(f"Checked '{file}': LGTM 🤖👍")
return True
Expand Down

0 comments on commit 13ad92e

Please sign in to comment.