Gitpush needs auth
This commit is contained in:
parent
f5d0877151
commit
676beab6b3
@ -1,11 +1,13 @@
|
|||||||
certifi==2024.2.2
|
certifi==2024.2.2
|
||||||
cffi==1.16.0
|
cffi==1.16.0
|
||||||
charset-normalizer==3.3.2
|
charset-normalizer==3.3.2
|
||||||
|
gitdb==4.0.11
|
||||||
|
GitPython==3.1.42
|
||||||
idna==3.6
|
idna==3.6
|
||||||
lxml==5.1.0
|
lxml==5.1.0
|
||||||
pycparser==2.21
|
pycparser==2.21
|
||||||
pygit2==1.14.1
|
|
||||||
python-docx-2023==0.2.17
|
python-docx-2023==0.2.17
|
||||||
PyYAML==6.0.1
|
PyYAML==6.0.1
|
||||||
requests==2.31.0
|
requests==2.31.0
|
||||||
|
smmap==5.0.1
|
||||||
urllib3==2.2.1
|
urllib3==2.2.1
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import requests, os, pygit2
|
import requests, os, git
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
BASE_URL = "https://git.fjla.uk/"
|
BASE_URL = "https://git.fjla.uk/"
|
||||||
@ -10,6 +10,8 @@ HEADERS = {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'accept': '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
|
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():
|
def clone_repository():
|
||||||
# Clone the repository
|
git.Repo.clone_from(REPO_URL, REPO_PATH)
|
||||||
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):
|
def commit_and_push_changes(text_to_append, commit_message):
|
||||||
index = repo.index
|
repo = git.Repo(REPO_PATH)
|
||||||
index.add(REPO_PATH + "/pis/gw.yaml")
|
repo.git.checkout("-b", BRANCH_NAME)
|
||||||
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:
|
with open(REPO_PATH + "/pis/gw.yaml", 'a') as file:
|
||||||
file.write(text_to_append)
|
file.write(text_to_append)
|
||||||
|
repo.index.add(["pis/gw.yaml"])
|
||||||
|
repo.index.commit(commit_message)
|
||||||
|
origin = repo.remote(name='origin')
|
||||||
|
origin.push(refspec=BRANCH_NAME)
|
||||||
if __name__ == "__main__":
|
|
||||||
clone_repository()
|
|
||||||
|
@ -55,9 +55,8 @@ 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.clone_repository()
|
||||||
gitea_connector.append_to_pis_file(formatted_additions)
|
gitea_connector.commit_and_push_changes(formatted_additions,"From owlbot diagram-parser")
|
||||||
gitea_connector.commit_and_push(repo, branch)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user