@@ -126,7 +126,7 @@ <h1 class="title">Module <code>continuous_delivery_scripts.assert_news</code></h
126126 validate_news_file(absolute_file_path)
127127
128128
129- def add_news_files (git: GitWrapper, news_dir: str) -> None :
129+ def generate_news_file (git: GitWrapper, news_dir: str) -> pathlib.Path :
130130 """Adds a news file if the branch corresponds to an dependency update.
131131
132132 Args:
@@ -142,19 +142,21 @@ <h1 class="title">Module <code>continuous_delivery_scripts.assert_news</code></h
142142 if not configuration.get_value(ConfigurationVariable.AUTOGENERATE_NEWS_FILE_ON_DEPENDENCY_UPDATE):
143143 raise EnvironmentError(f"Branch {current_branch} must contain a news file.")
144144
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(
146150 news_dir,
147- str(configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_MESSAGE)).format(
148- message=", ".join(groups)
149- ),
151+ message,
150152 configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_TYPE),
151153 )
152154
153155
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)} ...")
156158 git.configure_for_github()
157- git.add(news_dir )
159+ git.add(str(news_file) )
158160 git.commit("📰 Automatic changes ⚙ Adding news file")
159161 git.push()
160162 git.pull()
@@ -183,11 +185,11 @@ <h1 class="title">Module <code>continuous_delivery_scripts.assert_news</code></h
183185 except Exception as e:
184186 log_exception(logger, e)
185187 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 )
188190 except Exception as e2:
189191 log_exception(logger, e2)
190- sys.exit(1)
192+ sys.exit(1)
191193
192194
193195if __name__ == "__main__":
@@ -201,47 +203,6 @@ <h1 class="title">Module <code>continuous_delivery_scripts.assert_news</code></h
201203< section >
202204< h2 class ="section-title " id ="header-functions "> Functions</ h2 >
203205< 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 >
245206< dt id ="continuous_delivery_scripts.assert_news.find_news_files "> < code class ="name flex ">
246207< 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 >
247208</ code > </ dt >
@@ -283,6 +244,49 @@ <h2 id="returns">Returns</h2>
283244 return [str(pathlib.Path(root_dir, file_path)) for file_path in added_news_files]</ code > </ pre >
284245</ details >
285246</ 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 >
286290< dt id ="continuous_delivery_scripts.assert_news.main "> < code class ="name flex ">
287291< span > def < span class ="ident "> main</ span > </ span > (< span > ) ‑> NoneType</ span >
288292</ code > </ dt >
@@ -315,11 +319,11 @@ <h2 id="returns">Returns</h2>
315319 except Exception as e:
316320 log_exception(logger, e)
317321 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 )
320324 except Exception as e2:
321325 log_exception(logger, e2)
322- sys.exit(1)</ code > </ pre >
326+ sys.exit(1)</ code > </ pre >
323327</ details >
324328</ dd >
325329< dt id ="continuous_delivery_scripts.assert_news.validate_news_file "> < code class ="name flex ">
@@ -496,8 +500,8 @@ <h1>Index</h1>
496500</ li >
497501< li > < h3 > < a href ="#header-functions "> Functions</ a > </ h3 >
498502< 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 >
500503< 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 >
501505< li > < code > < a title ="continuous_delivery_scripts.assert_news.main " href ="#continuous_delivery_scripts.assert_news.main "> main</ a > </ code > </ li >
502506< 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 >
503507< 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