diff --git a/requirements.txt b/requirements.txt index db182cc..c1da158 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,11 @@ certifi==2024.2.2 +cffi==1.16.0 charset-normalizer==3.3.2 idna==3.6 lxml==5.1.0 +pycparser==2.21 +pygit2==1.14.1 python-docx-2023==0.2.17 +PyYAML==6.0.1 requests==2.31.0 urllib3==2.2.1 diff --git a/src/.~lock.20240221_file.docx# b/src/.~lock.20240221_file.docx# deleted file mode 100644 index 53c0680..0000000 --- a/src/.~lock.20240221_file.docx# +++ /dev/null @@ -1 +0,0 @@ -,fred.boniface,bedroom.ws.fjla.net,21.02.2024 22:41,file:///home/fred.boniface/.config/libreoffice/4; \ No newline at end of file diff --git a/src/20240221_file.docx b/src/20240221_file.docx index 95453da..753fceb 100644 Binary files a/src/20240221_file.docx and b/src/20240221_file.docx differ diff --git a/src/gitea_connector.py b/src/gitea_connector.py index 6b529e8..9d76610 100644 --- a/src/gitea_connector.py +++ b/src/gitea_connector.py @@ -1,7 +1,9 @@ -import requests, os +import requests, os, pygit2 from datetime import datetime BASE_URL = "https://git.fjla.uk/" +REPO_URL = f"{BASE_URL}owlboard/data" +REPO_PATH = "./git/clone/data" USER = 'owlbot' TOKEN = os.environ.get('DGP_GITEA_TOK') 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. 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?? -''' \ No newline at end of file + +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() diff --git a/src/local_mode.py b/src/local_mode.py index 655d1da..5c6c99e 100644 --- a/src/local_mode.py +++ b/src/local_mode.py @@ -55,6 +55,10 @@ def start(): formatted_additions = formatter.humanYaml(details) print(formatted_additions) + repo, branch = gitea_connector.clone_repository() + gitea_connector.append_to_pis_file(formatted_additions) + gitea_connector.commit_and_push(repo, branch) +