-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.py
More file actions
47 lines (38 loc) · 1.36 KB
/
update.py
File metadata and controls
47 lines (38 loc) · 1.36 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import subprocess
import argparse
import time
def fetch_updates():
"""Fetch updates from the remote repository."""
subprocess.run(["git", "fetch", "origin", "main"], check=True)
def get_changelog():
"""Get the changelog of new commits."""
result = subprocess.run(
["git", "log", "HEAD..origin/main", "--pretty=format:%h - %s (%an, %ar)"],
capture_output=True,
text=True,
check=True
)
return result.stdout if result.stdout else "No new updates available."
def save_changelog_to_file(changelog):
"""Save the changelog to a file."""
with open("changelog.txt", "w") as file:
file.write(changelog)
def apply_updates():
"""Apply the updates by resetting the local branch."""
subprocess.run(["git", "reset", "--hard", "origin/main"], check=True)
def main(apply):
while not apply:
fetch_updates()
changelog = get_changelog()
if changelog != "No new updates available.":
save_changelog_to_file(changelog)
time.sleep(60) # update check every minute!
if apply:
fetch_updates()
apply_updates()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Update script")
parser.add_argument('--apply', action='store_true', help='Apply the updates')
args = parser.parse_args()
print("HEY!")
main(args.apply)