@@ -126,7 +126,7 @@ <h1 class="title">Module <code>continuous_delivery_scripts.assert_news</code></h
126
126
validate_news_file(absolute_file_path)
127
127
128
128
129
- def add_news_files (git: GitWrapper, news_dir: str) -> None :
129
+ def generate_news_file (git: GitWrapper, news_dir: str) -> pathlib.Path :
130
130
"""Adds a news file if the branch corresponds to an dependency update.
131
131
132
132
Args:
@@ -142,19 +142,21 @@ <h1 class="title">Module <code>continuous_delivery_scripts.assert_news</code></h
142
142
if not configuration.get_value(ConfigurationVariable.AUTOGENERATE_NEWS_FILE_ON_DEPENDENCY_UPDATE):
143
143
raise EnvironmentError(f"Branch {current_branch} must contain a news file.")
144
144
145
- create_news_file(
145
+ message = str(configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_MESSAGE)).format(
146
+ message=", ".join(groups)
147
+ )
148
+ logger.info(f"Generating a news file with content: {message}...")
149
+ return create_news_file(
146
150
news_dir,
147
- str(configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_MESSAGE)).format(
148
- message=", ".join(groups)
149
- ),
151
+ message,
150
152
configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_TYPE),
151
153
)
152
154
153
155
154
- def _commit_news_file(git: GitWrapper, news_dir: str ) -> None:
155
- logger.info("Committing news file...")
156
+ def _commit_news_file(git: GitWrapper, news_file: pathlib.Path ) -> None:
157
+ logger.info(f "Committing news file {str(news_file)} ...")
156
158
git.configure_for_github()
157
- git.add(news_dir )
159
+ git.add(str(news_file) )
158
160
git.commit("📰 Automatic changes ⚙ Adding news file")
159
161
git.push()
160
162
git.pull()
@@ -183,11 +185,11 @@ <h1 class="title">Module <code>continuous_delivery_scripts.assert_news</code></h
183
185
except Exception as e:
184
186
log_exception(logger, e)
185
187
try:
186
- add_news_files (git, absolute_news_dir)
187
- _commit_news_file(git, absolute_news_dir )
188
+ news_file = generate_news_file (git, absolute_news_dir)
189
+ _commit_news_file(git, news_file )
188
190
except Exception as e2:
189
191
log_exception(logger, e2)
190
- sys.exit(1)
192
+ sys.exit(1)
191
193
192
194
193
195
if __name__ == "__main__":
@@ -201,47 +203,6 @@ <h1 class="title">Module <code>continuous_delivery_scripts.assert_news</code></h
201
203
< section >
202
204
< h2 class ="section-title " id ="header-functions "> Functions</ h2 >
203
205
< dl >
204
- < dt id ="continuous_delivery_scripts.assert_news.add_news_files "> < code class ="name flex ">
205
- < span > def < span class ="ident "> add_news_files</ span > </ span > (< span > git: < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper " href ="utils/git_helpers.html#continuous_delivery_scripts.utils.git_helpers.GitWrapper "> GitWrapper</ a > , news_dir: str) ‑> NoneType</ span >
206
- </ code > </ dt >
207
- < dd >
208
- < div class ="desc "> < p > Adds a news file if the branch corresponds to an dependency update.</ p >
209
- < h2 id ="args "> Args</ h2 >
210
- < dl >
211
- < dt > < strong > < code > git</ code > </ strong > </ dt >
212
- < dd > Instance of GitWrapper.</ dd >
213
- < dt > < strong > < code > news_dir</ code > </ strong > </ dt >
214
- < dd > Relative path to news directory.</ dd >
215
- </ dl > </ div >
216
- < details class ="source ">
217
- < summary >
218
- < span > Expand source code</ span >
219
- </ summary >
220
- < pre > < code class ="python "> def add_news_files(git: GitWrapper, news_dir: str) -> None:
221
- """Adds a news file if the branch corresponds to an dependency update.
222
-
223
- Args:
224
- git: Instance of GitWrapper.
225
- news_dir: Relative path to news directory.
226
- """
227
- current_branch = str(git.get_current_branch())
228
- is_dependency_update, groups = git.is_current_branch_of_type(
229
- str(configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_BRANCH_PATTERN))
230
- )
231
- if not is_dependency_update:
232
- raise EnvironmentError(f"Branch {current_branch} must contain a news file.")
233
- if not configuration.get_value(ConfigurationVariable.AUTOGENERATE_NEWS_FILE_ON_DEPENDENCY_UPDATE):
234
- raise EnvironmentError(f"Branch {current_branch} must contain a news file.")
235
-
236
- create_news_file(
237
- news_dir,
238
- str(configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_MESSAGE)).format(
239
- message=", ".join(groups)
240
- ),
241
- configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_TYPE),
242
- )</ code > </ pre >
243
- </ details >
244
- </ dd >
245
206
< dt id ="continuous_delivery_scripts.assert_news.find_news_files "> < code class ="name flex ">
246
207
< span > def < span class ="ident "> find_news_files</ span > </ span > (< span > git: < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper " href ="utils/git_helpers.html#continuous_delivery_scripts.utils.git_helpers.GitWrapper "> GitWrapper</ a > , root_dir: str, news_dir: str) ‑> List[str]</ span >
247
208
</ code > </ dt >
@@ -283,6 +244,49 @@ <h2 id="returns">Returns</h2>
283
244
return [str(pathlib.Path(root_dir, file_path)) for file_path in added_news_files]</ code > </ pre >
284
245
</ details >
285
246
</ dd >
247
+ < dt id ="continuous_delivery_scripts.assert_news.generate_news_file "> < code class ="name flex ">
248
+ < span > def < span class ="ident "> generate_news_file</ span > </ span > (< span > git: < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper " href ="utils/git_helpers.html#continuous_delivery_scripts.utils.git_helpers.GitWrapper "> GitWrapper</ a > , news_dir: str) ‑> pathlib.Path</ span >
249
+ </ code > </ dt >
250
+ < dd >
251
+ < div class ="desc "> < p > Adds a news file if the branch corresponds to an dependency update.</ p >
252
+ < h2 id ="args "> Args</ h2 >
253
+ < dl >
254
+ < dt > < strong > < code > git</ code > </ strong > </ dt >
255
+ < dd > Instance of GitWrapper.</ dd >
256
+ < dt > < strong > < code > news_dir</ code > </ strong > </ dt >
257
+ < dd > Relative path to news directory.</ dd >
258
+ </ dl > </ div >
259
+ < details class ="source ">
260
+ < summary >
261
+ < span > Expand source code</ span >
262
+ </ summary >
263
+ < pre > < code class ="python "> def generate_news_file(git: GitWrapper, news_dir: str) -> pathlib.Path:
264
+ """Adds a news file if the branch corresponds to an dependency update.
265
+
266
+ Args:
267
+ git: Instance of GitWrapper.
268
+ news_dir: Relative path to news directory.
269
+ """
270
+ current_branch = str(git.get_current_branch())
271
+ is_dependency_update, groups = git.is_current_branch_of_type(
272
+ str(configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_BRANCH_PATTERN))
273
+ )
274
+ if not is_dependency_update:
275
+ raise EnvironmentError(f"Branch {current_branch} must contain a news file.")
276
+ if not configuration.get_value(ConfigurationVariable.AUTOGENERATE_NEWS_FILE_ON_DEPENDENCY_UPDATE):
277
+ raise EnvironmentError(f"Branch {current_branch} must contain a news file.")
278
+
279
+ message = str(configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_MESSAGE)).format(
280
+ message=", ".join(groups)
281
+ )
282
+ logger.info(f"Generating a news file with content: {message}...")
283
+ return create_news_file(
284
+ news_dir,
285
+ message,
286
+ configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_TYPE),
287
+ )</ code > </ pre >
288
+ </ details >
289
+ </ dd >
286
290
< dt id ="continuous_delivery_scripts.assert_news.main "> < code class ="name flex ">
287
291
< span > def < span class ="ident "> main</ span > </ span > (< span > ) ‑> NoneType</ span >
288
292
</ code > </ dt >
@@ -315,11 +319,11 @@ <h2 id="returns">Returns</h2>
315
319
except Exception as e:
316
320
log_exception(logger, e)
317
321
try:
318
- add_news_files (git, absolute_news_dir)
319
- _commit_news_file(git, absolute_news_dir )
322
+ news_file = generate_news_file (git, absolute_news_dir)
323
+ _commit_news_file(git, news_file )
320
324
except Exception as e2:
321
325
log_exception(logger, e2)
322
- sys.exit(1)</ code > </ pre >
326
+ sys.exit(1)</ code > </ pre >
323
327
</ details >
324
328
</ dd >
325
329
< dt id ="continuous_delivery_scripts.assert_news.validate_news_file "> < code class ="name flex ">
@@ -496,8 +500,8 @@ <h1>Index</h1>
496
500
</ li >
497
501
< li > < h3 > < a href ="#header-functions "> Functions</ a > </ h3 >
498
502
< ul class ="">
499
- < li > < code > < a title ="continuous_delivery_scripts.assert_news.add_news_files " href ="#continuous_delivery_scripts.assert_news.add_news_files "> add_news_files</ a > </ code > </ li >
500
503
< li > < code > < a title ="continuous_delivery_scripts.assert_news.find_news_files " href ="#continuous_delivery_scripts.assert_news.find_news_files "> find_news_files</ a > </ code > </ li >
504
+ < li > < code > < a title ="continuous_delivery_scripts.assert_news.generate_news_file " href ="#continuous_delivery_scripts.assert_news.generate_news_file "> generate_news_file</ a > </ code > </ li >
501
505
< li > < code > < a title ="continuous_delivery_scripts.assert_news.main " href ="#continuous_delivery_scripts.assert_news.main "> main</ a > </ code > </ li >
502
506
< li > < code > < a title ="continuous_delivery_scripts.assert_news.validate_news_file " href ="#continuous_delivery_scripts.assert_news.validate_news_file "> validate_news_file</ a > </ code > </ li >
503
507
< li > < code > < a title ="continuous_delivery_scripts.assert_news.validate_news_files " href ="#continuous_delivery_scripts.assert_news.validate_news_files "> validate_news_files</ a > </ code > </ li >
0 commit comments