s4s-editor-beta / app.py
soiz1's picture
Update app.py
2cd2947 verified
raw
history blame
1.35 kB
import os
import subprocess
import shutil
# GitHubのリポジトリURL
repo_url = "https://github.com/izum00/penguinmod-s4s"
# 環境変数からトークンを取得
token = os.getenv("github_token")
if not token:
raise RuntimeError("環境変数 'github_token' が設定されていません。")
# 認証情報付きのURLを作成
authed_url = repo_url.replace("https://", f"https://{token}@")
# カレントディレクトリのパス
current_dir = os.getcwd()
subprocess.run(["git", "config", "--global", "user.name", "izum00"], check=True)
subprocess.run(["git", "config", "--global", "user.email", os.getenv("mail")], check=True)
subprocess.run(["git", "config", "--global", "--add", "safe.directory", "/app"], check=True)
# .gitディレクトリがなければ初期化
if not os.path.exists(os.path.join(current_dir, ".git")):
subprocess.run(["git", "init"], check=True)
subprocess.run(["git", "remote", "add", "origin", authed_url], check=True)
else:
subprocess.run(["git", "remote", "set-url", "origin", authed_url], check=True)
# Gitの操作
subprocess.run(["git", "add", "."], check=True)
subprocess.run(["git", "commit", "-m", "auto commit from script"], check=True)
subprocess.run(["git", "branch", "-M", "main"], check=True)
subprocess.run(["git", "push", "-u", "origin", "main", "--force"], check=True)