40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from gitea import *
|
|
import os
|
|
from base64 import b64decode, b64encode
|
|
|
|
URL = "https://git.mamahaha.work"
|
|
TOKEN = open("token.log", "r").read().strip()
|
|
gitea_connect = Gitea(URL, TOKEN)
|
|
print("Gitea Version: " + gitea_connect.get_version())
|
|
print("API-Token belongs to user: " + gitea_connect.get_user().username)
|
|
|
|
# Repository details
|
|
owner = "sangge" # Replace with the repository owner's username
|
|
repo_name = ".profile" # Replace with the repository name
|
|
|
|
# Get repository object
|
|
gitea_repo = Repository.request(gitea_connect, owner, repo_name)
|
|
print(gitea_repo.get_branches()[0].name)
|
|
|
|
readme_content = Content(gitea_connect)
|
|
readme_content.path = "README.md"
|
|
readme_content.type = Content.FILE
|
|
readme_data = gitea_repo.get_file_content(readme_content)
|
|
|
|
|
|
readme_contents = str(b64decode(readme_data), encoding="utf-8") + "123123"
|
|
# print(readme_contents)
|
|
|
|
readme_content = Content(gitea_connect)
|
|
readme_content.path = "README.md"
|
|
readme_content.type = Content.FILE
|
|
|
|
b64_readme_contents = b64encode(bytes(readme_contents, "utf-8"))
|
|
content = b64_readme_contents.decode("ascii")
|
|
|
|
acontent = gitea_repo.get_git_content()
|
|
readmes = [c for c in acontent if c.name == "README.md"]
|
|
# gitea_repo.change_file(readmes[0].name, readmes[0].sha, content)
|
|
print(content)
|
|
print(b64_readme_contents)
|