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.2

#### Added

- Allow `metadata` to be sent in `automa.code.propose`

### 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.1"
version = "0.2.2"

authors = [{ name = "Automa, Inc.", email = "engineering@automa.app" }]
description = "Bot helpers for Automa"
Expand Down
7 changes: 6 additions & 1 deletion packages/bot/src/automa/bot/resources/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,12 @@ class CodeDownloadParams(TypedDict):

class CodeProposeParams(CodeDownloadParams):
proposal: NotRequired[Proposal]
metadata: NotRequired[Metadata]

class Proposal(TypedDict, total=False):
class Proposal(TypedDict):
title: NotRequired[str]
body: NotRequired[str]

# TODO: Add `extra_items=Any`
class Metadata(TypedDict):
cost: NotRequired[float]
79 changes: 79 additions & 0 deletions packages/bot/tests/resources/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,82 @@ def test_propose_with_added_files_using_add_all(fixture_tarfile, code_resource):
"Content-Type": "application/json",
},
)


def test_propose_with_proposal_properties(fixture_tarfile, code_resource):
test_download(fixture_tarfile, code_resource)

with open(f"{folder}/README.md", "w") as f:
f.write("Content\n")

# 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(
{
"proposal": {"title": "PR title", "body": "PR body"},
"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": {
"title": "PR title",
"body": "PR body",
"token": "ghijkl",
"diff": "diff --git a/README.md b/README.md\nindex e69de29..39c9f36 100644\n--- a/README.md\n+++ b/README.md\n@@ -0,0 +1 @@\n+Content\n",
},
},
headers={
"Accept": "application/json",
"Content-Type": "application/json",
},
)


def test_propose_with_metadata(fixture_tarfile, code_resource):
test_download(fixture_tarfile, code_resource)

with open(f"{folder}/README.md", "w") as f:
f.write("Content\n")

# 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"},
"metadata": {"cost": 0.1, "random": "yes"},
}
)

# 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/README.md b/README.md\nindex e69de29..39c9f36 100644\n--- a/README.md\n+++ b/README.md\n@@ -0,0 +1 @@\n+Content\n",
},
"metadata": {"cost": 0.1, "random": "yes"},
},
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.