Skip to content

Commit

Permalink
updating docs, tweaking code organization
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Philion committed Sep 25, 2024
1 parent 4aabb9a commit 26e4d36
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
16 changes: 16 additions & 0 deletions docs/devlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down
9 changes: 7 additions & 2 deletions netbot/cog_scn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions netbot/cog_tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions netbot/netbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down

0 comments on commit 26e4d36

Please sign in to comment.