Files
docs-fastapi/scripts/topic_repos.py
T
The Scheduler a42b1ff04e
Issue Manager / issue-manager (push) Has been cancelled
Build Docs / changes (push) Has been cancelled
Build Docs / langs (push) Has been cancelled
Build Docs / build-docs (push) Has been cancelled
Build Docs / docs-all-green (push) Has been cancelled
Conflict detector / main (push) Has been cancelled
Test Redistribute / test-redistribute (fastapi) (push) Has been cancelled
Test Redistribute / test-redistribute (fastapi-slim) (push) Has been cancelled
Test Redistribute / test-redistribute-alls-green (push) Has been cancelled
Test / lint (push) Has been cancelled
Test / test (pydantic-v1, 3.10) (push) Has been cancelled
Test / test (pydantic-v1, 3.11) (push) Has been cancelled
Test / test (pydantic-v1, 3.13) (push) Has been cancelled
Test / test (pydantic-v1, 3.8) (push) Has been cancelled
Test / test (pydantic-v1, 3.9) (push) Has been cancelled
Test / test (pydantic-v2, 3.10) (push) Has been cancelled
Test / test (pydantic-v2, 3.11) (push) Has been cancelled
Test / test (pydantic-v2, 3.12) (push) Has been cancelled
Test / test (pydantic-v2, 3.13) (push) Has been cancelled
Test / test (pydantic-v2, 3.14) (push) Has been cancelled
Test / test (pydantic-v2, 3.8) (push) Has been cancelled
Test / test (pydantic-v2, 3.9) (push) Has been cancelled
Test / coverage-combine (push) Has been cancelled
Test / check (push) Has been cancelled
Label Approved / label-approved (push) Has been cancelled
FastAPI People Contributors / job (push) Has been cancelled
FastAPI People Sponsors / job (push) Has been cancelled
Update Topic Repos / topic-repos (push) Has been cancelled
FastAPI People / job (push) Has been cancelled
Test / test (pydantic-v1, 3.12) (push) Has been cancelled
Sync fastapi docs from b5ca1324 on 2025-12-07
2025-12-07 21:35:20 +00:00

81 lines
2.7 KiB
Python

import logging
import secrets
import subprocess
from pathlib import Path
import yaml
from github import Github
from pydantic import BaseModel, SecretStr
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
github_repository: str
github_token: SecretStr
class Repo(BaseModel):
name: str
html_url: str
stars: int
owner_login: str
owner_html_url: str
def main() -> None:
logging.basicConfig(level=logging.INFO)
settings = Settings()
logging.info(f"Using config: {settings.model_dump_json()}")
g = Github(settings.github_token.get_secret_value(), per_page=100)
r = g.get_repo(settings.github_repository)
repos = g.search_repositories(query="topic:fastapi")
repos_list = list(repos)
final_repos: list[Repo] = []
for repo in repos_list[:100]:
if repo.full_name == settings.github_repository:
continue
final_repos.append(
Repo(
name=repo.name,
html_url=repo.html_url,
stars=repo.stargazers_count,
owner_login=repo.owner.login,
owner_html_url=repo.owner.html_url,
)
)
data = [repo.model_dump() for repo in final_repos]
# Local development
# repos_path = Path("../docs/en/data/topic_repos.yml")
repos_path = Path("./docs/en/data/topic_repos.yml")
repos_old_content = repos_path.read_text(encoding="utf-8")
new_repos_content = yaml.dump(data, sort_keys=False, width=200, allow_unicode=True)
if repos_old_content == new_repos_content:
logging.info("The data hasn't changed. Finishing.")
return
repos_path.write_text(new_repos_content, encoding="utf-8")
logging.info("Setting up GitHub Actions git user")
subprocess.run(["git", "config", "user.name", "github-actions"], check=True)
subprocess.run(
["git", "config", "user.email", "github-actions@github.com"], check=True
)
branch_name = f"fastapi-topic-repos-{secrets.token_hex(4)}"
logging.info(f"Creating a new branch {branch_name}")
subprocess.run(["git", "checkout", "-b", branch_name], check=True)
logging.info("Adding updated file")
subprocess.run(["git", "add", str(repos_path)], check=True)
logging.info("Committing updated file")
message = "👥 Update FastAPI GitHub topic repositories"
subprocess.run(["git", "commit", "-m", message], check=True)
logging.info("Pushing branch")
subprocess.run(["git", "push", "origin", branch_name], check=True)
logging.info("Creating PR")
pr = r.create_pull(title=message, body=message, base="master", head=branch_name)
logging.info(f"Created PR: {pr.number}")
logging.info("Finished")
if __name__ == "__main__":
main()