|
25 | 25 | # Local application imports (anything from EESSI/eessi-bot-software-layer) |
26 | 26 | from connections import github |
27 | 27 | import tasks.build as build |
28 | | -from tasks.build import check_build_permission, get_architecture_targets, get_repo_cfg, submit_build_jobs |
| 28 | +from tasks.build import check_build_permission, get_architecture_targets, get_repo_cfg, \ |
| 29 | + request_bot_build_issue_comments, submit_build_jobs |
29 | 30 | import tasks.deploy as deploy |
30 | 31 | from tasks.deploy import deploy_built_artefacts |
31 | 32 | from tools import config |
@@ -416,7 +417,7 @@ def handle_bot_command_help(self, event_info, bot_command): |
416 | 417 | help_msg += "\n - Commands must be sent with a **new** comment (edits of existing comments are ignored)." |
417 | 418 | help_msg += "\n - A comment may contain multiple commands, one per line." |
418 | 419 | help_msg += "\n - Every command begins at the start of a line and has the syntax `bot: COMMAND [ARGUMENTS]*`" |
419 | | - help_msg += "\n - Currently supported COMMANDs are: `help`, `build`, `show_config`" |
| 420 | + help_msg += "\n - Currently supported COMMANDs are: `help`, `build`, `show_config`, `status`" |
420 | 421 | help_msg += "\n" |
421 | 422 | help_msg += "\n For more information, see https://www.eessi.io/docs/bot" |
422 | 423 | return help_msg |
@@ -476,6 +477,42 @@ def handle_bot_command_show_config(self, event_info, bot_command): |
476 | 477 | issue_comment = self.handle_pull_request_opened_event(event_info, pr) |
477 | 478 | return f"\n - added comment {issue_comment.html_url} to show configuration" |
478 | 479 |
|
| 480 | + def handle_bot_command_status(self, event_info, bot_command): |
| 481 | + """ |
| 482 | + Handles bot command 'status' by querying the github API |
| 483 | + for the comments in a pr. |
| 484 | +
|
| 485 | + Args: |
| 486 | + event_info (dict): event received by event_handler |
| 487 | + bot_command (EESSIBotCommand): command to be handled |
| 488 | +
|
| 489 | + Returns: |
| 490 | + github.IssueComment.IssueComment (note, github refers to |
| 491 | + PyGithub, not the github from the internal connections module) |
| 492 | + """ |
| 493 | + self.log("processing bot command 'status'") |
| 494 | + gh = github.get_instance() |
| 495 | + repo_name = event_info['raw_request_body']['repository']['full_name'] |
| 496 | + pr_number = event_info['raw_request_body']['issue']['number'] |
| 497 | + status_table = request_bot_build_issue_comments(repo_name, pr_number) |
| 498 | + |
| 499 | + comment_status = '' |
| 500 | + comment_status += "\nThis is the status of all the `bot: build` commands:" |
| 501 | + comment_status += "\n|arch|result|date|status|url|" |
| 502 | + comment_status += "\n|----|------|----|------|---|" |
| 503 | + for x in range(0, len(status_table['date'])): |
| 504 | + comment_status += f"\n|{status_table['arch'][x]}|" |
| 505 | + comment_status += f"{status_table['result'][x]}|" |
| 506 | + comment_status += f"{status_table['date'][x]}|" |
| 507 | + comment_status += f"{status_table['status'][x]}|" |
| 508 | + comment_status += f"{status_table['url'][x]}|" |
| 509 | + |
| 510 | + self.log(f"Overview of finished builds: comment '{comment_status}'") |
| 511 | + repo = gh.get_repo(repo_name) |
| 512 | + pull_request = repo.get_pull(pr_number) |
| 513 | + issue_comment = pull_request.create_issue_comment(comment_status) |
| 514 | + return issue_comment |
| 515 | + |
479 | 516 | def start(self, app, port=3000): |
480 | 517 | """ |
481 | 518 | Logs startup information to shell and log file and starts the app using |
|
0 commit comments