Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check for updates #235

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions clashroyalebuildabot/utils/git_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import subprocess
import sys

from loguru import logger


def _is_branch_late() -> bool:
subprocess.run(
["git", "fetch"], check=True, capture_output=True, text=True
)

status = subprocess.run(
["git", "status", "-uno"],
capture_output=True,
text=True,
check=True,
).stdout
return "Your branch is up to date" not in status


def _check_and_pull_updates() -> None:
if not _is_branch_late():
return

should_update = input(
"New updates available. Do you want to update the bot? [y]/n: "
)
if should_update.lower() not in ["y", "yes", ""]:
return
subprocess.run(["git", "pull"], check=True, capture_output=True, text=True)


def check_and_pull_updates() -> None:
try:
_check_and_pull_updates()
except subprocess.CalledProcessError as e:
logger.error(f"Error while checking / pulling updates: {e.stderr}")
sys.exit(1)
2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from clashroyalebuildabot.actions import MusketeerAction
from clashroyalebuildabot.actions import WitchAction
from clashroyalebuildabot.bot import Bot
from clashroyalebuildabot.utils.git_utils import check_and_pull_updates

start_time = datetime.now()

Expand All @@ -39,6 +40,7 @@ def update_terminal_title():


def main():
check_and_pull_updates()
actions = [
ArchersAction,
GoblinBarrelAction,
Expand Down