From 9b078920877c83f006d551ca00110ee9435b11a7 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 20 Aug 2023 16:19:34 -0400 Subject: [PATCH] feat(issues): added support for labels --- issues/modals.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/issues/modals.py b/issues/modals.py index 6b59a9e..954e667 100644 --- a/issues/modals.py +++ b/issues/modals.py @@ -275,10 +275,16 @@ class IssueResponseModal(discord.ui.Modal, title="Sending response message..."): if embed.author.name == "Bot Bug Report": issue_title = f"[BOT BUG] {_issue_title}" + desired_labels = ["bot", "bug"] elif embed.author.name == "Bot Suggestion": issue_title = f"[BOT SUGGESTION] {_issue_title}" - elif embed.author.name == "Cog Bug Report" or embed.author.name == "Cog Suggestion": + desired_labels = ["bot", "enhancement"] + elif embed.author.name == "Cog Bug Report": issue_title = f"[{field_values[0]}] {_issue_title}" + desired_labels = ["cog", "bug"] + elif embed.author.name == "Cog Suggestion": + issue_title = f"[{field_values[0]}] {_issue_title}" + desired_labels = ["cog", "enhancement"] headers = { "Authorization": f"Bearer {await self.config.gitea_token()}", @@ -291,7 +297,23 @@ class IssueResponseModal(discord.ui.Modal, title="Sending response message..."): [f"{name}\n{value}" for name, value in zip(field_names, field_values)] ) - issue_data = {"title": issue_title, "body": issue_body} + async def fetch_labels(): + async with aiohttp.ClientSession(headers=headers) as session: + async with session.post(url=f"{await self.config.gitea_root_url()}/api/v1/repos/{await self.config.gitea_repository_owner()}/{await self.config.gitea_repository()}/labels") as response: + label_list = [] + for label in response.json(): + if label["name"] in desired_labels: + label_list.append(label["id"]) + if label_list is None: + print("Error! Labels are not properly configured on the target repository.") + return await label_list, response.status + + issue_labels = fetch_labels() + + if issue_labels is None: + issue_data = {"title": issue_title, "body": issue_body} + else: + issue_data = {"title": issue_title, "body": issue_body, "labels": issue_labels} async def create_issue(): async with aiohttp.ClientSession(headers=headers) as session: