Untitled
unknown
plain_text
2 years ago
962 B
9
Indexable
import subprocess
from datetime import datetime, timedelta
def last_commit_within_last_hours(hours):
# Get the timestamp of the last commit
last_commit_timestamp = int(subprocess.check_output(['git', 'log', '-1', '--pretty=format:%ct']).decode('utf-8').strip())
# Get the current timestamp
current_timestamp = int(datetime.utcnow().timestamp())
# Calculate the time difference in seconds
time_difference = current_timestamp - last_commit_timestamp
# Check if the last commit is within the last specified hours
return time_difference <= hours * 3600
# Set the threshold time in hours
threshold_hours = 5
if last_commit_within_last_hours(threshold_hours):
print("Last commit is within the last {} hours. Skipping new commit.".format(threshold_hours))
else:
# Perform the new commit
commit_message = "Your commit message"
subprocess.run(['git', 'commit', '-m', commit_message])
print("New commit created.")
Editor is loading...
Leave a Comment