Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import pytz
import sentry_sdk
import tornado

from client_wrapper import ClientWrapper
from constants import (
Expand Down Expand Up @@ -131,7 +132,6 @@ def __init__(
npm_token,
timezone,
repos_info,
loop,
):
"""
Create the slack bot
Expand All @@ -143,15 +143,13 @@ def __init__(
npm_token (str): The NPM token to publish npm packages
timezone (tzinfo): The time zone of the team interacting with the bot
repos_info (list of RepoInfo): Information about the repositories connected to channels
loop (asyncio.events.AbstractEventLoop): The asyncio event loop
"""
self.doof_id = doof_id
self.slack_access_token = slack_access_token
self.github_access_token = github_access_token
self.npm_token = npm_token
self.timezone = timezone
self.repos_info = repos_info
self.loop = loop
# Keep track of long running or scheduled tasks
self.tasks = set()
self.doof_boot = now_in_utc()
Expand Down Expand Up @@ -1038,7 +1036,7 @@ async def start_new_releases(self, command_args): # pylint: disable=too-many-lo
title=f"Starting release {version} with these commits",
text=release_notes,
)
self.loop.create_task(
asyncio.create_task(
self._new_release(
repo_info=repo_info,
version=version,
Expand Down Expand Up @@ -1549,7 +1547,7 @@ async def startup(self):
if not release_pr:
continue

self.loop.create_task(
asyncio.create_task(
self.run_release_lifecycle(
repo_info=repo_info, manager=None, release_pr=release_pr
)
Expand Down Expand Up @@ -1640,7 +1638,6 @@ async def async_main():
npm_token=envs["NPM_TOKEN"],
timezone=pytz.timezone(envs["TIMEZONE"]),
repos_info=repos_info,
loop=asyncio.get_event_loop(),
doof_id=doof_id,
)
app = make_app(secret=envs["SLACK_SECRET"], bot=bot)
Expand All @@ -1651,9 +1648,7 @@ async def async_main():

def main():
"""main function for bot command"""
loop = asyncio.get_event_loop()
loop.run_until_complete(async_main())
loop.run_forever()
tornado.ioloop.IOLoop.current().run_sync(async_main)


if __name__ == "__main__":
Expand Down
4 changes: 1 addition & 3 deletions bot_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ async def async_main():
timezone=envs["TIMEZONE"],
npm_token=envs["NPM_TOKEN"],
repos_info=repos_info,
loop=asyncio.get_event_loop(),
)

await bot.startup()
Expand All @@ -63,8 +62,7 @@ async def async_main():

def main():
"""Main function"""
loop = asyncio.get_event_loop()
loop.run_until_complete(async_main())
asyncio.run(async_main())


if __name__ == "__main__":
Expand Down
7 changes: 3 additions & 4 deletions bot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
class DoofSpoof(Bot):
"""Testing bot"""

def __init__(self, *, loop):
def __init__(self):
"""Since the testing bot isn't contacting slack or github we don't need these tokens here"""
super().__init__(
doof_id="Doofenshmirtz",
Expand All @@ -59,7 +59,6 @@ def __init__(self, *, loop):
npm_token=NPM_TOKEN,
timezone=pytz.timezone("America/New_York"),
repos_info=[WEB_TEST_REPO_INFO, LIBRARY_TEST_REPO_INFO],
loop=loop,
)

self.slack_users = []
Expand Down Expand Up @@ -130,9 +129,9 @@ def sleep_sync_mock(mocker):


@pytest.fixture
def doof(event_loop, sleep_sync_mock): # pylint: disable=unused-argument
def doof(sleep_sync_mock): # pylint: disable=unused-argument
"""Create a Doof"""
yield DoofSpoof(loop=event_loop)
yield DoofSpoof()


@pytest.fixture
Expand Down
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
python-dateutil
pytz
requests
sentry-sdk
tornado
virtualenv
packaging
packaging==25.0
python-dateutil==2.9.0.post0
pytz==2025.2
requests==2.32.5
sentry-sdk==2.35.1
tornado==6.5.2
virtualenv==20.34.0
14 changes: 7 additions & 7 deletions test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
black==25.1.0
codecov
pdbpp
pylint
pytest
pytest-asyncio
pytest-cov
pytest-mock
codecov==2.1.13
pdbpp==0.11.7
pylint==3.3.8
pytest==8.4.1
pytest-asyncio==1.1.0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The version 1.1.0 for pytest-asyncio does not exist on PyPI. This will cause dependency installation to fail. It seems to be a typo. Please correct it to a valid version. The latest version is 0.23.7, which you could use if it's compatible with your setup.

pytest-asyncio==0.23.7

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytest-cov==6.2.1
pytest-mock==3.14.1
5 changes: 3 additions & 2 deletions web.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Web server for handling slack webhooks
"""

import asyncio
import hmac
import json

Expand Down Expand Up @@ -54,7 +55,7 @@ async def post(self, *args, **kwargs): # pylint: disable=unused-argument
arguments = json.loads(
self.get_argument("payload")
) # pylint: disable=no-value-for-parameter
self.bot.loop.create_task(self.bot.handle_webhook(webhook_dict=arguments))
asyncio.create_task(self.bot.handle_webhook(webhook_dict=arguments))
await self.finish("")


Expand Down Expand Up @@ -87,7 +88,7 @@ async def post(self, *args, **kwargs): # pylint: disable=unused-argument
await self.finish(challenge)
return

self.bot.loop.create_task(self.bot.handle_event(webhook_dict=arguments))
asyncio.create_task(self.bot.handle_event(webhook_dict=arguments))

await self.finish("")

Expand Down
4 changes: 1 addition & 3 deletions web_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Tests for the web server"""

import asyncio
import json
from unittest.mock import patch
import urllib.parse
Expand All @@ -21,8 +20,7 @@ class FinishReleaseTests(AsyncHTTPTestCase):

def setUp(self):
self.secret = uuid.uuid4().hex
self.loop = asyncio.get_event_loop()
self.doof = DoofSpoof(loop=self.loop)
self.doof = DoofSpoof()
self.app = make_app(secret=self.secret, bot=self.doof)

super().setUp()
Expand Down