Gitpush needs auth
This commit is contained in:
parent
f5d0877151
commit
676beab6b3
@ -1,11 +1,13 @@
|
||||
certifi==2024.2.2
|
||||
cffi==1.16.0
|
||||
charset-normalizer==3.3.2
|
||||
gitdb==4.0.11
|
||||
GitPython==3.1.42
|
||||
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
|
||||
smmap==5.0.1
|
||||
urllib3==2.2.1
|
||||
|
@ -1,4 +1,4 @@
|
||||
import requests, os, pygit2
|
||||
import requests, os, git
|
||||
from datetime import datetime
|
||||
|
||||
BASE_URL = "https://git.fjla.uk/"
|
||||
@ -10,6 +10,8 @@ HEADERS = {
|
||||
'Content-Type': 'application/json',
|
||||
'accept': 'application/json',
|
||||
}
|
||||
BRANCH_NAME = datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||
|
||||
|
||||
'''
|
||||
I need a way here to get the original file from the 'main' branch and
|
||||
@ -24,30 +26,14 @@ 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
|
||||
git.Repo.clone_from(REPO_URL, REPO_PATH)
|
||||
|
||||
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):
|
||||
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 + "/pis/gw.yaml", 'a') as file:
|
||||
file.write(text_to_append)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
clone_repository()
|
||||
repo.index.add(["pis/gw.yaml"])
|
||||
repo.index.commit(commit_message)
|
||||
origin = repo.remote(name='origin')
|
||||
origin.push(refspec=BRANCH_NAME)
|
||||
|
@ -55,9 +55,8 @@ 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)
|
||||
gitea_connector.clone_repository()
|
||||
gitea_connector.commit_and_push_changes(formatted_additions,"From owlbot diagram-parser")
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user