snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
140
zerver/openapi/merge_api_changelogs.py
Normal file
140
zerver/openapi/merge_api_changelogs.py
Normal file
@@ -0,0 +1,140 @@
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def get_changelog_files_list() -> list[str]:
|
||||
dir_path = Path("api_docs/unmerged.d")
|
||||
if os.path.exists(dir_path):
|
||||
return [os.path.basename(path) for path in glob.glob(f"{dir_path}/ZF-??????.md")]
|
||||
|
||||
return []
|
||||
|
||||
|
||||
def get_unmerged_changelogs(verbose: bool = True) -> str:
|
||||
changelogs = ""
|
||||
dir_path = Path("api_docs/unmerged.d")
|
||||
changelog_files_list = get_changelog_files_list()
|
||||
if verbose:
|
||||
if changelog_files_list:
|
||||
print(f"Unmerged changelog files: {changelog_files_list}")
|
||||
else:
|
||||
print("No unmerged changelog files found.")
|
||||
|
||||
for file_name in changelog_files_list:
|
||||
file_path = Path(f"{dir_path}/{file_name}")
|
||||
with open(file_path) as f:
|
||||
changelogs += f.read().strip("\n") + "\n"
|
||||
|
||||
return changelogs
|
||||
|
||||
|
||||
def get_feature_level(update_feature_level: bool = True) -> int:
|
||||
new_feature_level = None
|
||||
version_file_path = Path("version.py")
|
||||
|
||||
with open(version_file_path) as file:
|
||||
lines = file.readlines()
|
||||
|
||||
new_feature_level = None
|
||||
|
||||
with open(version_file_path, "w") as file:
|
||||
for line in lines:
|
||||
if line.startswith("API_FEATURE_LEVEL = "):
|
||||
match = re.search(r"\d+", line)
|
||||
if match:
|
||||
new_feature_level = int(match.group()) + 1
|
||||
if update_feature_level:
|
||||
file.write(f"API_FEATURE_LEVEL = {new_feature_level}\n")
|
||||
continue
|
||||
|
||||
file.write(line)
|
||||
|
||||
assert new_feature_level is not None
|
||||
if update_feature_level:
|
||||
print(f"Updated API feature level: {new_feature_level - 1} -> {new_feature_level}")
|
||||
return new_feature_level
|
||||
|
||||
|
||||
def get_current_major_version() -> str | None:
|
||||
changelog_path = Path("api_docs/changelog.md")
|
||||
with open(changelog_path) as file:
|
||||
for line in file:
|
||||
match = re.search(r"## Changes in Zulip (\d+\.\d+)", line)
|
||||
if match:
|
||||
return match.group(1)
|
||||
return None
|
||||
|
||||
|
||||
def merge_changelogs(changelogs: str, new_feature_level: int, update_changelog: bool = True) -> str:
|
||||
changelogs_merged = False
|
||||
changelog_path = Path("api_docs/changelog.md")
|
||||
|
||||
changelog_markdown_string = ""
|
||||
|
||||
with open(changelog_path) as file:
|
||||
lines = file.readlines()
|
||||
|
||||
changelogs_merged = False
|
||||
|
||||
with open(changelog_path, "w") as file:
|
||||
for line in lines:
|
||||
file.write(line)
|
||||
changelog_markdown_string += line
|
||||
if changelogs_merged:
|
||||
continue
|
||||
if re.fullmatch(r"## Changes in Zulip \d+\.\d+\n", line):
|
||||
changelogs_merged = True
|
||||
updates = f"\n**Feature level {new_feature_level}**\n\n{changelogs}"
|
||||
changelog_markdown_string += updates
|
||||
if update_changelog:
|
||||
file.write(updates)
|
||||
|
||||
if update_changelog:
|
||||
print(f"Changelogs merged to {changelog_path}.")
|
||||
return changelog_markdown_string
|
||||
|
||||
|
||||
def update_feature_level_in_api_docs(new_feature_level: int) -> None:
|
||||
changelog_files_list = get_changelog_files_list()
|
||||
num_replaces = 0
|
||||
current_version = get_current_major_version()
|
||||
|
||||
# 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"))
|
||||
|
||||
for api_docs_path in api_docs_paths:
|
||||
with open(api_docs_path) as file:
|
||||
lines = file.readlines()
|
||||
|
||||
num_replaces = 0
|
||||
|
||||
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")]
|
||||
|
||||
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)
|
||||
|
||||
if old_line != line:
|
||||
num_replaces += 1
|
||||
|
||||
file.write(line)
|
||||
|
||||
if num_replaces:
|
||||
print(f"Updated {api_docs_path}; {num_replaces} replaces were made.")
|
||||
|
||||
|
||||
def remove_unmerged_changelog_files() -> None:
|
||||
changelog_files_list = get_changelog_files_list()
|
||||
for file_name in changelog_files_list:
|
||||
os.remove(Path(f"api_docs/unmerged.d/{file_name}"))
|
||||
|
||||
if changelog_files_list:
|
||||
print("Removed all the unmerged changelog files.")
|
||||
Reference in New Issue
Block a user