-
Notifications
You must be signed in to change notification settings - Fork 2
fix: resolve issue #290 - Reduce Bert-e's verbosity by updating comment #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| from types import SimpleNamespace | ||
|
|
||
| import pytest | ||
|
|
||
| from bert_e import exceptions | ||
| from bert_e.workflow import pr_utils | ||
|
|
||
|
|
||
| class FakeComment: | ||
| def __init__(self, author, text, can_update=True): | ||
| self.author = author | ||
| self.text = text | ||
| self.can_update = can_update | ||
|
|
||
| def edit(self, text): | ||
| if not self.can_update: | ||
| raise NotImplementedError | ||
| self.text = text | ||
|
|
||
|
|
||
| class FakePR: | ||
| def __init__(self, can_update=True): | ||
| self.comments = [] | ||
| self.can_update = can_update | ||
|
|
||
| def add_comment(self, msg): | ||
| self.comments.append(FakeComment('bert-e', msg, self.can_update)) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def settings(): | ||
| return SimpleNamespace(no_comment=False, interactive=False, | ||
| robot='bert-e') | ||
|
|
||
|
|
||
| def send(settings, pr, msg, update=True): | ||
| pr_utils._send_comment(settings, pr, msg, 0, update) | ||
|
|
||
|
|
||
| def test_status_comment_is_updated_in_place(settings): | ||
| pr = FakePR() | ||
| send(settings, pr, 'history conflict') | ||
| send(settings, pr, 'reset complete') | ||
| assert len(pr.comments) == 1 | ||
| assert pr.comments[0].text.endswith('reset complete') | ||
| assert pr.comments[0].text.startswith(pr_utils.STATUS_MARKER) | ||
|
|
||
|
|
||
| def test_status_comment_updated_even_after_other_comments(settings): | ||
| pr = FakePR() | ||
| send(settings, pr, 'status 1') | ||
| pr.comments.append(FakeComment('bert-e', 'approved')) | ||
| send(settings, pr, 'status 2') | ||
| assert len(pr.comments) == 2 | ||
| assert pr.comments[0].text.endswith('status 2') | ||
|
|
||
|
|
||
| def test_identical_status_raises(settings): | ||
| pr = FakePR() | ||
| send(settings, pr, 'same') | ||
| with pytest.raises(exceptions.CommentAlreadyExists): | ||
| send(settings, pr, 'same') | ||
|
|
||
|
|
||
| def test_other_authors_comments_are_not_edited(settings): | ||
| pr = FakePR() | ||
| pr.comments.append( | ||
| FakeComment('someone', pr_utils.STATUS_MARKER + '\nfoo')) | ||
| send(settings, pr, 'status') | ||
| assert len(pr.comments) == 2 | ||
| assert pr.comments[0].text.endswith('foo') | ||
|
|
||
|
|
||
| def test_regular_comments_are_not_updated(settings): | ||
| pr = FakePR() | ||
| send(settings, pr, 'a', update=False) | ||
| send(settings, pr, 'b', update=False) | ||
| assert [c.text for c in pr.comments] == ['a', 'b'] | ||
|
|
||
|
|
||
| def test_fallback_when_host_cannot_edit(settings): | ||
| pr = FakePR(can_update=False) | ||
| send(settings, pr, 'a') | ||
| send(settings, pr, 'b') | ||
| assert len(pr.comments) == 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from unittest import mock | ||
|
|
||
| from bert_e.git_host.github import Client, Comment | ||
|
|
||
|
|
||
| def test_client_patch_uses_http_patch(): | ||
| client = Client.__new__(Client) | ||
| client.session = mock.Mock() | ||
| client.session.patch.return_value.text = '{}' | ||
| client._patch_url = lambda url: url | ||
| client.patch('https://api.github.com/c/1', data='{}') | ||
| client.session.patch.assert_called_once() | ||
| client.session.post.assert_not_called() | ||
|
|
||
|
|
||
| def test_comment_edit_sends_patch_and_refreshes_data(): | ||
| client = mock.Mock() | ||
| client.patch.return_value = { | ||
| 'id': 1, 'url': 'https://api.github.com/c/1', 'body': 'new', | ||
| 'user': {'login': 'bert-e', 'id': 1}, | ||
| 'created_at': '2020-01-01T00:00:00Z'} | ||
| comment = Comment(client, _validate=False, id=1, | ||
| url='https://api.github.com/c/1', body='old', | ||
| user={'login': 'bert-e', 'id': 1}, | ||
| created_at='2020-01-01T00:00:00Z') | ||
| comment.edit('new') | ||
| assert client.patch.call_args[0][0] == 'https://api.github.com/c/1' | ||
| assert comment.text == 'new' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
UPDATE_SCHEMAon theCommentclass —edit()callstype(self).update(), which falls back tocls.SCHEMA(schema.Commentwithid = fields.Int(required=True)) for serializing the outgoing payload. This works today only becausedumps()uses marshmallow 3'svalidate()which returns an errors dict rather than raisingValidationError, making the try/except dead code. If that validation is ever tightened,edit()will break. AddUPDATE_SCHEMA = schema.CreateCommentto theCommentclass.— Claude Code