import re
from octomachinery.app.server.runner import run as run_app
from octomachinery.routing import process_event_actions
from octomachinery.routing.decorators import process_webhook_payload
from octomachinery.runtime.context import RUNTIME_CONTEXT
class EyeingBot:
"""
A class representing a GitHub bot that reacts to comments on issues.
This bot, when mentioned in a comment on an issue, responds by
reacting to the comment with "eyes" and posting a response stating
it has read the issue.
"""
name = "eyeingbot"
@process_event_actions("issue_comment", {"created"})
@process_webhook_payload
async def on_comment(
self,
*,
action,
issue,
comment,
repository=None,
sender=None,
installation=None,
assignee=None,
changes=None,
organization=None,
):
"""
Asynchronously responds to comments on issues where the bot is mentioned.
This method is triggered when a comment is created on an issue. If the bot is
mentioned in the comment, it reacts to the comment with "eyes" and posts a
response stating it has read the issue.
"""
github_api = RUNTIME_CONTEXT.app_installation_client
if re.search(r"\@{}\b".format(self.name), comment["body"]):
comment_reactions_api_url = f"{comment['url']}/reactions"
await github_api.post(
comment_reactions_api_url,
preview_api_version="squirrel-girl",
data={"content": "eyes"},
)
issue_comments_api_url = f"{issue['url']}/comments"
await github_api.post(
issue_comments_api_url,
data={"body": "I have read the issue."},
)
bot = EyeingBot()
run_app(
name=bot.name,
version="0.0.1",
url="https://github.com/apps/eyeingbot",
)
2023-06-16T13:17:45.229604+00:00 heroku[web.1]: Starting process with command `python triage/eyeingbot.py`
2023-06-16T13:17:47.340600+00:00 app[web.1]: /app/.heroku/python/lib/python3.10/site-packages/envparse.py:195: UserWarning: Could not any envfile.
2023-06-16T13:17:47.340625+00:00 app[web.1]: warnings.warn('Could not any envfile.')
2023-06-16T13:17:47.441986+00:00 app[web.1]: INFO:octomachinery.app.server.machinery:Webhook secret is [NOT SET]: SIGNED WEBHOOKS WILL BE REJECTED
2023-06-16T13:17:47.842291+00:00 app[web.1]: INFO:octomachinery.app.server.machinery:Starting the following GitHub App:
2023-06-16T13:17:47.842746+00:00 app[web.1]: INFO:octomachinery.app.server.machinery:* app id: 337171
2023-06-16T13:17:47.842800+00:00 app[web.1]: INFO:octomachinery.app.server.machinery:* private key SHA-1 fingerprint: cc:d2:28:01:9f:62:7a:39:85:ee:36:cc:15:0c:be:37:18:0e:67:4b
2023-06-16T13:17:47.842840+00:00 app[web.1]: INFO:octomachinery.app.server.machinery:* user agent: eyeingbot/0.0.1 (+https://github.com/apps/eyeingbot)
2023-06-16T13:17:47.845414+00:00 app[web.1]: Traceback (most recent call last):
2023-06-16T13:17:47.845415+00:00 app[web.1]: File "/app/triage/eyeingbot.py", line 58, in <module>
2023-06-16T13:17:47.845475+00:00 app[web.1]: run_app(
2023-06-16T13:17:47.845476+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/octomachinery/app/server/runner.py", line 70, in run
2023-06-16T13:17:47.845512+00:00 app[web.1]: run_until_complete(run_server_forever, config, event_routers)
2023-06-16T13:17:47.845512+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/anyio/__init__.py", line 72, in run
2023-06-16T13:17:47.845555+00:00 app[web.1]: return asynclib.run(func, *args, **backend_options) # type: ignore
2023-06-16T13:17:47.845555+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 114, in run
2023-06-16T13:17:47.845592+00:00 app[web.1]: raise exception
2023-06-16T13:17:47.845592+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 76, in wrapper
2023-06-16T13:17:47.845622+00:00 app[web.1]: retval = await func(*args)
2023-06-16T13:17:47.845623+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/octomachinery/utils/asynctools.py", line 14, in async_func_wrapper
2023-06-16T13:17:47.845648+00:00 app[web.1]: return await async_func(*args, **kwargs)
2023-06-16T13:17:47.845648+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/octomachinery/app/server/machinery.py", line 134, in run_forever
2023-06-16T13:17:47.845684+00:00 app[web.1]: await _prepare_github_app(github_app)
2023-06-16T13:17:47.845684+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/octomachinery/app/server/machinery.py", line 64, in _prepare_github_app
2023-06-16T13:17:47.845713+00:00 app[web.1]: await github_app.log_installs_list()
2023-06-16T13:17:47.845713+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/octomachinery/github/api/app_client.py", line 71, in log_installs_list
2023-06-16T13:17:47.845744+00:00 app[web.1]: installations = await self.get_installations()
2023-06-16T13:17:47.845744+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/octomachinery/github/api/app_client.py", line 131, in get_installations
2023-06-16T13:17:47.845778+00:00 app[web.1]: async for install in amap(
2023-06-16T13:17:47.845779+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/octomachinery/utils/asynctools.py", line 81, in amap
2023-06-16T13:17:47.845808+00:00 app[web.1]: async for async_value in async_iterable:
2023-06-16T13:17:47.845808+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/octomachinery/github/api/utils.py", line 49, in async_generator_wrapper
2023-06-16T13:17:47.845836+00:00 app[web.1]: async for result_item in coroutine_instance:
2023-06-16T13:17:47.845836+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gidgethub/abc.py", line 185, in getiter
2023-06-16T13:17:47.845876+00:00 app[web.1]: data, more, _ = await self._make_request(
2023-06-16T13:17:47.845884+00:00 app[web.1]: TypeError: RawGitHubAPI._make_request() got an unexpected keyword argument 'extra_headers'