You've already forked wakapi-readme-stats
inlining LOC chart
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from json import load
|
||||
from os.path import join, dirname
|
||||
from os.path import join
|
||||
from typing import Dict
|
||||
|
||||
from manager_environment import EnvironmentManager as EM
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from base64 import b64decode
|
||||
from base64 import b64decode, b64encode
|
||||
from os import environ
|
||||
from random import choice
|
||||
from re import sub
|
||||
@@ -123,16 +123,23 @@ class GitHubManager:
|
||||
DBM.g("Action output set!")
|
||||
|
||||
@staticmethod
|
||||
def update_chart(chart_path: str):
|
||||
def update_chart(chart_path: str) -> str:
|
||||
"""
|
||||
Updates lines of code chart.
|
||||
Inlines data into readme if in debug mode, commits otherwise.
|
||||
Uses commit author, commit message and branch name specified by environmental variables.
|
||||
|
||||
:param chart_path: path to saved lines of code chart.
|
||||
:returns: string to add to README file.
|
||||
"""
|
||||
DBM.i("Updating lines of code chart...")
|
||||
with open(chart_path, "rb") as input_file:
|
||||
data = input_file.read()
|
||||
|
||||
if not EM.DEBUG_RUN:
|
||||
DBM.i("Pushing chart to repo...")
|
||||
chart_path = f"https://raw.githubusercontent.com/{GitHubManager.USER.login}/{GitHubManager.USER.login}/{GitHubManager.branch()}/{chart_path}"
|
||||
|
||||
try:
|
||||
contents = GitHubManager.REPO.get_contents(chart_path)
|
||||
GitHubManager.REPO.update_file(contents.path, "Charts Updated", data, contents.sha, committer=GitHubManager._get_author())
|
||||
@@ -140,3 +147,9 @@ class GitHubManager:
|
||||
except UnknownObjectException:
|
||||
GitHubManager.REPO.create_file(chart_path, "Charts Added", data, committer=GitHubManager._get_author())
|
||||
DBM.g("Lines of code chart created!")
|
||||
|
||||
else:
|
||||
DBM.i("Inlining chart...")
|
||||
chart_path = f"data:image/png;base64,{b64encode(data)}"
|
||||
|
||||
return f"**{FM.t('Timeline')}**\n\n\n\n"
|
||||
|
||||
Reference in New Issue
Block a user