scripts/deploy_docs_status.py PYTHON 150 lines View on github.com → Search inside
1import logging2import re3from typing import Literal45from github import Auth, Github6from pydantic import BaseModel, SecretStr7from pydantic_settings import BaseSettings8910class Settings(BaseSettings):11    github_repository: str12    github_token: SecretStr13    deploy_url: str | None = None14    commit_sha: str15    run_id: int16    state: Literal["pending", "success", "error"] = "pending"171819class LinkData(BaseModel):20    previous_link: str21    preview_link: str22    en_link: str | None = None232425def main() -> None:26    logging.basicConfig(level=logging.INFO)27    settings = Settings()2829    logging.info(f"Using config: {settings.model_dump_json()}")30    g = Github(auth=Auth.Token(settings.github_token.get_secret_value()))31    repo = g.get_repo(settings.github_repository)32    use_pr = next(33        (pr for pr in repo.get_pulls() if pr.head.sha == settings.commit_sha), None34    )35    if not use_pr:36        logging.error(f"No PR found for hash: {settings.commit_sha}")37        return38    commits = list(use_pr.get_commits())39    current_commit = [c for c in commits if c.sha == settings.commit_sha][0]40    run_url = f"https://github.com/{settings.github_repository}/actions/runs/{settings.run_id}"41    if settings.state == "pending":42        current_commit.create_status(43            state="pending",44            description="Deploying Docs",45            context="deploy-docs",46            target_url=run_url,47        )48        logging.info("No deploy URL available yet")49        return50    if settings.state == "error":51        current_commit.create_status(52            state="error",53            description="Error Deploying Docs",54            context="deploy-docs",55            target_url=run_url,56        )57        logging.info("Error deploying docs")58        return59    assert settings.state == "success"60    if not settings.deploy_url:61        current_commit.create_status(62            state="success",63            description="No Docs Changes",64            context="deploy-docs",65            target_url=run_url,66        )67        logging.info("No docs changes found")68        return69    assert settings.deploy_url70    current_commit.create_status(71        state="success",72        description="Docs Deployed",73        context="deploy-docs",74        target_url=run_url,75    )7677    files = list(use_pr.get_files())78    docs_files = [f for f in files if f.filename.startswith("docs/")]7980    deploy_url = settings.deploy_url.rstrip("/")81    lang_links: dict[str, list[LinkData]] = {}82    for f in docs_files:83        match = re.match(r"docs/([^/]+)/docs/(.*)", f.filename)84        if not match:85            continue86        lang = match.group(1)87        path = match.group(2)88        if path.endswith("index.md"):89            path = path.replace("index.md", "")90        else:91            path = path.replace(".md", "/")92        en_path = path93        if lang == "en":94            use_path = en_path95        else:96            use_path = f"{lang}/{path}"97        link = LinkData(98            previous_link=f"https://fastapi.tiangolo.com/{use_path}",99            preview_link=f"{deploy_url}/{use_path}",100        )101        if lang != "en":102            link.en_link = f"https://fastapi.tiangolo.com/{en_path}"103        lang_links.setdefault(lang, []).append(link)104105    links: list[LinkData] = []106    en_links = lang_links.get("en", [])107    en_links.sort(key=lambda x: x.preview_link)108    links.extend(en_links)109110    langs = list(lang_links.keys())111    langs.sort()112    for lang in langs:113        if lang == "en":114            continue115        current_lang_links = lang_links[lang]116        current_lang_links.sort(key=lambda x: x.preview_link)117        links.extend(current_lang_links)118119    header = "## 📝 Docs preview"120    message = header121    message += f"\n\nLast commit {settings.commit_sha} at: {deploy_url}"122123    if links:124        message += "\n\n### Modified Pages\n\n"125        for link in links:126            message += f"* {link.preview_link}"127            message += f" - ([before]({link.previous_link}))"128            if link.en_link:129                message += f" - ([English]({link.en_link}))"130            message += "\n"131132    print(message)133    issue = use_pr.as_issue()134    comments = list(issue.get_comments())135    for comment in comments:136        if (137            comment.body.startswith(header)138            and comment.user.login == "github-actions[bot]"139        ):140            comment.edit(message)141            break142    else:143        issue.create_comment(message)144145    logging.info("Finished")146147148if __name__ == "__main__":149    main()

Code quality findings 2

Ensure functions have docstrings for documentation
info maintainability missing-docstring
def main() -> None:
Use logging module for better control and configurability
info maintainability print-statement
print(message)

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.

Generated by searchcode.com · powered by code_get_file + code_get_findings