1
1
<!--
2
- -- Copyright (C) 2020-2021 Arm. All rights reserved.
2
+ -- Copyright (C) 2020-2021 Arm Limited or its affiliates and Contributors . All rights reserved.
3
3
-- SPDX-License-Identifier: Apache-2.0
4
4
-->
5
5
<!doctype html>
6
6
< html lang ="en ">
7
7
< head >
8
8
< meta charset ="utf-8 ">
9
9
< meta name ="viewport " content ="width=device-width, initial-scale=1, minimum-scale=1 " />
10
- < meta name ="generator " content ="pdoc 0.9.2 " />
10
+ < meta name ="generator " content ="pdoc 0.9.1 " />
11
11
< title > continuous_delivery_scripts.assert_news API documentation</ title >
12
12
< meta name ="description " content ="Checks if valid news files are created for changes in the project. " />
13
13
< link rel ="preload stylesheet " as ="style " href ="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css " integrity ="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs= " crossorigin >
@@ -46,6 +46,7 @@ <h1 class="title">Module <code>continuous_delivery_scripts.assert_news</code></h
46
46
from continuous_delivery_scripts.utils.configuration import configuration, ConfigurationVariable
47
47
from continuous_delivery_scripts.utils.git_helpers import ProjectTempClone, LocalProjectRepository, GitWrapper
48
48
from continuous_delivery_scripts.utils.logging import log_exception, set_log_level
49
+ from continuous_delivery_scripts.utils.news_file import create_news_file
49
50
50
51
logger = logging.getLogger(__name__)
51
52
@@ -125,6 +126,39 @@ <h1 class="title">Module <code>continuous_delivery_scripts.assert_news</code></h
125
126
validate_news_file(absolute_file_path)
126
127
127
128
129
+ def add_news_files(git: GitWrapper, news_dir: str) -> None:
130
+ """Adds a news file if the branch corresponds to an dependency update.
131
+
132
+ Args:
133
+ git: Instance of GitWrapper.
134
+ news_dir: Relative path to news directory.
135
+ """
136
+ current_branch = str(git.get_current_branch())
137
+ is_dependency_update, groups = git.is_current_branch_of_type(
138
+ str(configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_BRANCH_PATTERN))
139
+ )
140
+ if not is_dependency_update:
141
+ raise EnvironmentError(f"Branch {current_branch} must contain a news file.")
142
+ if not configuration.get_value(ConfigurationVariable.AUTOGENERATE_NEWS_FILE_ON_DEPENDENCY_UPDATE):
143
+ raise EnvironmentError(f"Branch {current_branch} must contain a news file.")
144
+
145
+ create_news_file(
146
+ news_dir,
147
+ str(configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_MESSAGE)).format(
148
+ message=", ".join(groups)
149
+ ),
150
+ configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_TYPE),
151
+ )
152
+
153
+
154
+ def _commit_news_file(git: GitWrapper, news_dir: str) -> None:
155
+ logger.info("Committing news file...")
156
+ git.add(news_dir)
157
+ git.commit("Adding news file")
158
+ git.push()
159
+ git.pull()
160
+
161
+
128
162
def main() -> None:
129
163
"""Asserts the new PR comprises at least one news file and it adheres to the required standard."""
130
164
parser = argparse.ArgumentParser(description="Check correctly formatted news files exist on feature branch.")
@@ -147,7 +181,12 @@ <h1 class="title">Module <code>continuous_delivery_scripts.assert_news</code></h
147
181
validate_news_files(git=git, news_dir=news_dir, root_dir=root_dir)
148
182
except Exception as e:
149
183
log_exception(logger, e)
150
- sys.exit(1)
184
+ try:
185
+ add_news_files(git, absolute_news_dir)
186
+ _commit_news_file(git, absolute_news_dir)
187
+ except Exception as e2:
188
+ log_exception(logger, e2)
189
+ sys.exit(1)
151
190
152
191
153
192
if __name__ == "__main__":
@@ -161,6 +200,47 @@ <h1 class="title">Module <code>continuous_delivery_scripts.assert_news</code></h
161
200
< section >
162
201
< h2 class ="section-title " id ="header-functions "> Functions</ h2 >
163
202
< dl >
203
+ < dt id ="continuous_delivery_scripts.assert_news.add_news_files "> < code class ="name flex ">
204
+ < 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 >
205
+ </ code > </ dt >
206
+ < dd >
207
+ < div class ="desc "> < p > Adds a news file if the branch corresponds to an dependency update.</ p >
208
+ < h2 id ="args "> Args</ h2 >
209
+ < dl >
210
+ < dt > < strong > < code > git</ code > </ strong > </ dt >
211
+ < dd > Instance of GitWrapper.</ dd >
212
+ < dt > < strong > < code > news_dir</ code > </ strong > </ dt >
213
+ < dd > Relative path to news directory.</ dd >
214
+ </ dl > </ div >
215
+ < details class ="source ">
216
+ < summary >
217
+ < span > Expand source code</ span >
218
+ </ summary >
219
+ < pre > < code class ="python "> def add_news_files(git: GitWrapper, news_dir: str) -> None:
220
+ """Adds a news file if the branch corresponds to an dependency update.
221
+
222
+ Args:
223
+ git: Instance of GitWrapper.
224
+ news_dir: Relative path to news directory.
225
+ """
226
+ current_branch = str(git.get_current_branch())
227
+ is_dependency_update, groups = git.is_current_branch_of_type(
228
+ str(configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_BRANCH_PATTERN))
229
+ )
230
+ if not is_dependency_update:
231
+ raise EnvironmentError(f"Branch {current_branch} must contain a news file.")
232
+ if not configuration.get_value(ConfigurationVariable.AUTOGENERATE_NEWS_FILE_ON_DEPENDENCY_UPDATE):
233
+ raise EnvironmentError(f"Branch {current_branch} must contain a news file.")
234
+
235
+ create_news_file(
236
+ news_dir,
237
+ str(configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_MESSAGE)).format(
238
+ message=", ".join(groups)
239
+ ),
240
+ configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_TYPE),
241
+ )</ code > </ pre >
242
+ </ details >
243
+ </ dd >
164
244
< dt id ="continuous_delivery_scripts.assert_news.find_news_files "> < code class ="name flex ">
165
245
< 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 >
166
246
</ code > </ dt >
@@ -233,7 +313,12 @@ <h2 id="returns">Returns</h2>
233
313
validate_news_files(git=git, news_dir=news_dir, root_dir=root_dir)
234
314
except Exception as e:
235
315
log_exception(logger, e)
236
- sys.exit(1)</ code > </ pre >
316
+ try:
317
+ add_news_files(git, absolute_news_dir)
318
+ _commit_news_file(git, absolute_news_dir)
319
+ except Exception as e2:
320
+ log_exception(logger, e2)
321
+ sys.exit(1)</ code > </ pre >
237
322
</ details >
238
323
</ dd >
239
324
< dt id ="continuous_delivery_scripts.assert_news.validate_news_file "> < code class ="name flex ">
@@ -410,6 +495,7 @@ <h1>Index</h1>
410
495
</ li >
411
496
< li > < h3 > < a href ="#header-functions "> Functions</ a > </ h3 >
412
497
< ul class ="">
498
+ < 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 >
413
499
< 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 >
414
500
< li > < code > < a title ="continuous_delivery_scripts.assert_news.main " href ="#continuous_delivery_scripts.assert_news.main "> main</ a > </ code > </ li >
415
501
< 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 >
@@ -432,7 +518,7 @@ <h4><code><a title="continuous_delivery_scripts.assert_news.NewsFileValidator" h
432
518
</ nav >
433
519
</ main >
434
520
< footer id ="footer ">
435
- < p > Generated by < a href ="https://pdoc3.github.io/pdoc "> < cite > pdoc</ cite > 0.9.2 </ a > .</ p >
521
+ < p > Generated by < a href ="https://pdoc3.github.io/pdoc "> < cite > pdoc</ cite > 0.9.1 </ a > .</ p >
436
522
</ footer >
437
523
</ body >
438
524
</ html >
0 commit comments