Skip to content

Commit

Permalink
[check-changelog] Add a verbose option so the output is easier to read
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed May 31, 2022
1 parent 30c3e95 commit 690713c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ repos:
- id: check-changelog
alias: check-changelog
name: check-changelog
entry: python3 -m script.check_changelog
types: [text]
entry: python3 script/check_changelog.py
pass_filenames: false
language: system
stages: [push]
- id: fix-documentation
name: Fix documentation
entry: python3 -m script.fix_documentation
Expand Down
27 changes: 17 additions & 10 deletions script/check_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}


def sorted_whatsnew() -> Iterator[Path]:
def sorted_whatsnew(verbose: bool) -> Iterator[Path]:
"""Return the whatsnew in the 'right' numerical order ('9' before '10')"""
numeric_whatsnew = {}
for file in PATH_TO_WHATSNEW.glob("**/*"):
Expand All @@ -46,7 +46,8 @@ def sorted_whatsnew() -> Iterator[Path]:
if file.name in NO_CHECK_REQUIRED_FILES or any(
version == x for x in UNCHECKED_VERSION
):
print(f"I don't care about '{file}' : πŸ€–πŸ€·")
if verbose:
print(f"I don't care about '{file}' : πŸ€–πŸ€·")
continue
num = tuple(int(x) for x in (version.split(".")))
numeric_whatsnew[num] = file
Expand All @@ -63,15 +64,17 @@ def main(argv: list[str] | None = None) -> int:
default=0,
help="The issue we expect to find in the changelog.",
)
parser.parse_args(argv)
parser.add_argument("--verbose", "-v", action="count", default=0)
args = parser.parse_args(argv)
verbose = args.verbose
is_valid = True
for file in sorted_whatsnew():
if not check_file(file):
for file in sorted_whatsnew(verbose):
if not check_file(file, verbose):
is_valid = False
return 0 if is_valid else 1


def check_file(file: Path) -> bool:
def check_file(file: Path, verbose: bool) -> bool:
"""Check that a file contain valid changelog's entries."""
with open(file, encoding="utf8") as f:
content = f.read()
Expand All @@ -81,22 +84,26 @@ def check_file(file: Path) -> bool:
expected = len(contain_issue_number_descriptions)
if result != expected:
return create_detailed_fail_message(
contain_issue_number_descriptions, valid_full_descriptions
file, contain_issue_number_descriptions, valid_full_descriptions
)
print(f"Checked '{file}' : LGTM πŸ€–πŸ‘")
if verbose:
print(f"Checked '{file}' : LGTM πŸ€–πŸ‘")
return True


def create_detailed_fail_message(
contain_issue_number_descriptions, valid_full_descriptions
file_name: Path,
contain_issue_number_descriptions: list,
valid_full_descriptions: list,
) -> bool:
is_valid = True
for issue_number_description in contain_issue_number_descriptions:
if not any(v[0] in issue_number_description for v in valid_full_descriptions):
is_valid = False
issue_number = ISSUE_NUMBER_PATTERN.findall(issue_number_description)[0]
print(
f"{issue_number}'s description is not on one line, or does not respect the standard format."
f"{file_name}: {issue_number}'s description is not on one line, or "
"does not respect the standard format πŸ€–πŸ‘Ž"
)
return is_valid

Expand Down

0 comments on commit 690713c

Please sign in to comment.