|
13 | 13 | import logging |
14 | 14 | import os |
15 | 15 | import pathlib |
16 | | -import re |
17 | 16 | import shutil |
18 | 17 | import typing |
19 | 18 | import urllib.parse |
|
32 | 31 | import shipit_api.common.config |
33 | 32 | import shipit_api.common.models |
34 | 33 | from shipit_api.admin.release import parse_version |
35 | | -from shipit_api.common.product import Product, ProductCategory |
| 34 | +from shipit_api.common.product import Product, ProductCategory, get_product_category |
36 | 35 |
|
37 | 36 | logger = logging.getLogger(__name__) |
38 | 37 |
|
@@ -259,44 +258,6 @@ def get_releases_from_db(db_session: sqlalchemy.orm.Session, breakpoint_version: |
259 | 258 | return query.all() |
260 | 259 |
|
261 | 260 |
|
262 | | -def get_product_categories(product: Product, version: str) -> typing.List[ProductCategory]: |
263 | | - # typically, these are dot releases that are considered major |
264 | | - SPECIAL_FIREFOX_MAJORS = ["14.0.1", "125.0.1"] |
265 | | - SPECIAL_THUNDERBIRD_MAJORS = ["14.0.1", "38.0.1"] |
266 | | - |
267 | | - def patternize_versions(versions): |
268 | | - if not versions: |
269 | | - return "" |
270 | | - return "|" + "|".join([v.replace(r".", r"\.") for v in versions]) |
271 | | - |
272 | | - categories = [] |
273 | | - categories_mapping: typing.List[typing.Tuple[ProductCategory, str]] = [] |
274 | | - |
275 | | - if product is Product.THUNDERBIRD: |
276 | | - special_majors = patternize_versions(SPECIAL_THUNDERBIRD_MAJORS) |
277 | | - else: |
278 | | - special_majors = patternize_versions(SPECIAL_FIREFOX_MAJORS) |
279 | | - |
280 | | - categories_mapping.append((ProductCategory.MAJOR, r"([0-9]+\.[0-9]+%s)$" % special_majors)) |
281 | | - categories_mapping.append((ProductCategory.MAJOR, r"([0-9]+\.[0-9]+(esr|)%s)$" % special_majors)) |
282 | | - categories_mapping.append((ProductCategory.STABILITY, r"([0-9]+\.[0-9]+\.[0-9]+$|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$)")) |
283 | | - categories_mapping.append((ProductCategory.STABILITY, r"([0-9]+\.[0-9]+\.[0-9]+(esr|)$|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+(esr|)$)")) |
284 | | - # We had 38.0.5b2 |
285 | | - categories_mapping.append((ProductCategory.DEVELOPMENT, r"([0-9]+\.[0-9]|[0-9]+\.[0-9]+\.[0-9])(b|rc|build|plugin)[0-9]+$")) |
286 | | - |
287 | | - # Ugly hack to manage the next ESR (when we have two overlapping esr) |
288 | | - if shipit_api.common.config.ESR_NEXT: |
289 | | - categories_mapping.append((ProductCategory.ESR, shipit_api.common.config.ESR_NEXT + r"(\.[0-9]+){1,2}esr$")) |
290 | | - else: |
291 | | - categories_mapping.append((ProductCategory.ESR, shipit_api.common.config.CURRENT_ESR + r"(\.[0-9]+){1,2}esr$")) |
292 | | - |
293 | | - for product_category, version_pattern in categories_mapping: |
294 | | - if re.match(version_pattern, version): |
295 | | - categories.append(product_category) |
296 | | - |
297 | | - return categories |
298 | | - |
299 | | - |
300 | 261 | def get_releases( |
301 | 262 | breakpoint_version: int, products: Products, releases: typing.List[shipit_api.common.models.Release], old_product_details: ProductDetails |
302 | 263 | ) -> Releases: |
@@ -358,20 +319,22 @@ def get_releases( |
358 | 319 | for release in releases: |
359 | 320 | if release.product != product.value: |
360 | 321 | continue |
361 | | - categories = get_product_categories(Product(release.product), release.version) |
| 322 | + |
362 | 323 | release_version = release.version |
363 | | - for category in categories: |
364 | | - if release_version.endswith("esr"): |
365 | | - release_version = release_version[: -len("esr")] |
366 | | - details[f"{release.product}-{release.version}"] = dict( |
367 | | - category=category.value, |
368 | | - product=release.product, |
369 | | - build_number=release.build_number, |
370 | | - description=None, |
371 | | - is_security_driven=False, # TODO: we don't have this field anymore |
372 | | - version=release_version, |
373 | | - date=with_default(release.completed, functools.partial(to_format, format="YYYY-MM-DD"), default=""), |
374 | | - ) |
| 324 | + version = parse_version(product, release_version) |
| 325 | + category = get_product_category(version) |
| 326 | + |
| 327 | + if release_version.endswith("esr"): |
| 328 | + release_version = release_version[: -len("esr")] |
| 329 | + details[f"{release.product}-{release.version}"] = dict( |
| 330 | + category=category.value, |
| 331 | + product=release.product, |
| 332 | + build_number=release.build_number, |
| 333 | + description=None, |
| 334 | + is_security_driven=False, # TODO: we don't have this field anymore |
| 335 | + version=release_version, |
| 336 | + date=with_default(release.completed, functools.partial(to_format, format="YYYY-MM-DD"), default=""), |
| 337 | + ) |
375 | 338 |
|
376 | 339 | return dict(releases=details) |
377 | 340 |
|
@@ -454,18 +417,6 @@ def get_release_history( |
454 | 417 | if release_version is None or release_version.major_number < breakpoint_version: |
455 | 418 | continue |
456 | 419 |
|
457 | | - # skip all releases which don't fit into product category |
458 | | - if product_category is ProductCategory.MAJOR and ( |
459 | | - release_version.patch_number is not None or release_version.beta_number is not None or release_version.is_esr |
460 | | - ): |
461 | | - continue |
462 | | - |
463 | | - elif product_category is ProductCategory.DEVELOPMENT and (release_version.beta_number is None or release_version.is_esr): |
464 | | - continue |
465 | | - |
466 | | - elif product_category is ProductCategory.STABILITY and (release_version.beta_number is not None or release_version.patch_number is None): |
467 | | - continue |
468 | | - |
469 | 420 | history_version = release.version |
470 | 421 | if history_version.endswith("esr"): |
471 | 422 | history_version = history_version[: -len("esr")] |
|
0 commit comments