👷 Refactor GitHub Action to comment docs deployment URLs and update token (#11925)

This commit is contained in:
Sebastián Ramírez
2024-07-31 18:40:04 -05:00
committed by GitHub
parent c0ae16ab7a
commit 8b930f8847
6 changed files with 52 additions and 97 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")