feat(issues): added support for labels
Some checks reported warnings
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
Seaswimmer 2023-08-20 16:19:34 -04:00
parent a8d873be33
commit 9b07892087
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -275,10 +275,16 @@ class IssueResponseModal(discord.ui.Modal, title="Sending response message..."):
if embed.author.name == "Bot Bug Report": if embed.author.name == "Bot Bug Report":
issue_title = f"[BOT BUG] {_issue_title}" issue_title = f"[BOT BUG] {_issue_title}"
desired_labels = ["bot", "bug"]
elif embed.author.name == "Bot Suggestion": elif embed.author.name == "Bot Suggestion":
issue_title = f"[BOT SUGGESTION] {_issue_title}" 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}" 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 = { headers = {
"Authorization": f"Bearer {await self.config.gitea_token()}", "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)] [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 def create_issue():
async with aiohttp.ClientSession(headers=headers) as session: async with aiohttp.ClientSession(headers=headers) as session: