13
13
from pathlib import Path
14
14
from typing import TextIO
15
15
16
+ # Fail if NEWS nit found before this line number
17
+ NEWS_NIT_THRESHOLD = 200
18
+
16
19
# Exclude these whether they're dirty or clean,
17
20
# because they trigger a rebuild of dirty files.
18
21
EXCLUDE_FILES = {
@@ -245,6 +248,32 @@ def fail_if_improved(
245
248
return 0
246
249
247
250
251
+ def fail_if_new_news_nit (warnings : list [str ], threshold : int ) -> int :
252
+ """
253
+ Ensure no warnings are found in the NEWS file before a given line number.
254
+ """
255
+ news_nits = (
256
+ warning
257
+ for warning in warnings
258
+ if "/build/NEWS:" in warning
259
+ )
260
+
261
+ # Nits found before the threshold line
262
+ new_news_nits = [
263
+ nit
264
+ for nit in news_nits
265
+ if int (nit .split (":" )[1 ]) <= threshold
266
+ ]
267
+
268
+ if new_news_nits :
269
+ print ("\n Error: new NEWS nits:\n " )
270
+ for warning in new_news_nits :
271
+ print (warning )
272
+ return - 1
273
+
274
+ return 0
275
+
276
+
248
277
def main (argv : list [str ] | None = None ) -> int :
249
278
parser = argparse .ArgumentParser ()
250
279
parser .add_argument (
@@ -264,6 +293,14 @@ def main(argv: list[str] | None = None) -> int:
264
293
action = "store_true" ,
265
294
help = "Fail if new files with no nits are found" ,
266
295
)
296
+ parser .add_argument (
297
+ "--fail-if-new-news-nit" ,
298
+ metavar = "threshold" ,
299
+ type = int ,
300
+ nargs = "?" ,
301
+ const = NEWS_NIT_THRESHOLD ,
302
+ help = "Fail if new NEWS nit found before threshold line number" ,
303
+ )
267
304
268
305
args = parser .parse_args (argv )
269
306
if args .annotate_diff is not None and len (args .annotate_diff ) > 2 :
@@ -304,6 +341,9 @@ def main(argv: list[str] | None = None) -> int:
304
341
if args .fail_if_improved :
305
342
exit_code += fail_if_improved (files_with_expected_nits , files_with_nits )
306
343
344
+ if args .fail_if_new_news_nit :
345
+ exit_code += fail_if_new_news_nit (warnings , args .fail_if_new_news_nit )
346
+
307
347
return exit_code
308
348
309
349
0 commit comments