9
9
10
10
from collections import defaultdict
11
11
from pathlib import Path
12
+ from typing import Optional
12
13
13
14
import yaml
14
15
@@ -71,6 +72,7 @@ def is_documentation_file(ref: str) -> bool:
71
72
prefix_list = (
72
73
"docs/" ,
73
74
"plugins/doc_fragments" ,
75
+ "examples" ,
74
76
)
75
77
return ref .startswith (prefix_list )
76
78
@@ -96,10 +98,11 @@ def is_release_pr(changes: dict[str, list[str]]) -> bool:
96
98
return True
97
99
98
100
99
- def is_changelog_needed (changes : dict [str , list [str ]]) -> bool :
101
+ def is_changelog_needed (changes : dict [str , list [str ]], custom_paths : Optional [ list [ str ]] ) -> bool :
100
102
"""Determine whether a changelog fragment is necessary.
101
103
102
104
:param changes: A dictionary keyed on change status (A, M, D, etc.) of lists of changed files
105
+ :param custom_paths: additional paths to check changes in
103
106
:returns: True if a changelog fragment is not required for this PR else False
104
107
"""
105
108
# Changes to existing plugins or modules require a changelog
@@ -108,6 +111,11 @@ def is_changelog_needed(changes: dict[str, list[str]]) -> bool:
108
111
modifications = changes ["M" ] + changes ["D" ]
109
112
if any (is_module_or_plugin (x ) for x in modifications ):
110
113
return True
114
+ # check any file from the custom paths
115
+ if custom_paths :
116
+ for ref in modifications + changes ["A" ]:
117
+ if any (ref .startswith (x ) for x in custom_paths ):
118
+ return True
111
119
112
120
return False
113
121
@@ -205,10 +213,11 @@ def list_files(ref: str) -> dict[str, list[str]]:
205
213
return changes
206
214
207
215
208
- def main (ref : str ) -> None :
216
+ def main (ref : str , custom_paths : Optional [ list [ str ]] ) -> None :
209
217
"""Run the script.
210
218
211
219
:param ref: The pull request base ref
220
+ :param custom_paths: additional paths to check changes in
212
221
"""
213
222
changes = list_files (ref )
214
223
if changes :
@@ -219,7 +228,7 @@ def main(ref: str) -> None:
219
228
changelog = [x for x in changes ["A" ] if is_changelog_file (x )]
220
229
logger .info ("changelog files -> %s" , changelog )
221
230
if not changelog :
222
- if is_changelog_needed (changes ):
231
+ if is_changelog_needed (changes , custom_paths ):
223
232
logger .error (
224
233
"Missing changelog fragment. This is not required"
225
234
" only if PR adds new modules and plugins or contain"
@@ -241,9 +250,19 @@ def main(ref: str) -> None:
241
250
sys .exit (0 )
242
251
243
252
253
+ def comma_separated_list (arg : str ) -> list [str ]:
254
+ """Parse a string into a list of string.
255
+
256
+ :param arg: The string list to parse
257
+ :returns: A list of string
258
+ """
259
+ return [x for x in arg .split ("," ) if x ]
260
+
261
+
244
262
if __name__ == "__main__" :
245
263
parser = argparse .ArgumentParser (description = "Validate changelog file from new commit" )
246
264
parser .add_argument ("--ref" , required = True , help = "Pull request base ref" )
265
+ parser .add_argument ("--custom-paths" , type = comma_separated_list )
247
266
248
267
args = parser .parse_args ()
249
- main (args .ref )
268
+ main (args .ref , args . custom_paths )
0 commit comments