Skip to content
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

close issue when all tasklists is closed #66

Merged
merged 2 commits into from
Jan 17, 2024
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
4 changes: 4 additions & 0 deletions src/managers/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be careful with directly editing the issue state without notifying or checking permissions of the user. There might be circumstances where users would want to still have discussions after closing all tasks in the task list.

28 changes: 25 additions & 3 deletions tests/managers/test_issue.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest.mock import Mock, patch
from unittest.mock import Mock, call, patch

import pytest

Expand Down Expand Up @@ -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")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you add additional assertions to verify the parameters of the 'issue.edit' method call as well. This is needed to ensure that it is being invoked with expected values.