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

Devel #40

Merged
merged 6 commits into from
Jan 1, 2025
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "signalbot"]
path = signalbot_local
url = https://github.com/jamesoncollins/signalbot.git
34 changes: 13 additions & 21 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,16 @@ services:
environment:
GIT_REPO_URL: https://github.com/jamesoncollins/turbo-bot.git
GIT_REPO_PATH: /root/git/turbo-bot/ # dont change this unless you change the volume below
GIT_REPO_BRANCH: main
GIT_REPO_BRANCH: main
SETUP_SCRIPT_NAME: setup.sh
SETUP_SCRIPT_URL: $${GIT_REPO_URL/\.git/}/raw/$${GIT_REPO_BRANCH}/$${SETUP_SCRIPT_NAME}
entrypoint: ["/bin/bash", "-c"]
command: >
'
mkdir -p $${GIT_REPO_PATH} &&
cd $${GIT_REPO_PATH} &&
( (git init; git remote add origin $${GIT_REPO_URL}; git fetch; git checkout -t origin/$${GIT_REPO_BRANCH} -f) || true ) &&
cd $${GIT_REPO_PATH} &&
git config --global --add safe.directory $${GIT_REPO_PATH} &&
git reset --hard &&
git pull &&
pip install -r requirements.txt &&
apt -y install $(cat pkglist) &&
$${GIT_REPO_PATH}/run.sh
cd /tmp && ( rm $$SETUP_SCRIPT_NAME || true ) &&
curl -o "$$SETUP_SCRIPT_NAME" -sfL "$$SETUP_SCRIPT_URL" &&
chmod +x "$$SETUP_SCRIPT_NAME" &&
./"$$SETUP_SCRIPT_NAME"
'
volumes:
- signal-bot-data:/root/git/
Expand All @@ -56,19 +52,15 @@ services:
GIT_REPO_URL: https://github.com/jamesoncollins/turbo-bot.git
GIT_REPO_PATH: /root/git/turbo-bot/ # dont change this unless you change the volume below
GIT_REPO_BRANCH: devel
SETUP_SCRIPT_NAME: setup.sh
SETUP_SCRIPT_URL: $${GIT_REPO_URL/\.git/}/raw/$${GIT_REPO_BRANCH}/$${SETUP_SCRIPT_NAME}
entrypoint: ["/bin/bash", "-c"]
command: >
'
mkdir -p $${GIT_REPO_PATH} &&
cd $${GIT_REPO_PATH} &&
( (git init; git remote add origin $${GIT_REPO_URL}; git fetch; git checkout -t origin/$${GIT_REPO_BRANCH} -f) || true ) &&
cd $${GIT_REPO_PATH} &&
git config --global --add safe.directory $${GIT_REPO_PATH} &&
git reset --hard &&
git pull &&
pip install -r requirements.txt &&
apt -y install $(cat pkglist) &&
$${GIT_REPO_PATH}/run.sh
cd /tmp && ( rm $$SETUP_SCRIPT_NAME || true ) &&
curl -o "$$SETUP_SCRIPT_NAME" -sfL "$$SETUP_SCRIPT_URL" &&
chmod +x "$$SETUP_SCRIPT_NAME" &&
./"$$SETUP_SCRIPT_NAME"
'
volumes:
- signal-bot-devel-data:/root/git/
Expand Down
25 changes: 12 additions & 13 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os
import sys
from signalbot import SignalBot, Command, Context
from signalbot_local.signalbot import SignalBot, Command, Context
import re
import time
import base64
from handlers.base_handler import BaseHandler
from utils import *
import time
from pickle import NONE
from datetime import datetime

start_time = time.time()

Expand All @@ -18,19 +18,22 @@

def get_git_info():
"""
Retrieves the current branch name and commit ID of the Git repository.
Retrieves the current branch name, commit ID, and timestamp of the latest commit
from the Git repository.

Returns:
tuple: A tuple containing the branch name and commit ID.
Returns (None, None) if not in a Git repository.
str: A formatted string with the branch name, commit ID, and timestamp on separate lines.
Returns "Not a Git repository" if not in a Git repository.
"""
try:
repo = git.Repo(os.path.dirname(os.path.abspath(__file__)), search_parent_directories=True)
branch_name = repo.active_branch.name
commit_id = repo.head.commit.hexsha
return branch_name, commit_id
commit_time = datetime.fromtimestamp(repo.head.commit.committed_date).strftime('%Y-%m-%d %H:%M:%S')

return f"Branch: {branch_name}\nCommit ID: {commit_id}\nTimestamp: {commit_time}"
except git.InvalidGitRepositoryError:
return None, None
return "Not a Git repository"

def find_group_by_internal_id(data, target_id):
for entry in data:
Expand Down Expand Up @@ -178,13 +181,9 @@ async def handle(self, c: Context):
await c.reply( LOGMSG + summary, base64_attachments=[plot_b64])
elif msg == "#":
print("is hash")
branch, commit = get_git_info()
git_info = get_git_info()
str = f"Uptime: {(time.time() - start_time)} seconds\n"
if branch and commit:
str += f"Branch: {branch}\n"
str += f"Commit ID: {commit}\n"
else:
str += "Not in a Git repository."
str += git_info
await c.reply( LOGMSG + "I am here.\n" + str)
elif msg == "#turboboot":
print("is reboot")
Expand Down
31 changes: 31 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Ensure the GIT_REPO_PATH directory exists
mkdir -p ${GIT_REPO_PATH}
cd ${GIT_REPO_PATH}

# Initialize the repository and configure the remote and branch
( (git init;
git remote add origin ${GIT_REPO_URL};
git fetch;
git checkout -t origin/${GIT_REPO_BRANCH} -f) || true )

# Configure the repository as a safe directory for Git
cd ${GIT_REPO_PATH}
git config --global --add safe.directory ${GIT_REPO_PATH}

# Fetch the latest changes and reset to match the remote branch
git fetch origin
git reset --hard origin/${GIT_REPO_BRANCH}

# Initialize and update Git submodules
git submodule update --init --recursive

# Install Python dependencies
pip install -r requirements.txt

# Install system packages from pkglist
apt -y install $(cat pkglist)

# Run the main script
${GIT_REPO_PATH}/run.sh
1 change: 1 addition & 0 deletions signalbot_local
Submodule signalbot_local added at 57d571
Loading