[red-hat-openshift] Refactor script (#243)
Make the script more readable, mostly by: - using the Product class, - a little bit of renaming and documentation, - removing the use of functions when unnecessary.
This commit is contained in:
@@ -1,46 +1,31 @@
|
||||
import re
|
||||
from pathlib import Path
|
||||
from common import dates
|
||||
from common import endoflife
|
||||
from common.git import Git
|
||||
|
||||
"""
|
||||
Fetch Red Hat OpenShift versions from the documentation git repository
|
||||
"""
|
||||
"""Fetches Red Hat OpenShift versions from the documentation's git repository"""
|
||||
|
||||
PRODUCT = "red-hat-openshift"
|
||||
REPO_URL = "https://github.com/openshift/openshift-docs.git"
|
||||
VERSION_AND_DATE_PATTERN = re.compile(r"{product-title}\s(?P<version>\d+\.\d+\.\d+).*\n+Issued:\s(?P<date>\d{4}-\d\d-\d\d)$", re.MULTILINE)
|
||||
|
||||
|
||||
def get_versions_from_file(release_notes_file: Path) -> dict:
|
||||
if not release_notes_file.exists():
|
||||
return {}
|
||||
|
||||
with open(release_notes_file, "rb") as f:
|
||||
plain = f.read().decode("utf-8")
|
||||
|
||||
return {
|
||||
version: date
|
||||
for (version, date) in re.findall(
|
||||
r"{product-title}\s(?P<version>\d+\.\d+\.\d+).*$\n+Issued:\s(?P<date>\d{4}-\d\d-\d\d)$",
|
||||
plain,
|
||||
re.MULTILINE,
|
||||
)
|
||||
}
|
||||
|
||||
git = Git(REPO_URL)
|
||||
product = endoflife.Product("red-hat-openshift")
|
||||
print(f"::group::{product.name}")
|
||||
git = Git("https://github.com/openshift/openshift-docs.git")
|
||||
git.setup()
|
||||
versions = {}
|
||||
|
||||
# only fetch v4+ branches, because the format was different in openshift v3
|
||||
for branch in git.list_branches("refs/heads/enterprise-[4-9]*"):
|
||||
version = branch.split("-")[1].replace(".", "-")
|
||||
release_notes_file = f"release_notes/ocp-{version}-release-notes.adoc"
|
||||
git.checkout(branch, file_list=[release_notes_file])
|
||||
versions = {**versions, **get_versions_from_file(git.repo_dir / release_notes_file)}
|
||||
release_notes_filename = f"release_notes/ocp-{version}-release-notes.adoc"
|
||||
git.checkout(branch, file_list=[release_notes_filename])
|
||||
|
||||
print(f"::group::{PRODUCT}")
|
||||
for version, date in versions.items():
|
||||
print(f"{version}: {date}")
|
||||
release_notes_file = git.repo_dir / release_notes_filename
|
||||
if not release_notes_file.exists():
|
||||
continue
|
||||
|
||||
endoflife.write_releases(PRODUCT, versions)
|
||||
with open(release_notes_file, "rb") as f:
|
||||
content = f.read().decode("utf-8")
|
||||
for (version, date_str) in VERSION_AND_DATE_PATTERN.findall(content):
|
||||
product.declare_version(version, dates.parse_date(date_str))
|
||||
|
||||
product.write()
|
||||
print("::endgroup::")
|
||||
|
||||
Reference in New Issue
Block a user