feat(issues): fixed configuration prompt
Some checks reported warnings
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
Seaswimmer 2023-08-19 17:42:10 -04:00
parent 1f26e32852
commit d4203cad9c
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -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,