Skip to content

Commit 4bd1d9a

Browse files
Move action handlers to hackbot api (#6802)
1 parent c64e128 commit 4bd1d9a

21 files changed

Lines changed: 88 additions & 73 deletions

libs/hackbot-runtime/pyproject.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@ dependencies = [
88
"httpx>=0.26.0",
99
"pydantic-settings>=2.1.0",
1010
"google-auth>=2.0.0",
11-
"async-lru>=2.0.0",
1211
"agent-tools",
13-
"lando-client",
1412
"phabricator-client",
15-
"testrail-client",
16-
"slack-sdk>=3.27.0",
17-
"sendgrid>=6.12.5",
18-
"markdown2>=2.4.0",
1913
"weave>=0.53.4"
2014
]
2115

@@ -28,9 +22,7 @@ phabricator = ["MozPhab==2.15.3"]
2822

2923
[tool.uv.sources]
3024
agent-tools = { workspace = true }
31-
lando-client = { workspace = true }
3225
phabricator-client = { workspace = true }
33-
testrail-client = { workspace = true }
3426

3527
[build-system]
3628
requires = ["hatchling"]

libs/hackbot-runtime/tests/test_testrail_action.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import pytest
22
from agent_tools.registry import ToolError
33
from hackbot_runtime.actions import ActionsRecorder, testrail
4-
from hackbot_runtime.actions.handlers import get_handler
5-
from hackbot_runtime.actions.handlers.testrail_handler import SubmitTestPlanHandler
64
from hackbot_runtime.actions.testrail import ACTION_TYPE
75

86

@@ -218,7 +216,3 @@ async def test_submit_test_plan_tool_rejects_not_run_results():
218216

219217
assert "invalid TestRail submission" in str(exc.value)
220218
assert recorder.actions == []
221-
222-
223-
def test_submit_test_plan_handler_is_registered():
224-
assert isinstance(get_handler(ACTION_TYPE), SubmitTestPlanHandler)

libs/hackbot-runtime/hackbot_runtime/actions/handlers/__init__.py renamed to services/hackbot-api/app/action_handlers/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"""Apply-side handlers for recorded actions."""
22

3-
from hackbot_runtime.actions.handlers.base import (
3+
from app.action_handlers.base import (
44
ActionHandler,
55
ActionResult,
66
ApplyContext,
77
)
8-
from hackbot_runtime.actions.handlers.bugzilla_handler import (
8+
from app.action_handlers.bugzilla_handler import (
99
merge_resolved,
1010
plan_coalesced_groups,
1111
)
12-
from hackbot_runtime.actions.handlers.registry import HANDLERS, get_handler
12+
from app.action_handlers.registry import HANDLERS, get_handler
1313

1414
__all__ = [
1515
"ActionHandler",

libs/hackbot-runtime/hackbot_runtime/actions/handlers/base.py renamed to services/hackbot-api/app/action_handlers/base.py

File renamed without changes.

libs/hackbot-runtime/hackbot_runtime/actions/handlers/bugzilla_handler.py renamed to services/hackbot-api/app/action_handlers/bugzilla_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import requests
1919

20-
from hackbot_runtime.actions.handlers.base import ActionResult, ApplyContext
20+
from app.action_handlers.base import ActionResult, ApplyContext
2121

2222
log = logging.getLogger(__name__)
2323

libs/hackbot-runtime/hackbot_runtime/actions/handlers/email_handler.py renamed to services/hackbot-api/app/action_handlers/email_handler.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@
2626
import os
2727
from typing import Any
2828

29-
from hackbot_runtime.actions.email import PATCH_PLACEHOLDER
30-
from hackbot_runtime.actions.handlers.base import ActionResult, ApplyContext
31-
from hackbot_runtime.changes import PATCH_ARTIFACT
29+
from app.action_handlers.base import ActionResult, ApplyContext
3230

3331
log = logging.getLogger(__name__)
3432

33+
# Artifact containing a run's source-code patch.
34+
_PATCH_ARTIFACT = "changes/changes.patch"
35+
36+
# Email-body token replaced with the source-code patch.
37+
PATCH_PLACEHOLDER = "{patch}"
38+
3539
# A diff long enough to bury the rest of the mail is cut off; the attachment,
3640
# when the caller asked for one, still carries every line.
3741
_MAX_PATCH_LINES = 400
@@ -56,7 +60,7 @@ async def _patch(ctx: ApplyContext) -> bytes | None:
5660
recipient the patch, not the whole notification.
5761
"""
5862
try:
59-
return await ctx.download_artifact(PATCH_ARTIFACT)
63+
return await ctx.download_artifact(_PATCH_ARTIFACT)
6064
except Exception:
6165
log.exception("Could not read the patch of run %s", ctx.run_id)
6266
return None
@@ -127,7 +131,7 @@ async def apply(self, params: dict[str, Any], ctx: ApplyContext) -> ActionResult
127131
message.add_attachment(
128132
Attachment(
129133
FileContent(base64.b64encode(patch).decode()),
130-
FileName(PATCH_ARTIFACT.rsplit("/", 1)[-1]),
134+
FileName(_PATCH_ARTIFACT.rsplit("/", 1)[-1]),
131135
disposition=Disposition("attachment"),
132136
)
133137
)

libs/hackbot-runtime/hackbot_runtime/actions/handlers/phabricator_handler.py renamed to services/hackbot-api/app/action_handlers/phabricator_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from async_lru import alru_cache
2828
from phabricator_client import PhabricatorClient
2929

30-
from hackbot_runtime.actions.handlers.base import ActionResult, ApplyContext
30+
from app.action_handlers.base import ActionResult, ApplyContext
3131

3232
log = logging.getLogger(__name__)
3333

libs/hackbot-runtime/hackbot_runtime/actions/handlers/registry.py renamed to services/hackbot-api/app/action_handlers/registry.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
from hackbot_runtime.actions.handlers.base import ActionHandler
2-
from hackbot_runtime.actions.handlers.bugzilla_handler import (
1+
from app.action_handlers.base import ActionHandler
2+
from app.action_handlers.bugzilla_handler import (
33
AddAttachmentHandler,
44
AddCommentHandler,
55
CreateBugHandler,
66
UpdateBugHandler,
77
)
8-
from hackbot_runtime.actions.handlers.email_handler import SendEmailHandler
9-
from hackbot_runtime.actions.handlers.phabricator_handler import (
8+
from app.action_handlers.email_handler import SendEmailHandler
9+
from app.action_handlers.phabricator_handler import (
1010
AddCommentHandler as PhabricatorAddCommentHandler,
1111
)
12-
from hackbot_runtime.actions.handlers.phabricator_handler import (
12+
from app.action_handlers.phabricator_handler import (
1313
SubmitPatchHandler,
1414
UpdatePatchHandler,
1515
)
16-
from hackbot_runtime.actions.handlers.slack_handler import PostMessageHandler
17-
from hackbot_runtime.actions.handlers.testrail_handler import SubmitTestPlanHandler
18-
from hackbot_runtime.actions.handlers.try_server_handler import PushHandler
16+
from app.action_handlers.slack_handler import PostMessageHandler
17+
from app.action_handlers.testrail_handler import SubmitTestPlanHandler
18+
from app.action_handlers.try_server_handler import PushHandler
19+
20+
# Actions that submit source changes to Phabricator.
21+
PATCH_ACTION_TYPES = frozenset({"phabricator.submit_patch", "phabricator.update_patch"})
1922

2023
# Maps a recorded action's dotted `type` to the handler that applies it.
2124
# Adding a new action type later is a one-line addition here — the dispatch

libs/hackbot-runtime/hackbot_runtime/actions/handlers/slack_handler.py renamed to services/hackbot-api/app/action_handlers/slack_handler.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313

1414
from slack_sdk import WebClient
1515

16-
from hackbot_runtime.actions.handlers.base import ActionResult, ApplyContext
17-
from hackbot_runtime.actions.slack import HACKBOT_UI_URL
16+
from app.action_handlers.base import ActionResult, ApplyContext
1817

1918
log = logging.getLogger(__name__)
2019

20+
_HACKBOT_UI_URL = "https://hackbot.moz.tools"
21+
2122
_TIMEOUT_SECONDS = 30
2223

2324

@@ -40,7 +41,7 @@ async def apply(self, params: dict[str, Any], ctx: ApplyContext) -> ActionResult
4041
"notification_type": "info",
4142
"source": {
4243
"ref_id": ctx.run_id,
43-
"ref_url": f"{HACKBOT_UI_URL}/runs/{ctx.run_id}",
44+
"ref_url": f"{_HACKBOT_UI_URL}/runs/{ctx.run_id}",
4445
},
4546
"context": {
4647
"agent": ctx.agent,

libs/hackbot-runtime/hackbot_runtime/actions/handlers/testrail_handler.py renamed to services/hackbot-api/app/action_handlers/testrail_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from testrail_client import TestRailClient
1111

12-
from hackbot_runtime.actions.handlers.base import ActionResult, ApplyContext
12+
from app.action_handlers.base import ActionResult, ApplyContext
1313

1414
log = logging.getLogger(__name__)
1515

0 commit comments

Comments
 (0)