mirror of https://github.com/tiangolo/fastapi.git
🔨 Update docs preview script to show previous version and English version (#12856)
This commit is contained in:
parent
5d03558363
commit
98182d02ce
|
|
@ -2,7 +2,7 @@ import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from github import Github
|
from github import Github
|
||||||
from pydantic import SecretStr
|
from pydantic import BaseModel, SecretStr
|
||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -15,7 +15,13 @@ class Settings(BaseSettings):
|
||||||
is_done: bool = False
|
is_done: bool = False
|
||||||
|
|
||||||
|
|
||||||
def main():
|
class LinkData(BaseModel):
|
||||||
|
previous_link: str
|
||||||
|
preview_link: str
|
||||||
|
en_link: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
|
||||||
|
|
@ -60,7 +66,7 @@ def main():
|
||||||
docs_files = [f for f in files if f.filename.startswith("docs/")]
|
docs_files = [f for f in files if f.filename.startswith("docs/")]
|
||||||
|
|
||||||
deploy_url = settings.deploy_url.rstrip("/")
|
deploy_url = settings.deploy_url.rstrip("/")
|
||||||
lang_links: dict[str, list[str]] = {}
|
lang_links: dict[str, list[LinkData]] = {}
|
||||||
for f in docs_files:
|
for f in docs_files:
|
||||||
match = re.match(r"docs/([^/]+)/docs/(.*)", f.filename)
|
match = re.match(r"docs/([^/]+)/docs/(.*)", f.filename)
|
||||||
if not match:
|
if not match:
|
||||||
|
|
@ -71,15 +77,22 @@ def main():
|
||||||
path = path.replace("index.md", "")
|
path = path.replace("index.md", "")
|
||||||
else:
|
else:
|
||||||
path = path.replace(".md", "/")
|
path = path.replace(".md", "/")
|
||||||
|
en_path = path
|
||||||
if lang == "en":
|
if lang == "en":
|
||||||
link = f"{deploy_url}/{path}"
|
use_path = en_path
|
||||||
else:
|
else:
|
||||||
link = f"{deploy_url}/{lang}/{path}"
|
use_path = f"{lang}/{path}"
|
||||||
|
link = LinkData(
|
||||||
|
previous_link=f"https://fastapi.tiangolo.com/{use_path}",
|
||||||
|
preview_link=f"{deploy_url}/{use_path}",
|
||||||
|
)
|
||||||
|
if lang != "en":
|
||||||
|
link.en_link = f"https://fastapi.tiangolo.com/{en_path}"
|
||||||
lang_links.setdefault(lang, []).append(link)
|
lang_links.setdefault(lang, []).append(link)
|
||||||
|
|
||||||
links: list[str] = []
|
links: list[LinkData] = []
|
||||||
en_links = lang_links.get("en", [])
|
en_links = lang_links.get("en", [])
|
||||||
en_links.sort()
|
en_links.sort(key=lambda x: x.preview_link)
|
||||||
links.extend(en_links)
|
links.extend(en_links)
|
||||||
|
|
||||||
langs = list(lang_links.keys())
|
langs = list(lang_links.keys())
|
||||||
|
|
@ -88,14 +101,19 @@ def main():
|
||||||
if lang == "en":
|
if lang == "en":
|
||||||
continue
|
continue
|
||||||
current_lang_links = lang_links[lang]
|
current_lang_links = lang_links[lang]
|
||||||
current_lang_links.sort()
|
current_lang_links.sort(key=lambda x: x.preview_link)
|
||||||
links.extend(current_lang_links)
|
links.extend(current_lang_links)
|
||||||
|
|
||||||
message = f"📝 Docs preview for commit {settings.commit_sha} at: {deploy_url}"
|
message = f"📝 Docs preview for commit {settings.commit_sha} at: {deploy_url}"
|
||||||
|
|
||||||
if links:
|
if links:
|
||||||
message += "\n\n### Modified Pages\n\n"
|
message += "\n\n### Modified Pages\n\n"
|
||||||
message += "\n".join([f"* {link}" for link in links])
|
for link in links:
|
||||||
|
message += f"* {link.preview_link}"
|
||||||
|
message += f" - ([before]({link.previous_link}))"
|
||||||
|
if link.en_link:
|
||||||
|
message += f" - ([English]({link.en_link}))"
|
||||||
|
message += "\n"
|
||||||
|
|
||||||
print(message)
|
print(message)
|
||||||
use_pr.as_issue().create_comment(message)
|
use_pr.as_issue().create_comment(message)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue