update readme
This commit is contained in:
48
main.py
48
main.py
@@ -42,6 +42,7 @@ 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 gitea import *
|
||||||
from requests import get as rq_get
|
from requests import get as rq_get
|
||||||
@@ -69,6 +70,7 @@ try:
|
|||||||
|
|
||||||
# comment this out to disable colored logging
|
# comment this out to disable colored logging
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
logger.debug("loguru loaded")
|
logger.debug("loguru loaded")
|
||||||
|
|
||||||
# load from .env before class def gets parsed
|
# load from .env before class def gets parsed
|
||||||
@@ -165,7 +167,12 @@ 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.gitea_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
|
||||||
@@ -444,9 +451,9 @@ def qualify_target(gitea_repo: Repository, gitea_connect: Gitea):
|
|||||||
readme_content = Content(gitea_connect)
|
readme_content = Content(gitea_connect)
|
||||||
readme_content.path = "README.md"
|
readme_content.path = "README.md"
|
||||||
readme_content.type = Content.FILE
|
readme_content.type = Content.FILE
|
||||||
target = gitea_repo.get_file_content(readme_content) # base64 encoded
|
target = gitea_repo.get_file_content(readme_content) # base64 encoded
|
||||||
# target = gitea_repo.get_readme()
|
# target = gitea_repo.get_readme()
|
||||||
|
|
||||||
# if wk_i.target_path != "NOT_SET":
|
# if wk_i.target_path != "NOT_SET":
|
||||||
# target = gitea_repo.get_contents(
|
# target = gitea_repo.get_contents(
|
||||||
# path=wk_i.target_path,
|
# path=wk_i.target_path,
|
||||||
@@ -487,26 +494,31 @@ def genesis():
|
|||||||
target = qualify_target(gitea_repo, gitea_connect)
|
target = qualify_target(gitea_repo, gitea_connect)
|
||||||
logger.debug("Decoding readme contents\n")
|
logger.debug("Decoding readme contents\n")
|
||||||
|
|
||||||
|
|
||||||
readme_contents = str(b64decode(target.this), encoding="utf-8")
|
readme_contents = str(b64decode(target.this), encoding="utf-8")
|
||||||
if not (new_content := churn(readme_contents)):
|
if not (new_content := churn(readme_contents)):
|
||||||
logger.info("WakaReadme was not updated")
|
logger.info("WakaReadme was not updated")
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.debug("WakaReadme stats has changed")
|
logger.debug("WakaReadme stats has changed")
|
||||||
update_metric = partial(
|
# update_metric = partial(
|
||||||
gitea_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,
|
||||||
sha=target.sha,
|
# sha=target.sha,
|
||||||
branch=target.branch,
|
# branch=target.branch,
|
||||||
)
|
# )
|
||||||
if target.committer:
|
# if target.committer:
|
||||||
update_metric = partial(update_metric, committer=target.committer)
|
# update_metric = partial(update_metric, committer=target.committer)
|
||||||
if target.author:
|
# if target.author:
|
||||||
update_metric = partial(update_metric, author=target.author)
|
# update_metric = partial(update_metric, author=target.author)
|
||||||
update_metric()
|
# update_metric()
|
||||||
|
b64_new_content = b64encode(bytes(new_content, "utf-8"))
|
||||||
|
repo_content = gitea_repo.get_git_content()
|
||||||
|
readmes = [c for c in repo_content if c.name == "README.md"]
|
||||||
|
sha = readmes[0].sha
|
||||||
|
str_new_content = b64_new_content.decode("utf-8")
|
||||||
|
gitea_repo.change_file(readmes[0].name, readmes[0].sha, str_new_content)
|
||||||
logger.info("Stats updated successfully")
|
logger.info("Stats updated successfully")
|
||||||
|
|
||||||
|
|
||||||
@@ -521,7 +533,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# initial waka-readme setup
|
# initial waka-readme setup
|
||||||
logger.debug("Initialize WakaReadme")
|
logger.debug("Initialize WakaReadme")
|
||||||
wk_i = WakaInput()
|
wk_i = WakaInput()
|
||||||
if not wk_i.validate_input():
|
if not wk_i.validate_input():
|
||||||
logger.error("Environment variables are misconfigured\n")
|
logger.error("Environment variables are misconfigured\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@@ -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", "py-gitea">=0.2.6]
|
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"
|
||||||
|
Reference in New Issue
Block a user