From 828d4bd2870ffe859becf6b5747878abe6aa36bd Mon Sep 17 00:00:00 2001 From: Andrey Gushchin Date: Tue, 1 Jul 2025 10:47:08 +0300 Subject: [PATCH] =?UTF-8?q?[ERP-1946]=20RNA:=20=D0=9D=D0=B5=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D0=BB=D1=8C=D0=BD=D0=BE=20=D0=BE=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=B4=D0=BB=D1=8F=D0=B5=D1=82=D1=81=D1=8F=20=D0=B0?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=80=20=D0=9F=D0=A0=D0=B0,=20=D0=B2=D0=BE?= =?UTF-8?q?=D1=88=D0=B5=D0=B4=D1=88=D0=B5=D0=B3=D0=BE=20=D0=B2=20=D1=8D?= =?UTF-8?q?=D0=BF=D0=B8=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mixins/github/epic.py | 27 +++++++++++++++------------ requirements.txt | 2 +- tests/base_test.py | 2 ++ tests/test_epic_tasks.py | 10 +++++++--- 4 files changed, 25 insertions(+), 16 deletions(-) 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)