From 4f90076c372bd31645b19fc3e7910a91dad3fcb1 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sat, 19 Aug 2023 17:27:30 -0400 Subject: [PATCH] feat(issues): finished api integration with gitea --- issues/issues.py | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/issues/issues.py b/issues/issues.py index 9629fef..e60c14b 100644 --- a/issues/issues.py +++ b/issues/issues.py @@ -193,6 +193,7 @@ class Issues(commands.Cog): self.message_id = message_id self.user = user self.approved = approved + self.config = Config.get_conf(None, cog_name='Issues', identifier=4285273314713) response = discord.ui.TextInput( label="Response", @@ -210,15 +211,40 @@ class Issues(commands.Cog): if self.approved: embed.color = 1226519 embed.title = "Issue Request Approved" - await interaction.response.send_message(content="Issue request accepted.", ephemeral=True) + status = "accepted" else: embed.color = 15671552 embed.title = "Issue Request Denied" - await interaction.response.send_message(content="Issue request denied.", ephemeral=True) + status = "denied" + await interaction.response.send_message(content=f"Issue request {status}.") if self.response.value is not None: embed.add_field(name=f"Response from {interaction.user.name}", value=self.response.value, inline=False) - for field in embed.fields: - field_names.append(field.name) - field_values.append(field.value) + if self.approved: + for field in embed.fields: + field_names.append(f"**{field.name}**") + field_values.append(field.value) + if embed.footer.text == "Bot Bug Report": + issue_title = f"[BOT BUG] Automatically generated issue" + elif embed.footer.text == "Bot Suggestion": + issue_title = f"[BOT SUGGESTION] Automatically generated issue" + elif embed.footer.text == "Cog Bug Report" or embed.footer.text == "Cog Suggestion": + issue_title = f"[{field_values[0]}] Automatically generated issue" + headers = { + "Authorization": f"Bearer {await self.config.gitea_token()}", + "Accept": "application/json" + } + url = await self.config.gitea_repository_url() + issue_body = "\n".join([f"{name}\n{value}" for name, value in zip(field_names, field_values)]) + issue_data = { + "title": issue_title, + "body": issue_body + } + async def create_issue(): + async with aiohttp.ClientSession(headers=headers) as session: + async with session.post(url, json=issue_data) as response: + return await response.json(), response.status + response_json, status_code = await create_issue() + if status_code == 201: + await interaction.response.send_message(content=f"Issue request {status}.\n[Issue successfully created.]({response_json.get('html_url')})", ephemeral=True) await message.edit(embed=embed, view=None) await self.user.send(embed=embed)