diff --git a/eessi_bot_event_handler.py b/eessi_bot_event_handler.py index f13cabbe..106af283 100644 --- a/eessi_bot_event_handler.py +++ b/eessi_bot_event_handler.py @@ -26,7 +26,7 @@ from connections import github import tasks.build as build from tasks.build import check_build_permission, get_architecture_targets, get_repo_cfg, \ - submit_build_jobs, request_bot_build_issue_comments + srequest_bot_build_issue_comment, submit_build_jobs import tasks.deploy as deploy from tasks.deploy import deploy_built_artefacts from tools import config @@ -479,15 +479,16 @@ def handle_bot_command_show_config(self, event_info, bot_command): def handle_bot_command_status(self, event_info, bot_command): """ - Handles bot command 'status' by running the handler for events of - type pull_request with the action opened. + Handles bot command 'status' by querying the github API + for the comments in a pr. Args: event_info (dict): event received by event_handler bot_command (EESSIBotCommand): command to be handled Returns: - (string): table which collects the status of each target + github.IssueComment.IssueComment (note, github refers to + PyGithub, not the github from the internal connections module) """ self.log("processing bot command 'status'") gh = github.get_instance() @@ -506,7 +507,7 @@ def handle_bot_command_status(self, event_info, bot_command): comment_status += f"{status_table['status'][x]}|" comment_status += f"{status_table['url'][x]}|" - self.log(f"PR opened: comment '{comment_status}'") + self.log(f"Overview of finished builds: comment '{comment_status}'") repo = gh.get_repo(repo_name) pull_request = repo.get_pull(pr_number) issue_comment = pull_request.create_issue_comment(comment_status) diff --git a/tasks/build.py b/tasks/build.py index 818e62d0..8bd5e3f8 100644 --- a/tasks/build.py +++ b/tasks/build.py @@ -763,6 +763,17 @@ def check_build_permission(pr, event_info): def request_bot_build_issue_comments(repo_name, pr_number): + """ + Query the github API for the issue_comments in a pr. + + Archs: + repo_name (string): name of the repository (format USER_OR_ORGANISATION/REPOSITORY) + pr_number (int): number og the pr + + Returns: + status_table (dict): dictionary with 'arch', 'date', 'status', 'url' and 'result' + for all the finished builds; + """ status_table = {'arch': [], 'date': [], 'status': [], 'url': [], 'result': []} cfg = config.read_config() @@ -780,7 +791,7 @@ def request_bot_build_issue_comments(repo_name, pr_number): if config.read_config()["submitted_job_comments"]['initial_comment'][:20] in comment['body']: # get archictecture from comment['body'] - first_line = comment['body'][:comment['body'].find('/n')] + first_line = comment['body'].split('\n')[0] arch_map = get_architecture_targets(cfg) for arch in arch_map.keys(): target_arch = '/'.join(arch.split('/')[1:]) @@ -815,7 +826,7 @@ def request_bot_build_issue_comments(repo_name, pr_number): status_table['url'].append(comment['html_url']) if 'FAILURE' in row['comment']: status_table['result'].append(':cry: FAILURE') - elif 'SUCCES' in row['comment']: + elif 'SUCCESS' in value['comment']: status_table['result'].append(':grin: SUCCESS') elif 'UNKNOWN' in row['comment']: status_table['result'].append(':shrug: UNKNOWN')