Skip to content

Commit aa6ad3d

Browse files
committed
🔨 Update docs previews script
1 parent 811fe9f commit aa6ad3d

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

scripts/deploy_docs_status.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
import re
33

44
from github import Github
5-
from pydantic import SecretStr
5+
from pydantic import BaseModel, SecretStr
66
from pydantic_settings import BaseSettings
77

8+
site_domain = "sqlmodel.tiangolo.com"
9+
810

911
class Settings(BaseSettings):
1012
github_repository: str
@@ -15,7 +17,12 @@ class Settings(BaseSettings):
1517
is_done: bool = False
1618

1719

18-
def main():
20+
class LinkData(BaseModel):
21+
previous_link: str
22+
preview_link: str
23+
24+
25+
def main() -> None:
1926
logging.basicConfig(level=logging.INFO)
2027
settings = Settings()
2128

@@ -60,24 +67,31 @@ def main():
6067
docs_files = [f for f in files if f.filename.startswith("docs/")]
6168

6269
deploy_url = settings.deploy_url.rstrip("/")
63-
links: list[str] = []
70+
links: list[LinkData] = []
6471
for f in docs_files:
6572
match = re.match(r"docs/(.*)", f.filename)
66-
assert match
73+
if not match:
74+
continue
6775
path = match.group(1)
6876
if path.endswith("index.md"):
69-
path = path.replace("index.md", "")
77+
use_path = path.replace("index.md", "")
7078
else:
71-
path = path.replace(".md", "/")
72-
link = f"{deploy_url}/{path}"
79+
use_path = path.replace(".md", "/")
80+
link = LinkData(
81+
previous_link=f"https://{site_domain}/{use_path}",
82+
preview_link=f"{deploy_url}/{use_path}",
83+
)
7384
links.append(link)
74-
links.sort()
85+
links.sort(key=lambda x: x.preview_link)
7586

7687
message = f"📝 Docs preview for commit {settings.commit_sha} at: {deploy_url}"
7788

7889
if links:
7990
message += "\n\n### Modified Pages\n\n"
80-
message += "\n".join([f"* {link}" for link in links])
91+
for link in links:
92+
message += f"* {link.preview_link}"
93+
message += f" - ([before]({link.previous_link}))"
94+
message += "\n"
8195

8296
print(message)
8397
use_pr.as_issue().create_comment(message)

0 commit comments

Comments
 (0)