Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 Update docs previews script #218

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions scripts/deploy_docs_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import re

from github import Github
from pydantic import SecretStr
from pydantic import BaseModel, SecretStr
from pydantic_settings import BaseSettings

site_domain = "dockerswarm.rocks"


class Settings(BaseSettings):
github_repository: str
Expand All @@ -15,7 +17,12 @@ class Settings(BaseSettings):
is_done: bool = False


def main():
class LinkData(BaseModel):
previous_link: str
preview_link: str


def main() -> None:
logging.basicConfig(level=logging.INFO)
settings = Settings()

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

deploy_url = settings.deploy_url.rstrip("/")
links: list[str] = []
links: list[LinkData] = []
for f in docs_files:
match = re.match(r"docs/(.*)", f.filename)
assert match
if not match:
continue
path = match.group(1)
if path.endswith("index.md"):
path = path.replace("index.md", "")
use_path = path.replace("index.md", "")
else:
path = path.replace(".md", "/")
link = f"{deploy_url}/{path}"
use_path = path.replace(".md", "/")
link = LinkData(
previous_link=f"https://{site_domain}/{use_path}",
preview_link=f"{deploy_url}/{use_path}",
)
links.append(link)
links.sort()
links.sort(key=lambda x: x.preview_link)

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

if links:
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}))"
message += "\n"

print(message)
use_pr.as_issue().create_comment(message)
Expand Down
Loading