[nutanix] Refactor script (#236)

Make the script more readable, mostly by:

- using the Product class,
- removing the use of functions when unnecessary,
- a little bit of renaming and documentation.
This commit is contained in:
Marc Wrobel
2023-12-11 21:24:32 +01:00
committed by GitHub
parent 27721b68d7
commit 3ca984522a

View File

@@ -1,37 +1,25 @@
from common import http from common import dates
from common import endoflife from common import endoflife
from common import http
"""Fetch Nutanix products versions with their dates from https://portal.nutanix.com/api/v1. """Fetch Nutanix products versions from https://portal.nutanix.com/api/v1."""
"""
PRODUCTS = { PRODUCTS = {
'nutanix-aos': 'NOS', 'nutanix-aos': 'https://portal.nutanix.com/api/v1/eol/find?type=NOS',
'nutanix-files': 'FILES', 'nutanix-files': 'https://portal.nutanix.com/api/v1/eol/find?type=FILES',
'nutanix-prism': 'PC', 'nutanix-prism': 'https://portal.nutanix.com/api/v1/eol/find?type=PC',
} }
BASE_URL = "https://portal.nutanix.com/api/v1/eol/find?type=" for product_name, url in PRODUCTS.items():
print(f"::group::{product_name}")
product = endoflife.Product(product_name)
def fetch_releases(product_code):
versions = {}
url = BASE_URL + product_code
print(url)
response = http.fetch_url(url)
data = response.json()
data = http.fetch_url(url).json()
for version_data in data["contents"]: for version_data in data["contents"]:
if 'GENERAL_AVAILABILITY' in version_data: if 'GENERAL_AVAILABILITY' in version_data:
version = version_data["version"] version = version_data["version"]
date = version_data["GENERAL_AVAILABILITY"].split("T")[0] date = dates.parse_datetime(version_data["GENERAL_AVAILABILITY"])
versions[version] = date product.declare_version(version, date)
print(f"{version}: {date}")
return versions product.write()
for product_name, product_code in PRODUCTS.items():
print(f"::group::{product_name}")
all_versions = fetch_releases(product_code)
endoflife.write_releases(product_name, all_versions)
print("::endgroup::") print("::endgroup::")