Skip to content

Commit 690713c

Browse files
[check-changelog] Add a verbose option so the output is easier to read
1 parent 30c3e95 commit 690713c

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

β€Ž.pre-commit-config.yamlβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ repos:
8484
- id: check-changelog
8585
alias: check-changelog
8686
name: check-changelog
87-
entry: python3 -m script.check_changelog
87+
types: [text]
88+
entry: python3 script/check_changelog.py
8889
pass_filenames: false
8990
language: system
90-
stages: [push]
9191
- id: fix-documentation
9292
name: Fix documentation
9393
entry: python3 -m script.fix_documentation

β€Žscript/check_changelog.pyβ€Ž

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
}
3737

3838

39-
def sorted_whatsnew() -> Iterator[Path]:
39+
def sorted_whatsnew(verbose: bool) -> Iterator[Path]:
4040
"""Return the whatsnew in the 'right' numerical order ('9' before '10')"""
4141
numeric_whatsnew = {}
4242
for file in PATH_TO_WHATSNEW.glob("**/*"):
@@ -46,7 +46,8 @@ def sorted_whatsnew() -> Iterator[Path]:
4646
if file.name in NO_CHECK_REQUIRED_FILES or any(
4747
version == x for x in UNCHECKED_VERSION
4848
):
49-
print(f"I don't care about '{file}' : πŸ€–πŸ€·")
49+
if verbose:
50+
print(f"I don't care about '{file}' : πŸ€–πŸ€·")
5051
continue
5152
num = tuple(int(x) for x in (version.split(".")))
5253
numeric_whatsnew[num] = file
@@ -63,15 +64,17 @@ def main(argv: list[str] | None = None) -> int:
6364
default=0,
6465
help="The issue we expect to find in the changelog.",
6566
)
66-
parser.parse_args(argv)
67+
parser.add_argument("--verbose", "-v", action="count", default=0)
68+
args = parser.parse_args(argv)
69+
verbose = args.verbose
6770
is_valid = True
68-
for file in sorted_whatsnew():
69-
if not check_file(file):
71+
for file in sorted_whatsnew(verbose):
72+
if not check_file(file, verbose):
7073
is_valid = False
7174
return 0 if is_valid else 1
7275

7376

74-
def check_file(file: Path) -> bool:
77+
def check_file(file: Path, verbose: bool) -> bool:
7578
"""Check that a file contain valid changelog's entries."""
7679
with open(file, encoding="utf8") as f:
7780
content = f.read()
@@ -81,22 +84,26 @@ def check_file(file: Path) -> bool:
8184
expected = len(contain_issue_number_descriptions)
8285
if result != expected:
8386
return create_detailed_fail_message(
84-
contain_issue_number_descriptions, valid_full_descriptions
87+
file, contain_issue_number_descriptions, valid_full_descriptions
8588
)
86-
print(f"Checked '{file}' : LGTM πŸ€–πŸ‘")
89+
if verbose:
90+
print(f"Checked '{file}' : LGTM πŸ€–πŸ‘")
8791
return True
8892

8993

9094
def create_detailed_fail_message(
91-
contain_issue_number_descriptions, valid_full_descriptions
95+
file_name: Path,
96+
contain_issue_number_descriptions: list,
97+
valid_full_descriptions: list,
9298
) -> bool:
9399
is_valid = True
94100
for issue_number_description in contain_issue_number_descriptions:
95101
if not any(v[0] in issue_number_description for v in valid_full_descriptions):
96102
is_valid = False
97103
issue_number = ISSUE_NUMBER_PATTERN.findall(issue_number_description)[0]
98104
print(
99-
f"{issue_number}'s description is not on one line, or does not respect the standard format."
105+
f"{file_name}: {issue_number}'s description is not on one line, or "
106+
"does not respect the standard format πŸ€–πŸ‘Ž"
100107
)
101108
return is_valid
102109

0 commit comments

Comments
Β (0)