summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorKyren223 <Kyren223@proton.me>2025-06-05 13:42:54 +0300
committerKyren223 <Kyren223@proton.me>2025-06-05 13:42:54 +0300
commitd2f9cb70ad60c3429df3b414d5bb33944ef685c4 (patch)
tree1a1a0ab23fc2491decab14466618d2018bada9e2 /scripts
parentbecb29ef63162549aa119acc4ad6727e7bc43226 (diff)
Moved timers into their own nix module, fixed issues with sops, upgraded
gitea.py to use env vars for secrets, added a timer to run every 5 hours to mirror repos from github to gitea
Diffstat (limited to 'scripts')
-rwxr-xr-x[-rw-r--r--]scripts/gitea.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/scripts/gitea.py b/scripts/gitea.py
index 873775e..7c63e07 100644..100755
--- a/scripts/gitea.py
+++ b/scripts/gitea.py
@@ -1,14 +1,27 @@
+import os
+import sys
import requests
from github import Github
from github import Auth
-GITHUB_TOKEN = ""
+def read_token(var: str) -> str:
+ path = os.getenv(var)
+ if path is None:
+ print(f"Missing env var: {var}", file=sys.stderr)
+ sys.exit(1)
+ return open(path).read().strip()
+
+GITHUB_TOKEN: str = read_token("GITHUB_TOKEN_FILE")
GITHUB_USERNAME = "Kyren223"
GITEA_URL = "https://git.kyren.codes"
-GITEA_TOKEN = ""
+GITEA_TOKEN: str = read_token("GITEA_TOKEN_FILE")
GITEA_USER = "Kyren223"
+success = 0
+skipped = 0
+failed = 0
+
def repo_exists(repo_name: str) -> bool:
headers = {'Authorization': f'token {GITEA_TOKEN}'}
r = requests.get(f'{GITEA_URL}/api/v1/repos/{GITEA_USER}/{repo_name}', headers=headers)
@@ -17,6 +30,7 @@ def repo_exists(repo_name: str) -> bool:
def mirror(addr: str, repo_name: str):
if repo_exists(repo_name):
print(f"Skipping existing repo: {repo_name}")
+ global skipped; skipped += 1
return
json = {
@@ -43,12 +57,11 @@ def mirror(addr: str, repo_name: str):
json=json, params=payload)
r.raise_for_status()
+ global success; success += 1
print(f'Mirrored {repo_name}')
except requests.exceptions.HTTPError as e:
- if r.status_code == 422:
- print(f"Skipping existing repo: {repo_name} (failed)")
- else:
- print(f"Failed to mirror {repo_name}: {e}")
+ global failed; failed += 1
+ print(f"Failed to mirror {repo_name}: {e}")
# using an access token
auth = Auth.Token(GITHUB_TOKEN or '')
@@ -64,3 +77,5 @@ for repo in g.get_user().get_repos():
# To close connections after use
g.close()
+
+print(f"\nSummary: {success} mirrored, {skipped} skipped, {failed} failed.")