Get on the right branch
This commit is contained in:
@@ -5,6 +5,8 @@ from fastapi import FastAPI
|
||||
from git import Repo
|
||||
from nextcord.ext import commands
|
||||
|
||||
from config import DakinyConfig
|
||||
|
||||
app = FastAPI()
|
||||
REPO_URL = "https://gitea.cheezers.org/imcompiling/dakiny-messages.git"
|
||||
REPO_DIR = "./dakiny-messages"
|
||||
@@ -13,7 +15,8 @@ REPO_DIR = "./dakiny-messages"
|
||||
class ClanMessages(commands.Cog, name="Clan Messages"):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
self.clone_repo()
|
||||
self.config: DakinyConfig = self.bot.config
|
||||
self.repo_setup()
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
@@ -38,9 +41,8 @@ class ClanMessages(commands.Cog, name="Clan Messages"):
|
||||
# for ever directory, sort the files by number then post
|
||||
# posting involves checking if there is a message for that particular file then editing it or creating a
|
||||
# new one. the message could be deleted, which would cause a new message to be sent and database updated.
|
||||
pass
|
||||
|
||||
def clone_repo(self):
|
||||
def repo_setup(self):
|
||||
"""
|
||||
Checks if the repo exists and creates repo object, clones if it does not.
|
||||
"""
|
||||
@@ -50,6 +52,19 @@ class ClanMessages(commands.Cog, name="Clan Messages"):
|
||||
else:
|
||||
self.repo = Repo.clone_from(REPO_URL, REPO_DIR)
|
||||
|
||||
self.origin = self.repo.remote("origin")
|
||||
|
||||
if self.config.params.git_branch == "test":
|
||||
self.repo.create_head("test", self.origin.refs.test).set_tracking_branch(
|
||||
self.origin.refs.test
|
||||
).checkout()
|
||||
else:
|
||||
self.repo.create_head("main", self.origin.refs.main).set_tracking_branch(
|
||||
self.origin.refs.main
|
||||
).checkout()
|
||||
|
||||
self.origin.pull()
|
||||
|
||||
|
||||
# This function will be called when this extension is loaded.
|
||||
# It is necessary to add these functions to the bot.
|
||||
|
||||
Reference in New Issue
Block a user