tools: Update files in api_docs folder along with zulip.yaml.

This commit is contained in:
Vector73
2025-05-12 07:20:48 +00:00
committed by Tim Abbott
parent fba724fbb5
commit 8e400eb283

View File

@@ -92,33 +92,36 @@ def merge_changelogs(changelogs: str, new_feature_level: int) -> None:
def update_feature_level_in_api_docs(new_feature_level: int) -> None:
changelog_files_list = get_changelog_files_list()
num_replaces = 0
api_docs_path = Path("zerver/openapi/zulip.yaml")
current_version = get_current_major_version()
with open(api_docs_path) as file:
lines = file.readlines()
# Get all the markdown files in api_docs folder along with zulip.yaml.
api_docs_folder = Path("api_docs")
api_docs_paths = list(api_docs_folder.glob("*.md"))
api_docs_paths.append(Path("zerver/openapi/zulip.yaml"))
num_replaces = 0
for api_docs_path in api_docs_paths:
with open(api_docs_path) as file:
lines = file.readlines()
with open(api_docs_path, "w") as file:
for line in lines:
old_line = line
for file_name in changelog_files_list:
temporary_feature_level = file_name[: -len(".md")]
num_replaces = 0
pattern = rf"Zulip \d+\.\d+ \(feature level {temporary_feature_level}\)"
replacement = f"Zulip {current_version} (feature level {new_feature_level})"
line = re.sub(pattern, replacement, line)
with open(api_docs_path, "w") as file:
for line in lines:
old_line = line
for file_name in changelog_files_list:
temporary_feature_level = file_name[: -len(".md")]
if old_line != line:
num_replaces += 1
pattern = rf"Zulip \d+\.\d+ \(feature level {temporary_feature_level}\)"
replacement = f"Zulip {current_version} (feature level {new_feature_level})"
line = re.sub(pattern, replacement, line)
file.write(line)
if old_line != line:
num_replaces += 1
if num_replaces:
print(f"Updated {api_docs_path}; {num_replaces} replaces were made.")
else:
print(f"No changes were made to {api_docs_path}; no matching file name found.")
file.write(line)
if num_replaces:
print(f"Updated {api_docs_path}; {num_replaces} replaces were made.")
def remove_unmerged_changelog_files() -> None: