From 26e4d36714c83c7774bd74428980054db1c30d5f Mon Sep 17 00:00:00 2001 From: Paul Philion Date: Wed, 25 Sep 2024 12:16:27 -0700 Subject: [PATCH] updating docs, tweaking code organization --- docs/devlog.md | 16 ++++++++++++++++ netbot/cog_scn.py | 9 +++++++-- netbot/cog_tickets.py | 16 ++++------------ netbot/netbot.py | 11 +++++++++++ 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/docs/devlog.md b/docs/devlog.md index 5106450..1140c41 100644 --- a/docs/devlog.md +++ b/docs/devlog.md @@ -4,6 +4,22 @@ Starting work on ticket 1207, to add admin overrides for all actions that default to self. +Added admin-specific params to allow member assignement for: +* collaborate +* progress +* assign + +Adding ticket ID autofill if in ticket thread: +* collaborate +* progress +* assign +* unassign +* resolve +* tracker +* priority +* subject + + ### 2024-09-05 *Haven't updated in a year. Sorry.* *I've got the notes, I just haven't put them here. I can if they are needed.* diff --git a/netbot/cog_scn.py b/netbot/cog_scn.py index fb62ec7..52ee140 100644 --- a/netbot/cog_scn.py +++ b/netbot/cog_scn.py @@ -4,12 +4,14 @@ import discord -from discord.commands import SlashCommandGroup +from discord.commands import option, SlashCommandGroup from discord.ext import commands +from discord.utils import basic_autocomplete from redmine.model import Message, User from redmine.redmine import Client, BLOCKED_TEAM_NAME +from netbot.netbot import default_ticket log = logging.getLogger(__name__) @@ -164,7 +166,10 @@ def is_admin(self, user: discord.Member) -> bool: return False - @scn.command() + # FIXME rename to "register"? + @scn.command(description="Add a Discord user to redmine") + @option("ticket_id", description="ticket ID", autocomplete=basic_autocomplete(default_ticket)) + @option("member", description="Discord member collaborating with ticket", optional=True) async def add(self, ctx:discord.ApplicationContext, redmine_login:str, member:discord.Member=None): """add a Discord user to the Redmine ticketing integration""" discord_name = ctx.user.name # by default, assume current user diff --git a/netbot/cog_tickets.py b/netbot/cog_tickets.py index bc0720c..31922b5 100644 --- a/netbot/cog_tickets.py +++ b/netbot/cog_tickets.py @@ -14,7 +14,7 @@ from discord.utils import basic_autocomplete from redmine.model import Message, Ticket from redmine.redmine import Client -from netbot.netbot import NetBot, TEAM_MAPPING, CHANNEL_MAPPING +from netbot.netbot import NetBot, TEAM_MAPPING, CHANNEL_MAPPING, default_ticket log = logging.getLogger(__name__) @@ -197,16 +197,6 @@ async def callback(self, interaction: discord.Interaction): await interaction.response.send_message(f"EditView.callback() {interaction.data}") -# WHERE SHOULD THIS GO? -# returns ticket id or none -def default_ticket(ctx: discord.AutocompleteContext) -> list[int]: - # examine the thread - ticket_id = ctx.bot.parse_thread_title(ctx.interaction.channel.name) - if ticket_id: - return [ticket_id] - else: - return [] - # distinct from above. takes app-context def default_term(ctx: discord.ApplicationContext) -> str: # examine the thread @@ -321,7 +311,7 @@ async def details(self, ctx: discord.ApplicationContext, ticket_id:int): @ticket.command(description="Collaborate on a ticket") @option("ticket_id", description="ticket ID", autocomplete=basic_autocomplete(default_ticket)) - @option("member", description="Discord member to collaborate", optional=True) + @option("member", description="Discord member collaborating with ticket", optional=True) async def collaborate(self, ctx: discord.ApplicationContext, ticket_id:int, member:discord.Member=None): """Add yourself as a collaborator on a ticket""" # lookup the user @@ -384,6 +374,7 @@ async def resolve(self, ctx: discord.ApplicationContext, ticket_id:int): @ticket.command(description="Mark a ticket in-progress") @option("ticket_id", description="ticket ID", autocomplete=basic_autocomplete(default_ticket)) + @option("member", description="Discord member taking ownership", optional=True) async def progress(self, ctx: discord.ApplicationContext, ticket_id:int, member:discord.Member=None): """Update status on a ticket, using: progress""" # lookup the user @@ -410,6 +401,7 @@ async def progress(self, ctx: discord.ApplicationContext, ticket_id:int, member: @ticket.command(description="Assign a ticket") @option("ticket_id", description="ticket ID", autocomplete=basic_autocomplete(default_ticket)) + @option("member", description="Discord member taking ownership", optional=True) async def assign(self, ctx: discord.ApplicationContext, ticket_id:int, member:discord.Member=None): # lookup the user user_name = ctx.user.name diff --git a/netbot/netbot.py b/netbot/netbot.py index 99a1a14..004fdd1 100755 --- a/netbot/netbot.py +++ b/netbot/netbot.py @@ -49,6 +49,17 @@ "uw-research-nsf": "research-team", } +# utility method to get a list of (one) ticket from the title of the channel, or empty list +# TODO could be moved to NetBot +def default_ticket(ctx: discord.AutocompleteContext) -> list[int]: + # examine the thread + ticket_id = ctx.bot.parse_thread_title(ctx.interaction.channel.name) + if ticket_id: + return [ticket_id] + else: + return [] + + class NetbotException(Exception): """netbot exception"""