This commit is contained in:
parent
5dc349128a
commit
108a90abce
32
main.py
32
main.py
@ -42,7 +42,8 @@ from typing import Any
|
|||||||
|
|
||||||
# external
|
# external
|
||||||
from faker import Faker
|
from faker import Faker
|
||||||
from github import ContentFile, Github, GithubException, InputGitAuthor, Repository
|
# from github import ContentFile, Github, GithubException, InputGitAuthor, Repository
|
||||||
|
from gitea import *
|
||||||
from requests import get as rq_get
|
from requests import get as rq_get
|
||||||
from requests.exceptions import RequestException
|
from requests.exceptions import RequestException
|
||||||
|
|
||||||
@ -127,7 +128,7 @@ class WakaInput:
|
|||||||
|
|
||||||
# mapped environment variables
|
# mapped environment variables
|
||||||
# # required
|
# # required
|
||||||
gh_token: str | None = os.getenv("INPUT_GH_TOKEN")
|
gitea_token: str | None = os.getenv("INPUT_GITEA_TOKEN")
|
||||||
waka_key: str | None = os.getenv("INPUT_WAKATIME_API_KEY")
|
waka_key: str | None = os.getenv("INPUT_WAKATIME_API_KEY")
|
||||||
api_base_url: str | None = os.getenv("INPUT_API_BASE_URL", "https://wakatime.com/api")
|
api_base_url: str | None = os.getenv("INPUT_API_BASE_URL", "https://wakatime.com/api")
|
||||||
repository: str | None = os.getenv("INPUT_REPOSITORY")
|
repository: str | None = os.getenv("INPUT_REPOSITORY")
|
||||||
@ -161,7 +162,7 @@ class WakaInput:
|
|||||||
def validate_input(self):
|
def validate_input(self):
|
||||||
"""Validate Input Env Variables."""
|
"""Validate Input Env Variables."""
|
||||||
logger.debug("Validating input variables")
|
logger.debug("Validating input variables")
|
||||||
if not self.gh_token or not self.waka_key or not self.api_base_url or not self.repository:
|
if not self.gitea_token or not self.waka_key or not self.api_base_url or not self.repository:
|
||||||
logger.error("Invalid inputs")
|
logger.error("Invalid inputs")
|
||||||
logger.info("Refer https://github.com/athul/waka-readme")
|
logger.info("Refer https://github.com/athul/waka-readme")
|
||||||
return False
|
return False
|
||||||
@ -416,7 +417,7 @@ def churn(old_readme: str, /):
|
|||||||
return None if new_readme == old_readme else new_readme
|
return None if new_readme == old_readme else new_readme
|
||||||
|
|
||||||
|
|
||||||
def qualify_target(gh_repo: Repository.Repository):
|
def qualify_target(gitea_repo: Repository.Repository):
|
||||||
"""Qualify target repository defaults."""
|
"""Qualify target repository defaults."""
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -429,15 +430,15 @@ def qualify_target(gh_repo: Repository.Repository):
|
|||||||
committer: InputGitAuthor | None
|
committer: InputGitAuthor | None
|
||||||
author: InputGitAuthor | None
|
author: InputGitAuthor | None
|
||||||
|
|
||||||
gh_branch = gh_repo.default_branch
|
gitea_branch = gitea_repo.default_branch
|
||||||
if wk_i.target_branch != "NOT_SET":
|
if wk_i.target_branch != "NOT_SET":
|
||||||
gh_branch = gh_repo.get_branch(wk_i.target_branch)
|
gitea_branch = gitea_repo.get_branch(wk_i.target_branch)
|
||||||
|
|
||||||
target = gh_repo.get_readme()
|
target = gitea_repo.get_readme()
|
||||||
if wk_i.target_path != "NOT_SET":
|
if wk_i.target_path != "NOT_SET":
|
||||||
target = gh_repo.get_contents(
|
target = gitea_repo.get_contents(
|
||||||
path=wk_i.target_path,
|
path=wk_i.target_path,
|
||||||
ref=gh_branch if isinstance(gh_branch, str) else gh_branch.commit.sha,
|
ref=gitea_branch if isinstance(gitea_branch, str) else gitea_branch.commit.sha,
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(target, list):
|
if isinstance(target, list):
|
||||||
@ -454,7 +455,7 @@ def qualify_target(gh_repo: Repository.Repository):
|
|||||||
path=target.path,
|
path=target.path,
|
||||||
commit_message=wk_i.commit_message,
|
commit_message=wk_i.commit_message,
|
||||||
sha=target.sha,
|
sha=target.sha,
|
||||||
branch=gh_branch if isinstance(gh_branch, str) else gh_branch.name,
|
branch=gitea_branch if isinstance(gitea_branch, str) else gitea_branch.name,
|
||||||
committer=committer,
|
committer=committer,
|
||||||
author=author,
|
author=author,
|
||||||
)
|
)
|
||||||
@ -462,12 +463,13 @@ def qualify_target(gh_repo: Repository.Repository):
|
|||||||
|
|
||||||
def genesis():
|
def genesis():
|
||||||
"""Run Program."""
|
"""Run Program."""
|
||||||
logger.debug("Connecting to GitHub")
|
logger.debug("Connecting to Gitea")
|
||||||
gh_connect = Github(wk_i.gh_token)
|
gitea_connect = Gitea(wk_i.gitea_token)
|
||||||
|
|
||||||
# since a validator is being used earlier, casting
|
# since a validator is being used earlier, casting
|
||||||
# `wk_i.ENV_VARIABLE` to a string here, is okay
|
# `wk_i.ENV_VARIABLE` to a string here, is okay
|
||||||
gh_repo = gh_connect.get_repo(str(wk_i.repository))
|
gitea_repo = gitea_connect.get_repo(str(wk_i.repository))
|
||||||
target = qualify_target(gh_repo)
|
target = qualify_target(gitea_repo)
|
||||||
logger.debug("Decoding readme contents\n")
|
logger.debug("Decoding readme contents\n")
|
||||||
|
|
||||||
readme_contents = str(target.this.decoded_content, encoding="utf-8")
|
readme_contents = str(target.this.decoded_content, encoding="utf-8")
|
||||||
@ -477,7 +479,7 @@ def genesis():
|
|||||||
|
|
||||||
logger.debug("WakaReadme stats has changed")
|
logger.debug("WakaReadme stats has changed")
|
||||||
update_metric = partial(
|
update_metric = partial(
|
||||||
gh_repo.update_file,
|
gitea_repo.update_file,
|
||||||
path=target.path,
|
path=target.path,
|
||||||
message=target.commit_message,
|
message=target.commit_message,
|
||||||
content=new_content,
|
content=new_content,
|
||||||
|
@ -16,7 +16,7 @@ classifiers = [
|
|||||||
"Typing :: Typed",
|
"Typing :: Typed",
|
||||||
]
|
]
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
dependencies = ["faker>=21.0.0", "pygithub>=2.1.1", "requests>=2.31.0"]
|
dependencies = ["faker>=21.0.0", "pygithub>=2.1.1", "requests>=2.31.0", "py-gitea">=0.2.6]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
Homepage = "https://github.com/athul/waka-readme"
|
Homepage = "https://github.com/athul/waka-readme"
|
||||||
|
12
test_giteaapi.py
Normal file
12
test_giteaapi.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
from gitea import *
|
||||||
|
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 = "sangge/tpre-python"
|
||||||
|
#target_branch = "main"
|
||||||
|
#gitea_repo = gitea_connect.get_repo(str(repository))
|
||||||
|
#gitea_branch = gitea_repo.get_branch(target_branch)
|
||||||
|
#print(gitea_branch)
|
Loading…
x
Reference in New Issue
Block a user