@@ -586,6 +586,34 @@ def handle_bot_command_status(self, event_info, bot_command):
586586 pr_number = event_info ['raw_request_body' ]['issue' ]['number' ]
587587 status_table = request_bot_build_issue_comments (repo_name , pr_number )
588588
589+
590+ # TODO: make the block until 'status_table = status_table_last' conditional on the bot command
591+ # If the bot command is something like 'bot:status=last', then we should execute this sorting block
592+ # First, add a timestamp for the date, so that we can use it for sorting
593+ dates = status_table ['date' ]
594+ timestamps = []
595+ for date in dates :
596+ date_object = datetime .datetime .strptime (date , "%b %d %X %Z %Y" )
597+ timestamps .append (int (date_object .timestamp ()))
598+ status_table ['timestamp' ] = timestamps
599+
600+ # Figure out the sorting indices, so that things are sorted first by the 'for arch', and then by 'date'
601+ sorted_indices = sorted (range (len (status_table ['for arch' ])), key = lambda x : (status_table ['for arch' [x ], status_table ['timestamp' ][x ]))
602+ # Reverse, so that the newest builds are first
603+ sorted_indices .reverse ()
604+ # Apply the sorted indices to get a sorted table
605+ sorted_table = {key : [status_table [key ][i ] for i in sorted_indices ] for key in status_table }
606+
607+ # Keep only the first entry for each 'for arch', as that is now the newest
608+ status_table_last = {'on arch' : [], 'for arch' : [], 'for repo' : [], 'date' : [], 'status' : [], 'url' : [], 'result' : []}
609+ for x in range (0 , len (status_table ['date' ])):
610+ if status_table ['for arch' ][x ] not in status_table_last ['for arch' ]:
611+ for key in status_table_last :
612+ status_table_last [key ].append (status_table [key ][x ])
613+
614+ # overwrite the original status_table
615+ status_table = status_table_last
616+
589617 comment_status = ''
590618 comment_status += "\n This is the status of all the `bot: build` commands:"
591619 comment_status += "\n |on|for|repo|result|date|status|url|"
0 commit comments