Skip to content

Commit 50a2920

Browse files
authored
Merge pull request #13 from automa/pavan/jj/rxzlrouwzqsx
Update several things
2 parents 9cce767 + 15c3a8b commit 50a2920

File tree

9 files changed

+106
-15
lines changed

9 files changed

+106
-15
lines changed

packages/bot/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
### Unreleased
44

5-
### 0.2.0
5+
### 0.2.1
66

77
* Initial release

packages/bot/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "automa-bot"
3-
version = "0.2.0"
3+
version = "0.2.1"
44

55
authors = [{ name = "Automa, Inc.", email = "[email protected]" }]
66
description = "Bot helpers for Automa"

packages/bot/src/automa/bot/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from ._client import AsyncAutoma, Automa
2+
from ._types import Org, Repo, Task, TaskItem, WebhookEventType, WebhookPayload
23
from .resources import AsyncCodeResource, CodeFolder, CodeResource
34

45
__all__ = [
@@ -7,6 +8,12 @@
78
"AsyncCodeResource",
89
"CodeResource",
910
"CodeFolder",
11+
"TaskItem",
12+
"Task",
13+
"Repo",
14+
"Org",
15+
"WebhookEventType",
16+
"WebhookPayload",
1017
]
1118

1219
# Update the __module__ attribute for exported symbols so that

packages/bot/src/automa/bot/_types.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

3-
from typing import Any, Literal, Mapping, TypedDict, Union
3+
from enum import Enum
4+
from typing import Any, Dict, Literal, Mapping, TypedDict, Union
45

56
from httpx._types import QueryParamTypes, RequestExtensions
67

@@ -35,3 +36,44 @@ class RequestOptions(TypedDict, total=False):
3536
params: QueryParamTypes | None
3637
extensions: RequestExtensions | None
3738
stream: bool | None
39+
40+
41+
class TaskItem(TypedDict):
42+
id: int
43+
type: Literal["origin", "message", "repo", "bot", "proposal", "activity"]
44+
data: Dict[str, Any]
45+
46+
47+
class Task(TypedDict):
48+
id: int
49+
token: str
50+
title: str
51+
items: list[TaskItem]
52+
53+
54+
class Repo(TypedDict):
55+
id: int
56+
name: str
57+
is_private: bool
58+
59+
60+
class Org(TypedDict):
61+
id: int
62+
name: str
63+
provider_type: Literal["github", "gitlab"]
64+
65+
66+
class WebhookEventType(Enum):
67+
TaskCreated = "task.created"
68+
69+
70+
class WebhookPayload(TypedDict):
71+
id: str
72+
timestamp: str
73+
type: WebhookEventType
74+
data: WebhookPayloadData
75+
76+
class WebhookPayloadData(TypedDict):
77+
task: Task
78+
repo: Repo
79+
org: Org

packages/bot/src/automa/bot/resources/code.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from .._resource import AsyncAPIResource, SyncAPIResource
1313
from .._types import RequestOptions
14-
from .shared.task import Task, TaskWithToken
1514

1615
__all__ = [
1716
"CodeResource",
@@ -49,6 +48,14 @@ def add(self, paths: str | list[str]) -> None:
4948
check=True,
5049
)
5150

51+
def add_all(self) -> None:
52+
"""Add all files to git repository"""
53+
subprocess.run(
54+
["git", "add", "-N", "."],
55+
cwd=self.path,
56+
check=True,
57+
)
58+
5259

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

212219

220+
class Task(TypedDict):
221+
id: int
222+
223+
224+
class TaskWithToken(Task):
225+
token: str
226+
227+
213228
class CodeCleanupParams(TypedDict):
214229
task: Task
215230

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

224239
class Proposal(TypedDict, total=False):
225-
message: str
240+
title: NotRequired[str]
241+
body: NotRequired[str]

packages/bot/src/automa/bot/resources/shared/__init__.py

Whitespace-only changes.

packages/bot/src/automa/bot/resources/shared/task.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/bot/tests/resources/test_code.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,38 @@ def test_propose_with_added_files(fixture_tarfile, code_resource):
456456
"Content-Type": "application/json",
457457
},
458458
)
459+
460+
461+
def test_propose_with_added_files_using_add_all(fixture_tarfile, code_resource):
462+
code_folder = test_download(fixture_tarfile, code_resource)
463+
464+
with open(f"{code_folder.path}/NEW.md", "w") as f:
465+
f.write("Content\n")
466+
467+
code_folder.add_all()
468+
469+
# Mock client response
470+
response_mock = MagicMock()
471+
response_mock.status_code = 204
472+
response_mock.is_error = False
473+
474+
code_resource._client._client.request.return_value = response_mock
475+
476+
code_resource.propose({"task": {"id": 28, "token": "abcdef"}})
477+
478+
# Hits the API
479+
code_resource._client._client.request.assert_called_once_with(
480+
"post",
481+
"/code/propose",
482+
json={
483+
"task": {"id": 28, "token": "abcdef"},
484+
"proposal": {
485+
"token": "ghijkl",
486+
"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",
487+
},
488+
},
489+
headers={
490+
"Accept": "application/json",
491+
"Content-Type": "application/json",
492+
},
493+
)

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)