From 80dd84d3703bdf071eaefc34a436a10d4c6bf851 Mon Sep 17 00:00:00 2001 From: Heitor Polidoro Date: Wed, 17 Jan 2024 03:03:10 -0300 Subject: [PATCH 1/2] close issue --- src/managers/issue.py | 4 ++++ tests/managers/test_issue.py | 28 +++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/managers/issue.py b/src/managers/issue.py index 632d4e6..e37a6d7 100644 --- a/src/managers/issue.py +++ b/src/managers/issue.py @@ -24,7 +24,9 @@ def handle_tasklist(event: IssuesEvent): repository = event.repository issue = event.issue issue_body = issue.body + all_checked = [] for checked, task in get_tasklist(issue_body): + all_checked.append(checked) if task_issue := get_issue(gh, repository, task): handle_issue_state(checked, task_issue) @@ -47,3 +49,5 @@ def handle_tasklist(event: IssuesEvent): issue_body = issue_body.replace(task, issue_ref(created_issue)) if issue_body != issue.body: issue.edit(body=issue_body) + if all_checked and all(all_checked): + issue.edit(state="closed") diff --git a/tests/managers/test_issue.py b/tests/managers/test_issue.py index ebd11f8..a00d7ef 100644 --- a/tests/managers/test_issue.py +++ b/tests/managers/test_issue.py @@ -1,4 +1,4 @@ -from unittest.mock import Mock, patch +from unittest.mock import Mock, patch, call import pytest @@ -76,11 +76,33 @@ def test_handle_tasklist_with_repository_name_and_title( def test_handle_tasklist_with_issue_in_task_list(event, issue, repository): - issue.body = "- [x] #123" + issue.body = "- [ ] #123" repository.get_issue.return_value = issue with patch("src.managers.issue.handle_issue_state") as handle_issue_state: handle_tasklist(event) - handle_issue_state.assert_called_once_with(True, issue) + handle_issue_state.assert_called_once_with(False, issue) repository.get_issue.assert_called_once_with(123) repository.create_issue.assert_not_called() issue.edit.assert_not_called() + + +def test_handle_tasklist_when_not_all_tasks_are_done(event, issue, repository): + issue.body = "- [x] #123\r\n- [ ] #321" + repository.get_issue.return_value = issue + with patch("src.managers.issue.handle_issue_state") as handle_issue_state: + handle_tasklist(event) + handle_issue_state.assert_has_calls([call(True, issue), call(False, issue)]) + repository.get_issue.assert_has_calls([call(123), call(321)]) + repository.create_issue.assert_not_called() + issue.edit.assert_not_called() + + +def test_handle_tasklist_when_all_tasks_are_done(event, issue, repository): + issue.body = "- [x] #123\r\n- [x] #321" + repository.get_issue.return_value = issue + with patch("src.managers.issue.handle_issue_state") as handle_issue_state: + handle_tasklist(event) + handle_issue_state.assert_has_calls([call(True, issue), call(True, issue)]) + repository.get_issue.assert_has_calls([call(123), call(321)]) + repository.create_issue.assert_not_called() + issue.edit.assert_called_once_with(state="closed") From 2c87328ba83bf0eb3affcc9a03fed1b239d2877e Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Wed, 17 Jan 2024 06:03:31 +0000 Subject: [PATCH 2/2] style: format code with Black and isort This commit fixes the style issues introduced in 80dd84d according to the output from Black and isort. Details: https://github.com/heitorpolidoro/bartholomew-smith/pull/66 --- tests/managers/test_issue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/managers/test_issue.py b/tests/managers/test_issue.py index a00d7ef..e5d138c 100644 --- a/tests/managers/test_issue.py +++ b/tests/managers/test_issue.py @@ -1,4 +1,4 @@ -from unittest.mock import Mock, patch, call +from unittest.mock import Mock, call, patch import pytest