diff --git a/mixins/github/epic.py b/mixins/github/epic.py index 4299337..668b8b4 100644 --- a/mixins/github/epic.py +++ b/mixins/github/epic.py @@ -36,27 +36,30 @@ def _process_epic_tasks(self, pull: PullRequest.PullRequest) -> List[Dict]: pull_number = pull.number link = pull.html_url author = pull.user.login - message = commit.commit.message + commit_message = commit.commit.message # Проверка на наличие ссылки на другой pull request в сообщении коммита - match = MERGE_PULL_REQUEST_PATTERN.search(message) + match = MERGE_PULL_REQUEST_PATTERN.search(commit_message) if match: pull_number = int(match.group(1)) pull_request = self.repo.get_pull(number=pull_number) # type: ignore[attr-defined] link = pull_request.html_url - - # Определение автора pull request, связанного с коммитом - cur_pulls = commit.get_pulls() - for cur_pull in cur_pulls: - if cur_pull.number == pull.number: - author = cur_pull.user.login - break + author = pull_request.user.login + else: + # Определение автора pull request, связанного с коммитом + cur_pulls = commit.get_pulls() + for cur_pull in cur_pulls: + if cur_pull.number == pull.number: + author = cur_pull.user.login + break # Извлечение ключей задач из сообщения коммита - all_matches = self.extract_task_keys(message, TASK_KEY_PATTERN) # type: ignore[attr-defined] + all_matches = self.extract_task_keys(commit_message, TASK_KEY_PATTERN) # type: ignore[attr-defined] if all_matches: epic_tasks.extend( - self.create_epic_task(pull_number, task_key, message, author, link) + self.create_epic_task( + pull_number, task_key, commit_message, author, link + ) for task_key in all_matches ) else: @@ -64,7 +67,7 @@ def _process_epic_tasks(self, pull: PullRequest.PullRequest) -> List[Dict]: self.create_epic_task( pull_number=pull_number, task_key=None, - message=message, + message=commit_message, author=author, link=link, ) diff --git a/requirements.txt b/requirements.txt index 251b365..04688cd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -requests==2.32.3 +requests==2.32.4 environs==14.1.1 PyGithub==2.6.1 diff --git a/tests/base_test.py b/tests/base_test.py index 6440bcb..252b14d 100644 --- a/tests/base_test.py +++ b/tests/base_test.py @@ -37,6 +37,8 @@ def prepare_github_service(self, mock_github): # Создаем мок репозитория и Pull Request mock_repo = MagicMock() mock_pull_request = MagicMock() + mock_pull_request_user = MagicMock(login="user") + mock_pull_request.author = mock_pull_request_user # Настраиваем возвращаемые значения для методов mock_repo.get_pull.return_value = mock_pull_request diff --git a/tests/test_epic_tasks.py b/tests/test_epic_tasks.py index 61b7d00..7b1177a 100644 --- a/tests/test_epic_tasks.py +++ b/tests/test_epic_tasks.py @@ -39,7 +39,11 @@ def test_epic_tasks(self, mock_github): github_service.main_commits.append(mock_commit) mock_repo.get_pull = MagicMock( - return_value=MagicMock(html_url=LINK_EXAMPLE, number=5) + return_value=MagicMock( + html_url=LINK_EXAMPLE, + number=5, + user=MagicMock(login="user_from_nested_pr"), + ) ) description_parts = github_service.build_description_parts() @@ -49,8 +53,8 @@ def test_epic_tasks(self, mock_github): "* [[ERP-4](https://tracker.yandex.ru/ERP-4)] ERP-4 by @user in [#4](https://link.com)", ( f"\n {EPIC_TITLE_NAME}: 1\n* " - "[[ERP-5](https://tracker.yandex.ru/ERP-5)] ERP-5 by @user in [#5](https://link.com)\n* " - "[[ERP-6](https://tracker.yandex.ru/ERP-6)] ERP-6 by @user in [#5](https://link.com)" + "[[ERP-5](https://tracker.yandex.ru/ERP-5)] ERP-5 by @user_from_nested_pr in [#5](https://link.com)\n* " + "[[ERP-6](https://tracker.yandex.ru/ERP-6)] ERP-6 by @user_from_nested_pr in [#5](https://link.com)" ), ] self.assertEqual(description_parts, expected_parts)