From d4203cad9cddefd8ff1463982cdb1f63f27433ab Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sat, 19 Aug 2023 17:42:10 -0400 Subject: [PATCH] feat(issues): fixed configuration prompt --- issues/issues.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/issues/issues.py b/issues/issues.py index b622b87..ddea316 100644 --- a/issues/issues.py +++ b/issues/issues.py @@ -14,7 +14,9 @@ class Issues(commands.Cog): self.config = Config.get_conf(self, identifier=4285273314713, force_registration=True) self.config.register_global( request_channel = None, - gitea_repository_url = None, + gitea_root_url = None, + gitea_repository_owner = None, + gitea_repository = None, gitea_token = None ) @@ -151,24 +153,44 @@ class Issues(commands.Cog): self.config = config self.ctx = ctx - gitea_repository_url = discord.ui.TextInput( - label="Gitea Repository URL", - placeholder="https://try.gitea.io/owner/repository", + gitea_root_url = discord.ui.TextInput( + label="Gitea Root URL", + placeholder="https://try.gitea.io", style=discord.TextStyle.short, + required=False, + max_length=200 + ) + gitea_repository_owner = discord.ui.TextInput( + label="Gitea Repository Owner", + placeholder="foo", + style=discord.TextStyle.short, + required=False, + max_length=200 + ) + gitea_repository = discord.ui.TextInput( + label="Gitea Repository Name", + placeholder="bar", + style=discord.TextStyle.short, + required=False, max_length=200 ) gitea_token = discord.ui.TextInput( label="Gitea User Access Token", placeholder="Generate one from your user settings page.", style=discord.TextStyle.short, + required=False, max_length=200 ) async def on_submit(self, interaction: discord.Interaction): if self.gitea_token.value is not None: await self.config.gitea_token.set(self.gitea_token.value) - if self.gitea_repository_url.value is not None: - await self.config.gitea_repository_url.set(self.gitea_repository_url.value) + if self.gitea_root_url.value is not None: + await self.config.gitea_root_url.set(self.gitea_root_url.value) + if self.gitea_repository_owner.value is not None: + await self.config.gitea_repository_owner.set(self.gitea_repository_owner.value) + if self.gitea_repository.value is not None: + await self.config.gitea_repository.set(self.gitea_repository.value) await interaction.response.send_message(content="Configuration changed!") class IssueResponseButtons(discord.ui.View): @@ -233,7 +255,7 @@ class Issues(commands.Cog): "Authorization": f"Bearer {await self.config.gitea_token()}", "Accept": "application/json" } - url = await self.config.gitea_repository_url() + url = f"{await self.config.gitea_root_url()}/api/v1/repos/{await self.config.gitea_repository_owner()}/{await self.config.gitea_repository()}/issues" issue_body = "\n".join([f"{name}\n{value}" for name, value in zip(field_names, field_values)]) issue_data = { "title": issue_title,