Skip to content

Commit dcc9332

Browse files
committed
Allow metadata for code proposal
1 parent 50a2920 commit dcc9332

File tree

5 files changed

+93
-3
lines changed

5 files changed

+93
-3
lines changed

packages/bot/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
### Unreleased
44

5+
### 0.2.2
6+
7+
#### Added
8+
9+
- Allow `metadata` to be sent in `automa.code.propose`
10+
511
### 0.2.1
612

713
* 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.1"
3+
version = "0.2.2"
44

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

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,12 @@ class CodeDownloadParams(TypedDict):
235235

236236
class CodeProposeParams(CodeDownloadParams):
237237
proposal: NotRequired[Proposal]
238+
metadata: NotRequired[Metadata]
238239

239-
class Proposal(TypedDict, total=False):
240+
class Proposal(TypedDict):
240241
title: NotRequired[str]
241242
body: NotRequired[str]
243+
244+
# TODO: Add `extra_items=Any`
245+
class Metadata(TypedDict):
246+
cost: NotRequired[float]

packages/bot/tests/resources/test_code.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,82 @@ def test_propose_with_added_files_using_add_all(fixture_tarfile, code_resource):
491491
"Content-Type": "application/json",
492492
},
493493
)
494+
495+
496+
def test_propose_with_proposal_properties(fixture_tarfile, code_resource):
497+
test_download(fixture_tarfile, code_resource)
498+
499+
with open(f"{folder}/README.md", "w") as f:
500+
f.write("Content\n")
501+
502+
# Mock client response
503+
response_mock = MagicMock()
504+
response_mock.status_code = 204
505+
response_mock.is_error = False
506+
507+
code_resource._client._client.request.return_value = response_mock
508+
509+
code_resource.propose(
510+
{
511+
"proposal": {"title": "PR title", "body": "PR body"},
512+
"task": {"id": 28, "token": "abcdef"},
513+
}
514+
)
515+
516+
# Hits the API
517+
code_resource._client._client.request.assert_called_once_with(
518+
"post",
519+
"/code/propose",
520+
json={
521+
"task": {"id": 28, "token": "abcdef"},
522+
"proposal": {
523+
"title": "PR title",
524+
"body": "PR body",
525+
"token": "ghijkl",
526+
"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",
527+
},
528+
},
529+
headers={
530+
"Accept": "application/json",
531+
"Content-Type": "application/json",
532+
},
533+
)
534+
535+
536+
def test_propose_with_metadata(fixture_tarfile, code_resource):
537+
test_download(fixture_tarfile, code_resource)
538+
539+
with open(f"{folder}/README.md", "w") as f:
540+
f.write("Content\n")
541+
542+
# Mock client response
543+
response_mock = MagicMock()
544+
response_mock.status_code = 204
545+
response_mock.is_error = False
546+
547+
code_resource._client._client.request.return_value = response_mock
548+
549+
code_resource.propose(
550+
{
551+
"task": {"id": 28, "token": "abcdef"},
552+
"metadata": {"cost": 0.1, "random": "yes"},
553+
}
554+
)
555+
556+
# Hits the API
557+
code_resource._client._client.request.assert_called_once_with(
558+
"post",
559+
"/code/propose",
560+
json={
561+
"task": {"id": 28, "token": "abcdef"},
562+
"proposal": {
563+
"token": "ghijkl",
564+
"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",
565+
},
566+
"metadata": {"cost": 0.1, "random": "yes"},
567+
},
568+
headers={
569+
"Accept": "application/json",
570+
"Content-Type": "application/json",
571+
},
572+
)

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)