-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_push.py
52 lines (44 loc) · 1.51 KB
/
auto_push.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
import subprocess
import time
repo_directory = '/home/facundol/deltix'
# Function to check for changes in the directory
def check_changes():
try:
# Run git status to check for changes
result = subprocess.run(
['git', 'status', '--porcelain'],
cwd=repo_directory,
capture_output=True,
text=True
)
# If the result is empty, no changes
return len(result.stdout.strip()) > 0
except Exception as e:
print(f"Error checking for changes: {e}")
return False
# Function to push changes to GitHub
def commit_and_push():
try:
# Stage all changes
subprocess.run(['git', 'add', '.'], cwd=repo_directory)
# Commit the changes
current_time = time.strftime("%H:%M")
commit_message = f"Update {current_time}"
subprocess.run(['git', 'commit', '-m', commit_message], cwd=repo_directory)
# Pull the latest changes from the remote repository
subprocess.run(['git', 'pull', '--rebase'], cwd=repo_directory)
# Push to GitHub
subprocess.run(['git', 'push'], cwd=repo_directory)
print("Changes pushed to GitHub")
except Exception as e:
print(f"Error pushing changes: {e}")
# Run once to check and push changes
def main():
if check_changes():
print("Changes detected, pushing to GitHub...")
commit_and_push()
else:
print("No changes detected.")
if __name__ == "__main__":
main()