feat(issues): finished api integration with gitea
Some checks reported warnings
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
Seaswimmer 2023-08-19 17:27:30 -04:00
parent cfd5f7b19c
commit 4f90076c37
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -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)
if self.approved:
for field in embed.fields:
field_names.append(field.name)
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)