fix: dead GitHub links -> gitea; gitea push helper
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import json, subprocess, os, pathlib
|
||||
|
||||
# Gitea push helper (post-recovery). Token is NEVER stored in this file.
|
||||
# Sources, in order: $GITEA_TOKEN -> ~/.gitea_token -> hermes scratch token file.
|
||||
def load_tok():
|
||||
t = os.environ.get("GITEA_TOKEN", "").strip()
|
||||
if t:
|
||||
return t
|
||||
for p in (pathlib.Path.home() / ".gitea_token",
|
||||
pathlib.Path(r"C:/Users/User/AppData/Local/hermes/cache/scratch/gitea_tok.txt")):
|
||||
if p.exists():
|
||||
t = p.read_text(encoding="utf-8").strip()
|
||||
if t:
|
||||
return t
|
||||
raise SystemExit("no gitea token: set GITEA_TOKEN or ~/.gitea_token")
|
||||
|
||||
tok = load_tok()
|
||||
|
||||
def sh(args, show=True):
|
||||
p = subprocess.run(args, capture_output=True, text=True, encoding="utf-8", errors="replace",
|
||||
cwd=r"C:/Users/User/tmp/treg_repo")
|
||||
if show:
|
||||
out = (p.stdout + p.stderr).strip()
|
||||
# never print credential URLs
|
||||
out = out.replace(tok, "TOKEN")
|
||||
print("rc", p.returncode, out[-600:] if out else "")
|
||||
return p.returncode
|
||||
|
||||
sh(["git", "add", "-A"])
|
||||
sh(["git", "-c", "user.name=reform", "-c", "user.email=reform@reformboss.com",
|
||||
"commit", "-m", "mail doors: PROVIDERS.md matrix, WP onelogin register API RE, prober v3 (cloakbrowser TokenFactory, 30/15min pacing), farm v3 core, GH OAuth door"])
|
||||
url = "https://reform:" + tok + "@git.reformboss.com/reform/treg-autoreg.git"
|
||||
subprocess.run(["git", "remote", "set-url", "origin", url], capture_output=True,
|
||||
cwd=r"C:/Users/User/tmp/treg_repo")
|
||||
rc = sh(["git", "push", "origin", "pubmain:main"], show=False)
|
||||
print("push rc:", rc)
|
||||
if rc != 0:
|
||||
p = subprocess.run(["git", "push", "origin", "pubmain:main"], capture_output=True, text=True,
|
||||
encoding="utf-8", errors="replace", cwd=r"C:/Users/User/tmp/treg_repo")
|
||||
print((p.stdout + p.stderr).replace(tok, "TOKEN")[-500:])
|
||||
# point origin at the token-free URL and set remote branch
|
||||
subprocess.run(["git", "remote", "set-url", "origin", "https://git.reformboss.com/reform/treg-autoreg.git"],
|
||||
capture_output=True, cwd=r"C:/Users/User/tmp/treg_repo")
|
||||
print("remote cleaned")
|
||||
Reference in New Issue
Block a user