From 0e54dd50ec80fb7d85bdc90285f0a5505e11f839 Mon Sep 17 00:00:00 2001 From: mQzLjP <91550006+mQzLjP@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:19:39 +0800 Subject: [PATCH] feat: JOJ3 issue enhancement (#43) --- joint_teapot/app.py | 15 ++++++++++++++- joint_teapot/utils/joj3.py | 28 +++++++++++++--------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/joint_teapot/app.py b/joint_teapot/app.py index 4b4888c..8dcee9b 100644 --- a/joint_teapot/app.py +++ b/joint_teapot/app.py @@ -235,6 +235,10 @@ def joj3_scoreboard( scoreboard_file_name: str = Argument( "scoreboard.csv", help="name of scoreboard file in the gitea repo" ), + exercise_name: str = Argument( + "unknown", + help="name of the exercise that appears on the issue title", + ), ) -> None: set_settings(Settings(_env_file=env_path)) set_logger(settings.stderr_log_level, diagnose=False, backtrace=False) @@ -256,6 +260,7 @@ def joj3_scoreboard( score_file_path, submitter, os.path.join(repo_path, scoreboard_file_name), + exercise_name, ) actions_link = ( f"https://{settings.gitea_domain_name}{settings.gitea_suffix}/" @@ -294,6 +299,10 @@ def joj3_failed_table( failed_table_file_name: str = Argument( "failed-table.md", help="name of failed table file in the gitea repo" ), + exercise_name: str = Argument( + "unknown", + help="name of the exercise that appears on the issue title", + ), ) -> None: set_settings(Settings(_env_file=env_path)) set_logger(settings.stderr_log_level, diagnose=False, backtrace=False) @@ -355,6 +364,10 @@ def joj3_create_result_issue( "", help="gitea actions run number", ), + exercise_name: str = Argument( + "unknown", + help="name of the exercise that appears on the issue title", + ), ) -> None: set_settings(Settings(_env_file=env_path)) set_logger(settings.stderr_log_level, diagnose=False, backtrace=False) @@ -367,7 +380,7 @@ def joj3_create_result_issue( + f"actions/runs/{run_number}" ) title, comment = joj3.generate_title_and_comment( - score_file_path, actions_link, run_number + score_file_path, actions_link, run_number, exercise_name ) tea.pot.gitea.create_issue(submitter_repo_name, title, comment, False) diff --git a/joint_teapot/utils/joj3.py b/joint_teapot/utils/joj3.py index f08edfa..6c28d2f 100644 --- a/joint_teapot/utils/joj3.py +++ b/joint_teapot/utils/joj3.py @@ -9,7 +9,7 @@ def generate_scoreboard( - score_file_path: str, submitter: str, scoreboard_file_path: str + score_file_path: str, submitter: str, scoreboard_file_path: str, exercise_name: str ) -> None: if not scoreboard_file_path.endswith(".csv"): logger.error( @@ -50,12 +50,12 @@ def generate_scoreboard( with open(score_file_path) as json_file: stages: List[Dict[str, Any]] = json.load(json_file) - exercise_name = "unknown" - for stage in stages: - if stage["name"] != "metadata": - continue - comment = stage["results"][0]["comment"] - exercise_name = comment.split("-")[0] + if exercise_name == "unknown": + for stage in stages: + if stage["name"] != "metadata": + continue + comment = stage["results"][0]["comment"] + exercise_name = comment.split("-")[0] # Find if exercise in table: if exercise_name not in columns: column_tail = columns[3:] @@ -179,7 +179,7 @@ def generate_failed_table( def generate_title_and_comment( - score_file_path: str, action_link: str, run_number: str + score_file_path: str, action_link: str, run_number: str, exercise_name: str ) -> Tuple[str, str]: with open(score_file_path) as json_file: stages: List[Dict[str, Any]] = json.load(json_file) @@ -195,19 +195,17 @@ def generate_title_and_comment( force_quit = stage["force_quit"] if force_quit: comment += " - Failed" - single_case = len(stage["results"]) == 1 - if single_case: - comment += f" - Score: {stage['results'][0]['score']}" comment += "\n" for i, result in enumerate(stage["results"]): - if not single_case: - comment += f"### Case {i} - Score: {result['score']}\n" + comment += ( + f"
Case {i} - Score: {result['score']}\n" + ) if result["comment"].strip() != "": comment += f"{result['comment']}\n" total_score += result["score"] + comment += "
\n\n" comment += "\n" - now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") - title = f"JOJ3 Result {now} - Score: {total_score}" + title = f"JOJ3 Result for {exercise_name} - Score: {total_score}" return title, comment