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
6 changes: 6 additions & 0 deletions packages/bot/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

### Unreleased

### 0.2.3

#### Added

- Added more webhook events to `WebhookPayload` type

### 0.2.2

#### Added
Expand Down
2 changes: 1 addition & 1 deletion packages/bot/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "automa-bot"
version = "0.2.2"
version = "0.2.3"

authors = [{ name = "Sunkara, Inc.", email = "engineering@automa.app" }]
description = "Bot helpers for Automa"
Expand Down
39 changes: 37 additions & 2 deletions packages/bot/src/automa/bot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,53 @@
from ._client import AsyncAutoma, Automa
from ._types import Org, Repo, Task, TaskItem, WebhookEventType, WebhookPayload
from .resources import AsyncCodeResource, CodeFolder, CodeResource
from ._types import (
GenericTaskItem,
Org,
ProposalTaskItem,
Repo,
Task,
TaskForCode,
TaskItem,
WebhookEventType,
WebhookPayload,
WebhookProposalAcceptedData,
WebhookProposalAcceptedPayload,
WebhookProposalRejectedData,
WebhookProposalRejectedPayload,
WebhookTaskCreatedData,
WebhookTaskCreatedPayload,
)
from .resources import (
AsyncCodeResource,
CodeCleanupParams,
CodeDownloadParams,
CodeFolder,
CodeProposeParams,
CodeResource,
)

__all__ = [
"Automa",
"AsyncAutoma",
"AsyncCodeResource",
"CodeResource",
"CodeFolder",
"CodeCleanupParams",
"CodeDownloadParams",
"CodeProposeParams",
"ProposalTaskItem",
"GenericTaskItem",
"TaskItem",
"Task",
"TaskForCode",
"Repo",
"Org",
"WebhookEventType",
"WebhookTaskCreatedData",
"WebhookTaskCreatedPayload",
"WebhookProposalAcceptedData",
"WebhookProposalAcceptedPayload",
"WebhookProposalRejectedData",
"WebhookProposalRejectedPayload",
"WebhookPayload",
]

Expand Down
83 changes: 71 additions & 12 deletions packages/bot/src/automa/bot/_types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from enum import Enum
from typing import Any, Dict, Literal, Mapping, TypedDict, Union
from typing import Any, Dict, Literal, Mapping, NotRequired, TypedDict, Union

from httpx._types import QueryParamTypes, RequestExtensions

Expand Down Expand Up @@ -38,16 +38,41 @@ class RequestOptions(TypedDict, total=False):
stream: bool | None


class TaskItem(TypedDict):
class ProposalTaskItem(TypedDict):
id: int
type: Literal["origin", "message", "repo", "bot", "proposal", "activity"]
type: Literal["proposal"]
data: ProposalTaskItemData
bot_id: int
repo_id: int

class ProposalTaskItemData(TypedDict):
prId: int
prNumber: int
prTitle: str
prHead: str
prBase: str
prState: Literal["open", "closed"]
prMerged: bool


class GenericTaskItem(TypedDict):
id: int
type: Literal["origin", "message", "repo", "bot", "activity"]
data: Dict[str, Any]
bot_id: NotRequired[int]
repo_id: NotRequired[int]


TaskItem = Union[ProposalTaskItem, GenericTaskItem]


class Task(TypedDict):
id: int
token: str
title: str


class TaskForCode(Task):
token: str
items: list[TaskItem]


Expand All @@ -64,16 +89,50 @@ class Org(TypedDict):


class WebhookEventType(Enum):
TaskCreated = "task.created"
TASK_CREATED = "task.created"
PROPOSAL_ACCEPTED = "proposal.accepted"
PROPOSAL_REJECTED = "proposal.rejected"


class WebhookTaskCreatedData(TypedDict):
task: TaskForCode
repo: Repo
org: Org


class WebhookProposalClosedData(TypedDict):
proposal: ProposalTaskItem
task: Task
org: Org


class WebhookPayload(TypedDict):
WebhookProposalAcceptedData = WebhookProposalClosedData
WebhookProposalRejectedData = WebhookProposalClosedData


class WebhookTaskCreatedPayload(TypedDict):
id: str
timestamp: str
type: Literal[WebhookEventType.TASK_CREATED]
data: WebhookTaskCreatedData


class WebhookProposalAcceptedPayload(TypedDict):
id: str
timestamp: str
type: WebhookEventType
data: WebhookPayloadData
type: Literal[WebhookEventType.PROPOSAL_ACCEPTED]
data: WebhookProposalAcceptedData


class WebhookProposalRejectedPayload(TypedDict):
id: str
timestamp: str
type: Literal[WebhookEventType.PROPOSAL_REJECTED]
data: WebhookProposalRejectedData


class WebhookPayloadData(TypedDict):
task: Task
repo: Repo
org: Org
WebhookPayload = Union[
WebhookTaskCreatedPayload,
WebhookProposalAcceptedPayload,
WebhookProposalRejectedPayload,
]
6 changes: 6 additions & 0 deletions packages/bot/src/automa/bot/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from .code import (
AsyncCodeResource,
CodeCleanupParams,
CodeDownloadParams,
CodeFolder,
CodeProposeParams,
CodeResource,
)

__all__ = [
"AsyncCodeResource",
"CodeResource",
"CodeFolder",
"CodeCleanupParams",
"CodeDownloadParams",
"CodeProposeParams",
]
5 changes: 4 additions & 1 deletion packages/bot/src/automa/bot/resources/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"CodeResource",
"AsyncCodeResource",
"CodeFolder",
"CodeCleanupParams",
"CodeDownloadParams",
"CodeProposeParams",
]


Expand Down Expand Up @@ -241,6 +244,6 @@ class Proposal(TypedDict):
title: NotRequired[str]
body: NotRequired[str]

# TODO: Add `extra_items=Any`
# TODO: Add `extra_items=Any` (py 3.15)
class Metadata(TypedDict):
cost: NotRequired[float]
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.