Skip to content

Commit

Permalink
Ticket 830: Add legend for priority and status icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Philion committed May 3, 2024
1 parent e250ac0 commit 87ef398
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,42 @@ async def print_ticket(self, ticket, ctx):
msg = msg[:MAX_MESSAGE_LEN]
await ctx.respond(msg)

def build_legend(self, tickets:list[Ticket]) -> dict[str,str]:
# builds an icon-based legend from the status and
# priorities of a list of tickets

legend = {}

# TODO: Ordering?
for ticket in tickets:
# track which symbols are used for status and priority
if ticket.status.name not in legend:
legend[ticket.status.name] = EMOJI[ticket.status.name]
if ticket.priority.name not in legend:
legend[ticket.priority.name] = EMOJI[ticket.priority.name]

return legend

def format_tickets(self, title:str, tickets:list[Ticket], max_len=MAX_MESSAGE_LEN) -> str:
if tickets is None:
return "No tickets found."

legend = self.build_legend(tickets)
legend_row = "` "
for name, icon in legend.items():
legend_row += icon + name + " "
legend_row = legend_row[:-1] + '`' # remove the last space

section = "**" + title + "**\n"
for ticket in tickets:
ticket_line = self.format_ticket_row(ticket)
if len(section) + len(ticket_line) + 1 < max_len:
if len(section) + len(ticket_line) + len(legend_row) + 1 < max_len:
# make sure the lenght is less that the max
section += ticket_line + "\n" # append each ticket
else:
break # max_len hit

section += legend_row # add the legend
return section.strip()


Expand Down

0 comments on commit 87ef398

Please sign in to comment.