inlining LOC chart

This commit is contained in:
pseusys
2023-02-26 12:45:17 +01:00
parent 38a74e3a74
commit cd6377a956
2 changed files with 23 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
from json import load from json import load
from os.path import join, dirname from os.path import join
from typing import Dict from typing import Dict
from manager_environment import EnvironmentManager as EM from manager_environment import EnvironmentManager as EM

View File

@@ -1,4 +1,4 @@
from base64 import b64decode from base64 import b64decode, b64encode
from os import environ from os import environ
from random import choice from random import choice
from re import sub from re import sub
@@ -123,16 +123,23 @@ class GitHubManager:
DBM.g("Action output set!") DBM.g("Action output set!")
@staticmethod @staticmethod
def update_chart(chart_path: str): def update_chart(chart_path: str) -> str:
""" """
Updates lines of code chart. 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. Uses commit author, commit message and branch name specified by environmental variables.
:param chart_path: path to saved lines of code chart. :param chart_path: path to saved lines of code chart.
:returns: string to add to README file.
""" """
DBM.i("Updating lines of code chart...") DBM.i("Updating lines of code chart...")
with open(chart_path, "rb") as input_file: with open(chart_path, "rb") as input_file:
data = input_file.read() 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: try:
contents = GitHubManager.REPO.get_contents(chart_path) contents = GitHubManager.REPO.get_contents(chart_path)
GitHubManager.REPO.update_file(contents.path, "Charts Updated", data, contents.sha, committer=GitHubManager._get_author()) GitHubManager.REPO.update_file(contents.path, "Charts Updated", data, contents.sha, committer=GitHubManager._get_author())
@@ -140,3 +147,9 @@ class GitHubManager:
except UnknownObjectException: except UnknownObjectException:
GitHubManager.REPO.create_file(chart_path, "Charts Added", data, committer=GitHubManager._get_author()) GitHubManager.REPO.create_file(chart_path, "Charts Added", data, committer=GitHubManager._get_author())
DBM.g("Lines of code chart created!") 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![Lines of Code chart]({chart_path})\n\n"