From 1336c6f1f8a1da634186c8a5e4264d47b6b74eb8 Mon Sep 17 00:00:00 2001 From: BoYanZh Date: Thu, 19 Jun 2025 02:05:47 -0400 Subject: [PATCH] feat: joj3 create label when create issue --- joint_teapot/app.py | 10 ++++++++++ joint_teapot/teapot.py | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/joint_teapot/app.py b/joint_teapot/app.py index c2934b6..d81872f 100644 --- a/joint_teapot/app.py +++ b/joint_teapot/app.py @@ -299,6 +299,14 @@ def joj3_all_env( True, help="whether to include submitter in issue title", ), + issue_label_name: str = Option( + "Kind/Testing", + help="label name for the issue created by this command", + ), + issue_label_color: str = Option( + "#795548", + help="label color for the issue created by this command", + ), ) -> None: app.pretty_exceptions_enable = False set_settings(Settings(_env_file=env_path)) @@ -340,6 +348,8 @@ def joj3_all_env( gitea_actions_url, submitter_in_issue_title, submitter_repo_name, + issue_label_name, + issue_label_color, ) res["issue"] = issue_number gitea_issue_url = f"{submitter_repo_url}/issues/{issue_number}" diff --git a/joint_teapot/teapot.py b/joint_teapot/teapot.py index 9579b0c..a0b71be 100644 --- a/joint_teapot/teapot.py +++ b/joint_teapot/teapot.py @@ -238,6 +238,8 @@ class Teapot: gitea_actions_url: str, submitter_in_issue_title: bool, submitter_repo_name: str, + issue_label_name: str, + issue_label_color: str, ) -> int: title, comment = joj3.generate_title_and_comment( env.joj3_output_path, @@ -265,10 +267,25 @@ class Teapot: break else: new_issue = True + labels = self.gitea.issue_api.issue_list_labels( + self.gitea.org_name, submitter_repo_name + ) + label_id = 0 + for label in labels: + if label.name == issue_label_name: + label_id = label.id + break + else: + label = self.gitea.issue_api.issue_create_label( + self.gitea.org_name, + submitter_repo_name, + body={"name": issue_label_name, "color": issue_label_color}, + ) + label_id = label.id joj3_issue = self.gitea.issue_api.issue_create_issue( self.gitea.org_name, submitter_repo_name, - body={"title": title, "body": comment}, + body={"title": title, "body": comment, "labels": [label_id]}, ) logger.info(f"created joj3 issue: #{joj3_issue.number}") gitea_issue_url = joj3_issue.html_url