@@ -592,6 +592,55 @@ def handle_bot_command_status(self, event_info, bot_command):
592592 pr_number = event_info ['raw_request_body' ]['issue' ]['number' ]
593593 status_table = request_bot_build_issue_comments (repo_name , pr_number )
594594
595+ if 'last_build' in bot_command .general_args :
596+ # If the bot command is something like 'bot:status =last_build', then only retain the last build for each
597+ # architecture in the status_table
598+ # To do this, we first insert a timestamp to facilitate sorting by time
599+ # Then, we obtain sorting indices that first sort by architecture, then by build time
600+ # Then, we reverse the sorting, so that the last build (highest timestamp) for each archictecture occurs
601+ # first.
602+ # Finally, we copy the table, but each time we encounter an entry for an architecture that we've already
603+ # copied, we ignore it, since - as a result of the sorting - the second entry is always older than the
604+ # first
605+ dates = status_table ['date' ]
606+ timestamps = []
607+ for date in dates :
608+ date_object = datetime .strptime (date , "%b %d %X %Z %Y" )
609+ timestamps .append (int (date_object .timestamp ()))
610+ status_table ['timestamp' ] = timestamps
611+
612+ # Figure out the sorting indices, so that things are sorted first by the 'for arch', and then by 'date'
613+ sorted_indices = sorted (
614+ range (len (status_table ['for arch' ])),
615+ key = lambda x : (status_table ['for arch' ][x ], status_table ['timestamp' ][x ])
616+ )
617+ # Reverse, so that the newest builds are first
618+ sorted_indices .reverse ()
619+ # Apply the sorted indices to get a sorted table
620+ sorted_table = {key : [status_table [key ][i ] for i in sorted_indices ] for key in status_table }
621+ self .log (f"Sorted status table: { sorted_table } " )
622+
623+ # Keep only the first entry for each 'for arch', as that is now the newest
624+ status_table_last = {
625+ 'on arch' : [], 'for arch' : [], 'for repo' : [], 'date' : [], 'status' : [], 'url' : [], 'result' : []
626+ }
627+ for x in range (0 , len (sorted_table ['date' ])):
628+ if sorted_table ['for arch' ][x ] not in status_table_last ['for arch' ]:
629+ self .log (f"arch: { sorted_table ['for arch' ][x ]} not yet in status_table_last" )
630+ for key in status_table_last :
631+ self .log (f"Adding to '{ key } ' and the value { sorted_table [key ][x ]} " )
632+ status_table_last [key ].append (sorted_table [key ][x ])
633+
634+ # Re-sort, now only on 'for arch', for nicer viewing
635+ sorted_indices = sorted (
636+ range (len (status_table_last ['for arch' ])),
637+ key = lambda x : status_table_last ['for arch' ][x ]
638+ )
639+ sorted_table_last = {key : [status_table_last [key ][i ] for i in sorted_indices ] for key in status_table_last }
640+
641+ # overwrite the original status_table
642+ status_table = sorted_table_last
643+
595644 comment_status = ''
596645 comment_status += "\n This is the status of all the `bot: build` commands:"
597646 comment_status += "\n |on|for|repo|result|date|status|url|"
0 commit comments