3636from tools import config
3737from tools .args import event_handler_parse
3838from tools .commands import EESSIBotCommand , EESSIBotCommandError , \
39- contains_any_bot_command , get_bot_command
39+ contains_any_bot_command , get_bot_command , get_supported_commands , ALL_COMMANDS
4040from tools .event_info import create_event_info_instance
41- from tools .git import connect_to_git_hosting_platform , get_git_hosting_platform
41+ from tools .git import connect_to_git_hosting_platform , get_app_name , get_git_hosting_platform
4242from tools .permissions import check_command_permission
4343from tools .pr_comments import ChatLevels , create_comment
4444
@@ -188,7 +188,7 @@ def handle_issue_comment_event(self, event_info, log_file=None):
188188 comments for any bot command and execute it if one is found.
189189
190190 Args:
191- event_info (dict ): event received by event_handler
191+ event_info (EventInfo ): event received by event_handler
192192 log_file (string): path to log messages to
193193
194194 Returns:
@@ -197,27 +197,26 @@ def handle_issue_comment_event(self, event_info, log_file=None):
197197 Raises:
198198 Exception: raises any exception that is not of type EESSIBotCommandError
199199 """
200- request_body = event_info ['raw_request_body' ]
201- issue_url = request_body ['issue' ]['url' ]
202- action = request_body ['action' ]
203- sender = request_body ['sender' ]['login' ]
204- owner = request_body ['comment' ]['user' ]['login' ]
205- repo_name = request_body ['repository' ]['full_name' ]
206- pr_number = request_body ['issue' ]['number' ]
200+ issue_url = event_info .issue_url
201+ action = event_info .action
202+ sender = event_info .event_triggered_by
203+ owner = event_info .comment_created_by
204+ repo_name = event_info .repo_name
205+ pr_number = event_info .issue_number
207206
208207 # TODO add request body text (['comment']['body']) to log message when
209208 # log level is set to debug
210209 self .log (f"Comment in { issue_url } (owned by @{ owner } ) { action } by @{ sender } " )
211210
212- app_name = self .cfg [ config . SECTION_GITHUB ][ config . GITHUB_SETTING_APP_NAME ]
211+ app_name = get_app_name ( self .cfg )
213212 command_response_fmt = self .cfg [config .SECTION_BOT_CONTROL ][config .BOT_CONTROL_SETTING_COMMAND_RESPONSE_FMT ]
214213
215214 # currently, only commands in new comments are supported
216215 # - commands have the syntax 'bot: COMMAND [ARGS*]'
217216
218217 # only scan for commands in newly created comments
219218 if action == 'created' :
220- comment_received = request_body [ 'comment' ][ 'body' ]
219+ comment_received = event_info . comment_body
221220 self .log (f"comment action '{ action } ' is handled" )
222221 else :
223222 # NOTE we do not respond to an updated PR comment with yet another
@@ -368,6 +367,9 @@ def handle_issue_comment_event(self, event_info, log_file=None):
368367
369368 self .log (f"issue_comment event (url { issue_url } ) handled!" )
370369
370+ # PyGHee gets the event type by subscripting event_info, i.e., it gets 'note' for GL comment events
371+ handle_note_event = handle_issue_comment_event
372+
371373 def handle_installation_event (self , event_info , log_file = None ):
372374 """
373375 Handle events of type installation. Main action is to log the event.
@@ -497,7 +499,7 @@ def handle_bot_command(self, event_info, bot_command, log_file=None):
497499 specific bot_command given.
498500
499501 Args:
500- event_info (dict ): event received by event_handler
502+ event_info (EventInfo ): event received by event_handler
501503 bot_command (EESSIBotCommand): command to be handled
502504 log_file (string): path to log messages to
503505
@@ -512,9 +514,13 @@ def handle_bot_command(self, event_info, bot_command, log_file=None):
512514 cmd = bot_command .command
513515 handler_name = f"handle_bot_command_{ cmd } "
514516 if hasattr (self , handler_name ):
515- handler = getattr (self , handler_name )
516- self .log (f"Handling bot command { cmd } " )
517- return handler (event_info , bot_command )
517+ if cmd in get_supported_commands (self .cfg ):
518+ handler = getattr (self , handler_name )
519+ self .log (f"Handling bot command { cmd } " )
520+ return handler (event_info , bot_command )
521+ else :
522+ self .log (f"Command '{ cmd } ' is not supported on the configured Git hosting platform." )
523+ raise EESSIBotCommandError (f"Unsupported command `{ cmd } `; use `bot: help` for usage information" )
518524 else :
519525 self .log (f"No handler for command '{ cmd } '" )
520526 raise EESSIBotCommandError (f"unknown command `{ cmd } `; use `bot: help` for usage information" )
@@ -525,17 +531,25 @@ def handle_bot_command_help(self, event_info, bot_command):
525531 commands.
526532
527533 Args:
528- event_info (dict ): event received by event_handler
534+ event_info (EventInfo ): event received by event_handler
529535 bot_command (EESSIBotCommand): command to be handled
530536
531537 Returns:
532538 (string): basic information about sending commands to the bot
533539 """
540+ # Create comma-separated lists of supported and unsupported commands
541+ supported_commands = get_supported_commands (self .cfg )
542+ unsupported_commands = [cmd for cmd in ALL_COMMANDS if cmd not in supported_commands ]
543+ supported_commands_str = ", " .join ([f"`{ cmd } `" for cmd in supported_commands ])
544+ unsupported_commands_str = ", " .join ([f"`{ cmd } `" for cmd in unsupported_commands ])
545+
534546 help_msg = "\n **How to send commands to bot instances**"
535547 help_msg += "\n - Commands must be sent with a **new** comment (edits of existing comments are ignored)."
536548 help_msg += "\n - A comment may contain multiple commands, one per line."
537549 help_msg += "\n - Every command begins at the start of a line and has the syntax `bot: COMMAND [ARGUMENTS]*`"
538- help_msg += "\n - Currently supported COMMANDs are: `help`, `build`, `show_config`, `status`, `cancel`"
550+ help_msg += "\n - Currently supported COMMANDs are: " + supported_commands_str
551+ if unsupported_commands_str :
552+ help_msg += "\n - The following COMMANDs are not yet supported: " + unsupported_commands_str
539553 help_msg += "\n "
540554 help_msg += "\n For more information, see https://www.eessi.io/docs/bot"
541555 return help_msg
@@ -572,7 +586,7 @@ def handle_bot_command_build(self, event_info, bot_command):
572586 else :
573587 for job_id , issue_comment in submitted_jobs .items ():
574588 build_msg += f"\n - submitted job `{ job_id } `"
575- if issue_comment :
589+ if issue_comment and issue_comment . html_url :
576590 build_msg += f", for details & status see { issue_comment .html_url } "
577591 else :
578592 request_body = event_info ['raw_request_body' ]
0 commit comments