|
31 | 31 | from tasks.deploy import deploy_built_artefacts |
32 | 32 | from tools import config |
33 | 33 | from tools.args import event_handler_parse |
34 | | -from tools.commands import EESSIBotCommand, EESSIBotCommandError, get_bot_command |
| 34 | +from tools.commands import EESSIBotCommand, EESSIBotCommandError, \ |
| 35 | + contains_any_bot_command, get_bot_command |
35 | 36 | from tools.permissions import check_command_permission |
36 | 37 | from tools.pr_comments import create_comment |
37 | 38 |
|
@@ -113,7 +114,25 @@ def handle_issue_comment_event(self, event_info, log_file=None): |
113 | 114 | # currently, only commands in new comments are supported |
114 | 115 | # - commands have the syntax 'bot: COMMAND [ARGS*]' |
115 | 116 |
|
116 | | - # first check if sender is authorized to send any command |
| 117 | + # only scan for commands in newly created comments |
| 118 | + if action == 'created': |
| 119 | + comment_received = request_body['comment']['body'] |
| 120 | + self.log(f"comment action '{action}' is handled") |
| 121 | + else: |
| 122 | + # NOTE we do not respond to an updated PR comment with yet another |
| 123 | + # new PR comment, because it would make the bot very noisy or |
| 124 | + # worse could result in letting the bot enter an endless loop |
| 125 | + self.log(f"comment action '{action}' not handled") |
| 126 | + return |
| 127 | + # at this point we know that we are handling a new comment |
| 128 | + |
| 129 | + # check if comment does not contain a bot command |
| 130 | + if not contains_any_bot_command(comment_received): |
| 131 | + self.log("comment does not contain a bot comment; not processing it further") |
| 132 | + return |
| 133 | + # at this point we know that the comment contains a bot command |
| 134 | + |
| 135 | + # check if sender is authorized to send any command |
117 | 136 | # - this serves a double purpose: |
118 | 137 | # 1. check permission |
119 | 138 | # 2. skip any comment updates that were done by the bot itself |
@@ -150,17 +169,6 @@ def handle_issue_comment_event(self, event_info, log_file=None): |
150 | 169 | else: |
151 | 170 | self.log(f"account `{sender}` has permission to send commands to bot") |
152 | 171 |
|
153 | | - # only scan for commands in newly created comments |
154 | | - if action == 'created': |
155 | | - comment_received = request_body['comment']['body'] |
156 | | - self.log(f"comment action '{action}' is handled") |
157 | | - else: |
158 | | - # NOTE we do not respond to an updated PR comment with yet another |
159 | | - # new PR comment, because it would make the bot very noisy or |
160 | | - # worse could result in letting the bot enter an endless loop |
161 | | - self.log(f"comment action '{action}' not handled") |
162 | | - return |
163 | | - |
164 | 172 | # search for commands in comment |
165 | 173 | comment_response = '' |
166 | 174 | commands = [] |
|
0 commit comments