Skip to content

Commit

Permalink
Merge pull request #25 from Local-Connectivity-Lab/ticket-1037
Browse files Browse the repository at this point in the history
initial implementation of epic command
  • Loading branch information
philion authored Jul 27, 2024
2 parents f44aa53 + cfcccbd commit a29aada
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
10 changes: 9 additions & 1 deletion cog_scn.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ async def teams(self, ctx:discord.ApplicationContext, teamname:str=None):
if teamname:
team = self.redmine.get_team(teamname)
if team:
#await self.print_team(ctx, team)
await ctx.respond(self.format_team(team))
else:
await ctx.respond(f"Unknown team name: {teamname}") # error
Expand All @@ -195,6 +194,15 @@ async def teams(self, ctx:discord.ApplicationContext, teamname:str=None):
await ctx.respond(buff[:2000]) # truncate!


@scn.command(description="list all open epics")
async def epics(self, ctx:discord.ApplicationContext):
"""List all the epics, grouped by tracker"""
# get the epics.
epics = self.redmine.ticket_mgr.get_epics()
# format the epics and respond
msg = self.bot.formatter.format_epics(epics)
await ctx.respond(msg)

@scn.command(description="list blocked email")
async def blocked(self, ctx:discord.ApplicationContext):
team = self.redmine.get_team(BLOCKED_TEAM_NAME)
Expand Down
15 changes: 15 additions & 0 deletions formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'High': '🔼',
'Urgent': '⚠️',
'Immediate': '❗',
'EPIC': '🎇',
}

class DiscordFormatter():
Expand Down Expand Up @@ -176,6 +177,20 @@ def format_ticket_alert(self, ticket: Ticket, discord_ids: list[str], msg: str):
return f"ALERT #{self.format_link(ticket)} {' '.join(ids_str)}: {msg}"


def format_epic(self, name: str, epic: list[Ticket]) -> str:
buff = f"**{name}**\n"
for ticket in epic:
buff += self.format_ticket_row(ticket)
return buff


def format_epics(self, epics: dict[str,list[Ticket]]) -> str:
buff = ""
for name, epic in epics.items():
buff += self.format_epic(name, epic) + '\n'
return buff[:MAX_MESSAGE_LEN] # truncate!


def main():
ticket_manager = TicketManager(RedmineSession.fromenvfile(), "1")

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ frozenlist==1.4.0
humanize==4.8.0
idna==3.4
IMAPClient==3.0.0
install==1.3.5
isort==5.13.2
markdown-it-py==3.0.0
mccabe==0.7.0
Expand Down
24 changes: 24 additions & 0 deletions tickets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
"""redmine ticket handling"""

from collections import defaultdict
import datetime as dt
import logging
import re
Expand Down Expand Up @@ -213,6 +214,29 @@ def get_tickets(self, ticket_ids: list[int]) -> list[Ticket]:
log.info(f"Unknown ticket numbers: {ticket_ids}")
return []

def get_epics(self) -> dict[str, list[Ticket]]:
"""Get all the open epics, organized by tracker"""
# query tickets pri = epic
# http://localhost/issues.json?priority_id=14
epic_priority_id = 14 # fixme - lookup based on "EPIC", from redmine.get_priorities()
response = self.session.get(f"/issues.json?priority_id={epic_priority_id}&limit=100")
if not response:
return None

epics = defaultdict(list)
result = TicketsResult(**response)
if result.total_count > 0:
# iterate to slot by tracker
for epic in result.issues:
tracker_name = epic.tracker.name
if tracker_name not in epics.keys():
# create the tracker list
epics[tracker_name] = [epic]
else:
epics[tracker_name].append(epic)

return epics


def expire(self, ticket:Ticket):
"""Expire a ticket:
Expand Down

0 comments on commit a29aada

Please sign in to comment.