Git doesn't work

This commit is contained in:
Fred Boniface 2024-02-21 23:56:35 +00:00
parent a98e069b88
commit f5d0877151
5 changed files with 44 additions and 3 deletions

View File

@ -1,7 +1,11 @@
certifi==2024.2.2 certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2 charset-normalizer==3.3.2
idna==3.6 idna==3.6
lxml==5.1.0 lxml==5.1.0
pycparser==2.21
pygit2==1.14.1
python-docx-2023==0.2.17 python-docx-2023==0.2.17
PyYAML==6.0.1
requests==2.31.0 requests==2.31.0
urllib3==2.2.1 urllib3==2.2.1

View File

@ -1 +0,0 @@
,fred.boniface,bedroom.ws.fjla.net,21.02.2024 22:41,file:///home/fred.boniface/.config/libreoffice/4;

Binary file not shown.

View File

@ -1,7 +1,9 @@
import requests, os import requests, os, pygit2
from datetime import datetime from datetime import datetime
BASE_URL = "https://git.fjla.uk/" BASE_URL = "https://git.fjla.uk/"
REPO_URL = f"{BASE_URL}owlboard/data"
REPO_PATH = "./git/clone/data"
USER = 'owlbot' USER = 'owlbot'
TOKEN = os.environ.get('DGP_GITEA_TOK') TOKEN = os.environ.get('DGP_GITEA_TOK')
HEADERS = { HEADERS = {
@ -16,4 +18,36 @@ append the generated PIS codes. Then push to a new generated branch.
Then a pull request should be created but can probably be done with actions. Then a pull request should be created but can probably be done with actions.
In reality this program should just take in DOCX files and spit out formatted In reality this program should just take in DOCX files and spit out formatted
PIS data to the repo, everything else can be handled at the repo level?? PIS data to the repo, everything else can be handled at the repo level??
'''
None of this currently works...
'''
def clone_repository():
# Clone the repository
repo = pygit2.clone_repository(REPO_URL, REPO_PATH, bare=False, depth=1)
new_branch_name = "bot" + datetime.now().strftime("%Y%m%d-%H%M%S")
repo.create_branch(new_branch_name)
repo.checkout(new_branch_name)
print("Repository cloned successfully!")
return repo, branch
def commit_and_push(repo, branch, commit_msg):
index = repo.index
index.add(REPO_PATH + "/pis/gw.yaml")
tree = index.write_tree()
author = pygit2.Signature("OwlBot", "bot@owlboard.info")
committer = author
new_commit = repo.create_commit(branch, author, committer, commit_message, tree, [repo.head.target])
remote = repo.remotes["origin"]
remote.push(["new-branch"])
def append_to_pis_file(text_to_append):
with open(REPO_PATH + "/pis/gw.yaml", 'a') as file:
file.write(text_to_append)
if __name__ == "__main__":
clone_repository()

View File

@ -55,6 +55,10 @@ def start():
formatted_additions = formatter.humanYaml(details) formatted_additions = formatter.humanYaml(details)
print(formatted_additions) print(formatted_additions)
repo, branch = gitea_connector.clone_repository()
gitea_connector.append_to_pis_file(formatted_additions)
gitea_connector.commit_and_push(repo, branch)