22import re
33
44from github import Github
5- from pydantic import SecretStr
5+ from pydantic import BaseModel , SecretStr
66from pydantic_settings import BaseSettings
77
8+ site_domain = "sqlmodel.tiangolo.com"
9+
810
911class 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