♻️ Refactor Deploy Docs GitHub Action to be a script and update token preparing for org (#1039)

This commit is contained in:
Sebastián Ramírez
2024-07-31 19:05:06 -05:00
committed by GitHub
parent d7af50c184
commit 77374aa016
6 changed files with 57 additions and 92 deletions

View File

@ -0,0 +1,31 @@
import logging
import sys
from github import Github
from pydantic import SecretStr
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
github_repository: str
github_token: SecretStr
deploy_url: str
commit_sha: str
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
settings = Settings()
logging.info(f"Using config: {settings.model_dump_json()}")
g = Github(settings.github_token.get_secret_value())
repo = g.get_repo(settings.github_repository)
use_pr = next(
(pr for pr in repo.get_pulls() if pr.head.sha == settings.commit_sha), None
)
if not use_pr:
logging.error(f"No PR found for hash: {settings.commit_sha}")
sys.exit(0)
use_pr.as_issue().create_comment(
f"📝 Docs preview for commit {settings.commit_sha} at: {settings.deploy_url}"
)
logging.info("Finished")