From 47844b47d39b0fb6215edfbfe343d35e521697a1 Mon Sep 17 00:00:00 2001 From: Paul Philion Date: Mon, 30 Sep 2024 12:01:03 -0700 Subject: [PATCH] sub-ticket formatting step 1: strike out. DONE --- netbot/formatting.py | 101 ++++++++++++++++++------------------------ tests/test_tickets.py | 1 + 2 files changed, 45 insertions(+), 57 deletions(-) diff --git a/netbot/formatting.py b/netbot/formatting.py index 7f392d8..3344059 100644 --- a/netbot/formatting.py +++ b/netbot/formatting.py @@ -174,8 +174,13 @@ def format_ticket_row(self, ticket:Ticket) -> str: return f"`{link_padding}`{link}` {status} {priority} {age:<10} {assigned:<18} `{ticket.subject[:60]}" - def format_subticket(self, ticket:SubTicket) -> str: - return f"[{ticket.id}]({self.base_url}/issues/{ticket.id}) - {ticket.subject}" + def format_subticket(self, ticket:Ticket) -> str: + if ticket.status and ticket.status.is_closed: + # if the ticket is closed, remove the link and add strikeout + return f"~~{ticket.id} - {ticket.subject}~~" + else: + # TODO: What is the ticket thread in Discord? + return f"[{ticket.id}]({self.base_url}/issues/{ticket.id}) - {ticket.subject}" def format_discord_note(self, note) -> str: @@ -309,65 +314,47 @@ def ticket_embed(self, ctx: discord.ApplicationContext, ticket:Ticket) -> discor return embed - def epics_embed(self, ctx: discord.ApplicationContext, epics: dict[str,list[Ticket]]) -> list[discord.Embed]: + def epics_embed(self, ctx: discord.ApplicationContext, epics: list[Ticket]) -> list[discord.Embed]: """Build an array of embeds, one for each epic""" embeds = [] total_len = 0 - for _, tickets in epics.items(): - for epic in tickets: - title = f"{ get_emoji(epic.priority.name) } {epic.subject[:EMBED_TITLE_LEN-8]} (#{epic.id})" - embed = discord.Embed( - title=title, - description=epic.description[:EMBED_DESC_LEN], - color=discord.Color.blurple() # based on tracker? - ) - - # noting, assuming all these values are less than - if epic.assigned_to: - embed.add_field(name="Owner", value=self.get_user_id(ctx, epic)) - embed.add_field(name="Tracker", value=self.format_tracker(epic.tracker)) - embed.add_field(name="Age", value=epic.age_str) - embed.add_field(name="Redmine", value=self.format_link(epic)) - - if epic.children: - buff = "" - for child in epic.children: - buff += "- " + self.format_subticket(child) + "\n" - embed.add_field(name="", value=buff, inline=False) - - # truncing approach: - # 1 message, 10 embeds, 6000 chars max - # if the embed is > 600, clip the description so the overall length == 600 - # this effectively removes descriptions from epics with a lot of tickets. - # it also leaves a lot of wasted overhead, when the other embeds in the message - # are less than 600, about 10% on current samples. - embed_len = len(embed) - if embed_len > 600: # 6000/10 - overage = embed_len - 600 - embed.description = embed.description[:-overage] - #log.info(f"EMBED: orig={embed_len}, desc={len(embed.description)}, over={overage}") - - # add embed to the set - total_len += len(embed) - embeds.append(embed) - - # if total_len > EMBED_MAX_LEN: - # log.info(f"too-long epics: total={total_len}, max={EMBED_MAX_LEN}") - # adjusted_total = 0 - # over_count = 10 - under_count - # grace = under_total/over_count - - # for embed in embeds: - # embed_len = len(embed) - # overage = int(round(embed_len - (600 + grace))) - # if overage > 0: - # log.info(f"EMBED1: len={embed_len}, desc={len(embed.description)}, over={overage}") - # embed.description = embed.description[:-overage] - # log.info(f"EMBED2: len={embed_len}, desc={len(embed.description)}") - # adjusted_total += len(embed) - - #log.info(f"after adjust: total={total_len}") + for epic in epics: + title = f"{ get_emoji(epic.priority.name) } {epic.subject[:EMBED_TITLE_LEN-8]} (#{epic.id})" + embed = discord.Embed( + title=title, + description=epic.description[:EMBED_DESC_LEN], + color=discord.Color.blurple() # based on tracker? + ) + + # noting, assuming all these values are less than + if epic.assigned_to: + embed.add_field(name="Owner", value=self.get_user_id(ctx, epic)) + embed.add_field(name="Tracker", value=self.format_tracker(epic.tracker)) + embed.add_field(name="Age", value=epic.age_str) + embed.add_field(name="Redmine", value=self.format_link(epic)) + + if epic.children: + buff = "" + for child in epic.children: + buff += "- " + self.format_subticket(child) + "\n" + embed.add_field(name="", value=buff, inline=False) + + # truncing approach: + # 1 message, 10 embeds, 6000 chars max + # if the embed is > 600, clip the description so the overall length == 600 + # this effectively removes descriptions from epics with a lot of tickets. + # it also leaves a lot of wasted overhead, when the other embeds in the message + # are less than 600, about 10% on current samples. + embed_len = len(embed) + if embed_len > 600: # 6000/10 + overage = embed_len - 600 + embed.description = embed.description[:-overage] + #log.info(f"EMBED: orig={embed_len}, desc={len(embed.description)}, over={overage}") + + # add embed to the set + total_len += len(embed) + embeds.append(embed) return embeds diff --git a/tests/test_tickets.py b/tests/test_tickets.py index 9b11d36..654c6e5 100755 --- a/tests/test_tickets.py +++ b/tests/test_tickets.py @@ -148,6 +148,7 @@ def test_epics(self): self.assertEqual(10, len(check)) self.assertEqual(595, check[8].id) self.assertEqual(8, len(check[8].children)) + # check which are open vs closed. if __name__ == '__main__':