@@ -54,13 +54,17 @@ def li(text: str) -> str:
54
54
55
55
@staticmethod
56
56
def clean_pr_title (title : str ) -> str :
57
+ task_re = r"[a-zA-Z]+-\d+" # task tracker issue key
57
58
prefix_patterns_to_remove = [
58
- r"^\[?(DLPROJECTS|CHARTS|BI|YCDOCS|DOCSUP)-\d+\]?[ .:]*" ,
59
+ rf"^\[?({ task_re } )\]?[ .:]*" , # e.g. "TASK-123: minor improvements"
60
+ rf"^[a-z]+(\([a-z, ]+\))?: { task_re } " , # e.g. "fix(datasets, connectors): TASK-123 moderate improvements"
61
+ rf"^[a-z]+(\([a-z, ]+\))?: " , # e.g. "fix(datasets, connectors): major improvements"
59
62
]
60
63
61
64
for pattern in prefix_patterns_to_remove :
62
65
title = re .sub (pattern , "" , title )
63
66
title = title .strip (" ." )
67
+ title = title [0 ].upper () + title [1 :]
64
68
65
69
return title
66
70
@@ -100,7 +104,7 @@ def release_bump_version(version: str, release_type: str) -> str:
100
104
def normalize_tag (tag : str ) -> str :
101
105
""" Ensures there is a "v" at the beginning """
102
106
103
- return "v" + tag .lstrip ("v" )
107
+ return "v" + tag .lstrip ("v" ) if tag else ""
104
108
105
109
106
110
def normalize_version (version : str ) -> str :
@@ -123,25 +127,29 @@ def write_output(content: str) -> None:
123
127
124
128
def populate_helper_maps (
125
129
changelog_config : dict [str , Any ],
126
- current_image_versions : dict [str , str ],
130
+ current_repo_versions : dict [str , str ],
127
131
new_repo_versions : dict [str , str ],
128
132
) -> None :
129
133
for repo in changelog_config ["repositories" ]:
130
- for img in repo [ "images" ] :
134
+ for img in repo . get ( "images" , []) :
131
135
REPO_CFG_BY_IMG [img ["name" ]] = repo
132
- IMG_VERSIONS_BY_NAME [img ["name" ]]["from" ] = current_image_versions [img ["version_descriptor" ]]
136
+ IMG_VERSIONS_BY_NAME [img ["name" ]]["from" ] = current_repo_versions [img ["version_descriptor" ]]
133
137
134
138
for repo in changelog_config ["repositories" ]:
135
- for img in repo ["images" ]:
139
+ repo_images = repo .get ("images" , [])
140
+ for img in repo_images :
136
141
existing_tag = REPO_VERSIONS .get (repo ["name" ], {}).get ("from" )
137
- new_tag = current_image_versions [img ["version_descriptor" ]]
142
+ new_tag = current_repo_versions [img ["version_descriptor" ]]
138
143
if existing_tag :
139
144
new_tag = min (new_tag , existing_tag )
140
145
LOGGER .info (
141
146
f"Got multiple image tags for { img ['name' ]} , "
142
147
f"picking the older one for the starting version ({ new_tag } )"
143
148
)
144
149
REPO_VERSIONS [repo ["name" ]]["from" ] = new_tag
150
+ if not repo_images :
151
+ # if the repo provides no images, its version should be described by its name
152
+ REPO_VERSIONS [repo ["name" ]]["from" ] = current_repo_versions .get (repo ["name" ], "" )
145
153
146
154
for repo_name , new_version in new_repo_versions .items ():
147
155
REPO_VERSIONS [repo_name ]["to" ] = new_version
@@ -156,7 +164,7 @@ def populate_helper_maps(
156
164
}
157
165
158
166
# save result image to map
159
- repo_images = next (repo [ "images" ] for repo in changelog_config ["repositories" ] if repo ["name" ] == repo_name )
167
+ repo_images = next (repo . get ( "images" , []) for repo in changelog_config ["repositories" ] if repo ["name" ] == repo_name )
160
168
for img in repo_images :
161
169
IMG_VERSIONS_BY_NAME [img ["name" ]]["to" ] = normalize_version (REPO_VERSIONS [repo_name ]["to" ])
162
170
@@ -170,15 +178,19 @@ def gather_changelog(cfg: dict[str, Any], repos_dir: Path, gh_headers: dict[str,
170
178
for repository in cfg ["repositories" ]:
171
179
repo_full_name = "/" .join (repository ["url" ].split ("/" )[- 2 :])
172
180
181
+ tag_from = REPO_VERSIONS [repository ["name" ]]["from" ]
182
+ tag_to = REPO_VERSIONS [repository ["name" ]]["to" ]
173
183
commits = gh .get_commits_between_tags (
174
- tag_from = REPO_VERSIONS [ repository [ "name" ]][ "from" ] ,
175
- tag_to = REPO_VERSIONS [ repository [ "name" ]][ "to" ] ,
184
+ tag_from = tag_from ,
185
+ tag_to = tag_to ,
176
186
repo_path = repos_dir / repository ["name" ],
177
187
)
188
+ LOGGER .info (f"Got { len (commits )} commits from range { tag_from } ..{ tag_to } for { repo_full_name } " )
178
189
179
- for commit in commits :
190
+ for idx , commit in enumerate (commits ):
191
+ LOGGER .info (f"[{ idx + 1 } /{ len (commits )} ] Fetching PRs for commit { commit .sha } " )
180
192
prs_info = gh .get_pull_requests_by_commit (
181
- repo_full_name , commit , gh_headers , changelog_config [' changelog_include_label' ]
193
+ repo_full_name , commit , gh_headers , changelog_config [" changelog_include_label" ]
182
194
)
183
195
184
196
for pr in prs_info :
@@ -223,7 +235,7 @@ def gather_changelog(cfg: dict[str, Any], repos_dir: Path, gh_headers: dict[str,
223
235
parser .add_argument ("--root-repo-name" , default = "datalens-tech/datalens" )
224
236
parser .add_argument ("--repos-dir" , type = Path , default = Path ("./repos" ))
225
237
parser .add_argument ("--changelog-path" , type = Path , default = Path ("../../../../CHANGELOG.md" ))
226
- parser .add_argument ("--version-config-path" , required = True , type = Path , help = "path to versionn_config .json" )
238
+ parser .add_argument ("--version-config-path" , required = True , type = Path , help = "path to versions-config .json" )
227
239
parser .add_argument ("--release-type" , choices = ("major" , "minor" , "patch" ), default = "minor" )
228
240
parser .add_argument ("--new-repo-versions" , required = True , help = (
229
241
'a new version for each repo, space separated in the format "name:tag",'
@@ -247,20 +259,29 @@ def gather_changelog(cfg: dict[str, Any], repos_dir: Path, gh_headers: dict[str,
247
259
changelog_config : dict [str , Any ] = json .load (f )
248
260
249
261
with open (args .version_config_path , "r" ) as f :
250
- current_image_versions : dict [str , str ] = json .load (f )
262
+ current_repo_versions : dict [str , str ] = json .load (f )
251
263
264
+ new_repo_versions_input = args .new_repo_versions .strip ()
252
265
new_repo_versions : dict [str , str ] = {}
253
- for item in args .new_repo_versions .strip ().split (" " ):
254
- repo_name , new_version = item .split (":" )
255
- new_repo_versions [repo_name ] = normalize_version (new_version )
266
+ if new_repo_versions_input :
267
+ for item in new_repo_versions_input .split (" " ):
268
+ repo_name , new_version = item .split (":" )
269
+ new_repo_versions [repo_name ] = normalize_version (new_version )
270
+
271
+ # Figure out release tags
272
+ gh_auth_headers = gh .make_gh_auth_headers_from_env ()
273
+ root_repo_name_full = args .root_repo_name
274
+ root_repo_name_short = root_repo_name_full .split ("/" )[- 1 ]
275
+ latest_release = gh .get_latest_repo_release (root_repo_name_full , gh_auth_headers )
276
+ new_release = release_bump_version (latest_release , args .release_type )
256
277
257
278
# Prepare helper mappings
258
- populate_helper_maps (changelog_config , current_image_versions , new_repo_versions )
279
+ if changelog_config .get ("include_root_repo_changes" , True ):
280
+ current_repo_versions [root_repo_name_short ] = latest_release
281
+ new_repo_versions [root_repo_name_short ] = ""
282
+ populate_helper_maps (changelog_config , current_repo_versions , new_repo_versions )
259
283
260
284
# Gather changes
261
- gh_auth_headers = gh .make_gh_auth_headers_from_env ()
262
- latest_release = gh .get_latest_repo_release (args .root_repo_name , gh_auth_headers )
263
- new_release = release_bump_version (latest_release , args .release_type )
264
285
CF = ChangelogFormatter
265
286
changelog = gather_changelog (changelog_config , args .repos_dir , gh_auth_headers )
266
287
@@ -270,18 +291,18 @@ def gather_changelog(cfg: dict[str, Any], repos_dir: Path, gh_headers: dict[str,
270
291
271
292
changelog_lines .append (CF .release (new_release ) + f" ({ datetime .date .today ()} )" )
272
293
273
- changelog_lines .append (CF .section (changelog_config [' images_versions_section' ]))
294
+ changelog_lines .append (CF .section (changelog_config [" images_versions_section" ]))
274
295
img_versions_list : list [str ] = []
275
296
for img_name , img_versions in IMG_VERSIONS_BY_NAME .items ():
276
297
if img_versions ["from" ] != img_versions ["to" ]:
277
298
full_changelog_url = "{repo_url}/compare/v{v_from}...v{v_to}" .format (
278
- repo_url = REPO_CFG_BY_IMG [img_name ][' url' ],
279
- v_from = img_versions [' from' ],
280
- v_to = img_versions ['to' ],
299
+ repo_url = REPO_CFG_BY_IMG [img_name ][" url" ],
300
+ v_from = img_versions [" from" ],
301
+ v_to = img_versions ["to" ],
281
302
)
282
- img_versions_list .append (CF .img_version_changed (img_name , img_versions [' from' ], img_versions ['to' ], full_changelog_url ))
303
+ img_versions_list .append (CF .img_version_changed (img_name , img_versions [" from" ], img_versions ["to" ], full_changelog_url ))
283
304
else :
284
- img_versions_list .append (CF .img_version_unchanged (img_name , img_versions ['to' ]))
305
+ img_versions_list .append (CF .img_version_unchanged (img_name , img_versions ["to" ]))
285
306
changelog_lines .extend (sorted (img_versions_list )) # let's have them in a predictable order
286
307
287
308
for changelog_section , section_lines in sorted (changelog .items ()): # type: str, list[tuple[str, str]]
@@ -306,7 +327,7 @@ def gather_changelog(cfg: dict[str, Any], repos_dir: Path, gh_headers: dict[str,
306
327
# Update image versions
307
328
new_image_versions : dict [str , str ] = {}
308
329
for repo in changelog_config ["repositories" ]:
309
- for img in repo [ "images" ] :
330
+ for img in repo . get ( "images" , []) :
310
331
new_image_versions [img ["version_descriptor" ]] = IMG_VERSIONS_BY_NAME [img ["name" ]]["to" ]
311
332
if not dry_run :
312
333
with open (args .version_config_path , "w" ) as f :
@@ -317,7 +338,7 @@ def gather_changelog(cfg: dict[str, Any], repos_dir: Path, gh_headers: dict[str,
317
338
# Create GitHub release
318
339
if args .create_release and not dry_run :
319
340
release_resp = requests .post (
320
- f"https://api.github.com/repos/{ args . root_repo_name } /releases" ,
341
+ f"https://api.github.com/repos/{ root_repo_name_full } /releases" ,
321
342
headers = gh_auth_headers ,
322
343
json = dict (
323
344
tag_name = new_release ,
@@ -331,7 +352,7 @@ def gather_changelog(cfg: dict[str, Any], repos_dir: Path, gh_headers: dict[str,
331
352
)
332
353
release_resp .raise_for_status ()
333
354
resp_body = release_resp .json ()
334
- release_url = resp_body .get (' html_url' )
355
+ release_url = resp_body .get (" html_url" )
335
356
print (f"Release response body: { resp_body } " )
336
357
print (f"Successfully created a release: { release_url } " )
337
358
if args .make_outputs :
0 commit comments