(self, command, payload)
| 264 | raise ValueError(f"Unexpected event type {event}") |
| 265 | |
| 266 | def handle_issue_comment(self, command, payload): |
| 267 | repo = self.github.get_repo(payload['repository']['id'], lazy=True) |
| 268 | issue = repo.get_issue(payload['issue']['number']) |
| 269 | |
| 270 | try: |
| 271 | pull = issue.as_pull_request() |
| 272 | except github.GithubException: |
| 273 | return issue.create_comment( |
| 274 | "The comment bot only listens to pull request comments!" |
| 275 | ) |
| 276 | |
| 277 | comment = pull.get_issue_comment(payload['comment']['id']) |
| 278 | try: |
| 279 | # Only allow users of apache org to submit commands, for more see |
| 280 | # https://developer.github.com/v4/enum/commentauthorassociation/ |
| 281 | # Checking privileges here enables the bot to respond |
| 282 | # without relying on the handler. |
| 283 | allowed_roles = {'OWNER', 'MEMBER', 'COLLABORATOR'} |
| 284 | if payload['comment']['author_association'] not in allowed_roles: |
| 285 | raise EventError( |
| 286 | "Only contributors can submit requests to this bot. " |
| 287 | "Please ask someone from the community for help with " |
| 288 | "getting the first commit in." |
| 289 | ) |
| 290 | self.handler(command, issue=issue, pull_request=pull, |
| 291 | comment=comment) |
| 292 | except Exception as e: |
| 293 | logger.exception(e) |
| 294 | url = "{server}/{repo}/actions/runs/{run_id}".format( |
| 295 | server=os.environ["GITHUB_SERVER_URL"], |
| 296 | repo=os.environ["GITHUB_REPOSITORY"], |
| 297 | run_id=os.environ["GITHUB_RUN_ID"], |
| 298 | ) |
| 299 | pull.create_issue_comment( |
| 300 | f"```\n{e}\nThe Archery job run can be found at: {url}\n```") |
| 301 | comment.create_reaction('-1') |
| 302 | else: |
| 303 | comment.create_reaction('+1') |
| 304 | |
| 305 | def handle_review_comment(self, payload): |
| 306 | raise NotImplementedError() |
no test coverage detected