-
Notifications
You must be signed in to change notification settings - Fork 0
/
repo_monitor.py
33 lines (24 loc) · 1.04 KB
/
repo_monitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import shelve
from conf import MONITORED_REPOS
def read_commit_log(repo, local_path, on_new_commit):
os.system(f"cd {local_path} && git log --all --oneline > commit_log.txt")
with open(f"{local_path}/commit_log.txt", "r") as f:
with shelve.open(f"{local_path}/commit_log") as db:
for line in reversed(f.readlines()):
key = line[0:9]
value = line[10:]
if key not in db:
db[key] = value
on_new_commit(repo, value)
def check_repos(on_new_commit):
print("Checking repos...")
for repo, path in MONITORED_REPOS.items():
local_path = path.split("/")[-1][:-4]
if not os.path.exists(local_path):
os.system(f"git clone --filter=blob:none --no-checkout {path}")
read_commit_log(repo, local_path, lambda *args: None)
os.system(f"cd {local_path} && git fetch --filter=blob:none")
read_commit_log(repo, local_path, on_new_commit)
if __name__ == "__main__":
check_repos(print)