import requests, os, git 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 = { 'Content-Type': 'application/json', 'accept': 'application/json', } BRANCH_NAME = 'auto-' + datetime.now().strftime("%Y%m%d-%H%M%S") FILE_NAME = 'dg_parser_' + datetime.now().strftime("%Y%m%d-%H%M%S") ''' I need a way here to get the original file from the 'main' branch and 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?? None of this currently works... ''' def clone_repository(): git.Repo.clone_from(REPO_URL, REPO_PATH) def commit_and_push_changes(text_to_append, commit_message): repo = git.Repo(REPO_PATH) repo.git.checkout("-b", BRANCH_NAME) with open(REPO_PATH + f"/pis/{FILE_NAME}.yaml", 'w') as file: file.write(text_to_append) repo.index.add([f"pis/{FILE_NAME}.yaml"]) repo.index.commit(commit_message) origin = repo.remote(name='origin') origin_url_credentials = REPO_URL.replace('https://', f'https://{USER}:{TOKEN}@') origin.set_url(origin_url_credentials) origin.push(refspec=BRANCH_NAME)