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

### Unreleased

### 0.2.0
### 0.2.1

* Initial release
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.0"
version = "0.2.1"

authors = [{ name = "Automa, Inc.", email = "engineering@automa.app" }]
description = "Bot helpers for Automa"
Expand Down
7 changes: 7 additions & 0 deletions packages/bot/src/automa/bot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ._client import AsyncAutoma, Automa
from ._types import Org, Repo, Task, TaskItem, WebhookEventType, WebhookPayload
from .resources import AsyncCodeResource, CodeFolder, CodeResource

__all__ = [
Expand All @@ -7,6 +8,12 @@
"AsyncCodeResource",
"CodeResource",
"CodeFolder",
"TaskItem",
"Task",
"Repo",
"Org",
"WebhookEventType",
"WebhookPayload",
]

# Update the __module__ attribute for exported symbols so that
Expand Down
44 changes: 43 additions & 1 deletion packages/bot/src/automa/bot/_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

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

from httpx._types import QueryParamTypes, RequestExtensions

Expand Down Expand Up @@ -35,3 +36,44 @@ class RequestOptions(TypedDict, total=False):
params: QueryParamTypes | None
extensions: RequestExtensions | None
stream: bool | None


class TaskItem(TypedDict):
id: int
type: Literal["origin", "message", "repo", "bot", "proposal", "activity"]
data: Dict[str, Any]


class Task(TypedDict):
id: int
token: str
title: str
items: list[TaskItem]


class Repo(TypedDict):
id: int
name: str
is_private: bool


class Org(TypedDict):
id: int
name: str
provider_type: Literal["github", "gitlab"]


class WebhookEventType(Enum):
TaskCreated = "task.created"


class WebhookPayload(TypedDict):
id: str
timestamp: str
type: WebhookEventType
data: WebhookPayloadData

class WebhookPayloadData(TypedDict):
task: Task
repo: Repo
org: Org
20 changes: 18 additions & 2 deletions packages/bot/src/automa/bot/resources/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from .._resource import AsyncAPIResource, SyncAPIResource
from .._types import RequestOptions
from .shared.task import Task, TaskWithToken

__all__ = [
"CodeResource",
Expand Down Expand Up @@ -49,6 +48,14 @@ def add(self, paths: str | list[str]) -> None:
check=True,
)

def add_all(self) -> None:
"""Add all files to git repository"""
subprocess.run(
["git", "add", "-N", "."],
cwd=self.path,
check=True,
)


class BaseCodeResource:
def _path(self, task: Task) -> str:
Expand Down Expand Up @@ -210,6 +217,14 @@ async def propose(self, body: CodeProposeParams, *, options: RequestOptions = {}
)


class Task(TypedDict):
id: int


class TaskWithToken(Task):
token: str


class CodeCleanupParams(TypedDict):
task: Task

Expand All @@ -222,4 +237,5 @@ class CodeProposeParams(CodeDownloadParams):
proposal: NotRequired[Proposal]

class Proposal(TypedDict, total=False):
message: str
title: NotRequired[str]
body: NotRequired[str]
Empty file.
9 changes: 0 additions & 9 deletions packages/bot/src/automa/bot/resources/shared/task.py

This file was deleted.

35 changes: 35 additions & 0 deletions packages/bot/tests/resources/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,38 @@ def test_propose_with_added_files(fixture_tarfile, code_resource):
"Content-Type": "application/json",
},
)


def test_propose_with_added_files_using_add_all(fixture_tarfile, code_resource):
code_folder = test_download(fixture_tarfile, code_resource)

with open(f"{code_folder.path}/NEW.md", "w") as f:
f.write("Content\n")

code_folder.add_all()

# Mock client response
response_mock = MagicMock()
response_mock.status_code = 204
response_mock.is_error = False

code_resource._client._client.request.return_value = response_mock

code_resource.propose({"task": {"id": 28, "token": "abcdef"}})

# Hits the API
code_resource._client._client.request.assert_called_once_with(
"post",
"/code/propose",
json={
"task": {"id": 28, "token": "abcdef"},
"proposal": {
"token": "ghijkl",
"diff": "diff --git a/NEW.md b/NEW.md\nnew file mode 100644\nindex 0000000..39c9f36\n--- /dev/null\n+++ b/NEW.md\n@@ -0,0 +1 @@\n+Content\n",
},
},
headers={
"Accept": "application/json",
"Content-Type": "application/json",
},
)
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.