From ecd3d32ceb55330ff84dea7ff5cd64bcc71cbfa7 Mon Sep 17 00:00:00 2001 From: pseusys Date: Sun, 26 Feb 2023 10:46:32 +0100 Subject: [PATCH] prefix added to readme contents --- sources/manager_environment.py | 13 ------------- sources/manager_github.py | 24 ++++++++++++++++++------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/sources/manager_environment.py b/sources/manager_environment.py index 777ba9e..a38a782 100644 --- a/sources/manager_environment.py +++ b/sources/manager_environment.py @@ -1,6 +1,4 @@ from os import getenv, environ -from random import choice -from string import ascii_letters class EnvironmentManager: @@ -48,14 +46,3 @@ class EnvironmentManager: DEBUG_LOGGING = getenv("INPUT_DEBUG_LOGGING", "0").lower() in _TRUTHY DEBUG_RUN = getenv("DEBUG_RUN", "False").lower() in _TRUTHY - - @staticmethod - def set_github_output(name: str, content: str): - if "GITHUB_OUTPUT" not in environ.keys(): - raise Exception("Not in GitHub environment ('GITHUB_OUTPUT' not defined)!") - eol = "".join(choice(ascii_letters) for _ in range(10)) - escaped = content.replace("%", "%25").replace("\n", "%0A").replace("\r", "%0D") - with open(environ["GITHUB_OUTPUT"], "a") as fh: - fh.write(f"{name}<<{eol}") - fh.write(escaped) - fh.write(eol) diff --git a/sources/manager_github.py b/sources/manager_github.py index 8714c47..e34588d 100644 --- a/sources/manager_github.py +++ b/sources/manager_github.py @@ -1,5 +1,8 @@ from base64 import b64decode +from os import environ +from random import choice from re import sub +from string import ascii_letters from github import Github, AuthenticatedUser, Repository, ContentFile, InputGitAuthor, UnknownObjectException @@ -102,16 +105,25 @@ class GitHubManager: return False @staticmethod - async def push_to_pr(stats: str): + def set_github_output(stats: str): """ - Pushes readme data to current PR body instead of committing it. + Outputs readme data as current action output instead of committing it. - :param stats: Readme stats to be pushed. + param stats: Readme stats to be outputted. """ + DBM.i("Setting README contents as action output...") + if "GITHUB_OUTPUT" not in environ.keys(): + raise Exception("Not in GitHub environment ('GITHUB_OUTPUT' not defined)!") + prefix = "README stats current output:" - DBM.i("Commenting PR...") - EM.set_github_output("README_CONTENT", f"{prefix}\n\n{stats}") - DBM.g("PR commented!") + eol = "".join(choice(ascii_letters) for _ in range(10)) + with open(environ["GITHUB_OUTPUT"], "a") as fh: + fh.write(f"README_CONTENT<<{eol}") + fh.write(f"{prefix}\n\n{stats}") + fh.write(eol) + + DBM.g("Action output set!") + @staticmethod def update_chart(chart_path: str):