2
2
import re
3
3
4
4
from github import Github
5
- from pydantic import SecretStr
5
+ from pydantic import BaseModel , SecretStr
6
6
from pydantic_settings import BaseSettings
7
7
8
+ site_domain = "sqlmodel.tiangolo.com"
9
+
8
10
9
11
class Settings (BaseSettings ):
10
12
github_repository : str
@@ -15,7 +17,12 @@ class Settings(BaseSettings):
15
17
is_done : bool = False
16
18
17
19
18
- def main ():
20
+ class LinkData (BaseModel ):
21
+ previous_link : str
22
+ preview_link : str
23
+
24
+
25
+ def main () -> None :
19
26
logging .basicConfig (level = logging .INFO )
20
27
settings = Settings ()
21
28
@@ -60,24 +67,31 @@ def main():
60
67
docs_files = [f for f in files if f .filename .startswith ("docs/" )]
61
68
62
69
deploy_url = settings .deploy_url .rstrip ("/" )
63
- links : list [str ] = []
70
+ links : list [LinkData ] = []
64
71
for f in docs_files :
65
72
match = re .match (r"docs/(.*)" , f .filename )
66
- assert match
73
+ if not match :
74
+ continue
67
75
path = match .group (1 )
68
76
if path .endswith ("index.md" ):
69
- path = path .replace ("index.md" , "" )
77
+ use_path = path .replace ("index.md" , "" )
70
78
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
+ )
73
84
links .append (link )
74
- links .sort ()
85
+ links .sort (key = lambda x : x . preview_link )
75
86
76
87
message = f"📝 Docs preview for commit { settings .commit_sha } at: { deploy_url } "
77
88
78
89
if links :
79
90
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 "
81
95
82
96
print (message )
83
97
use_pr .as_issue ().create_comment (message )
0 commit comments