|
1 | 1 | import logging |
2 | 2 | import re |
3 | 3 | import sys |
4 | | -from typing import Optional |
| 4 | +from typing import Dict, Optional |
5 | 5 |
|
6 | 6 | from github.PullRequest import PullRequest |
7 | 7 |
|
8 | 8 | TASK_KEY_PATTERN = re.compile(r"[^[]*\[([^]]*)\]") # noqa |
| 9 | +TASK_LINK_TITLE_TEMPLATE = ( |
| 10 | + "[[{task_key}] {task_title}](https://tracker.yandex.ru/{task_key})" |
| 11 | +) |
9 | 12 | logger = logging.getLogger(__name__) |
10 | 13 |
|
11 | 14 |
|
12 | 15 | def _prepare_description( |
13 | 16 | *, |
14 | | - task_keys: list[str], |
| 17 | + tasks: Dict, |
15 | 18 | pr: PullRequest, |
16 | 19 | ) -> Optional[str]: |
17 | 20 | """ |
18 | 21 | Update the existing PR description with links to the task keys. |
19 | 22 | Args: |
20 | | - task_keys: List of the Yandex tracker tasks from action. |
| 23 | + tasks: Dict with Yandex Tracker task number as key and task data as value. |
21 | 24 | pr: GitHub PullRequest object. |
22 | 25 | Return: |
23 | 26 | Description in string format if exists or None. |
24 | 27 | """ |
25 | 28 | body = pr.body |
26 | | - links = [f"https://tracker.yandex.ru/{task}" for task in filter(None, task_keys)] |
| 29 | + links = [ |
| 30 | + TASK_LINK_TITLE_TEMPLATE.format( |
| 31 | + task_key=task_key, |
| 32 | + task_title=task_data.get("summary", ""), |
| 33 | + ) |
| 34 | + for task_key, task_data in tasks.items() |
| 35 | + ] |
27 | 36 |
|
28 | 37 | task_links = "" |
29 | 38 | for link in links: |
@@ -60,16 +69,16 @@ def get_pr_commits( |
60 | 69 |
|
61 | 70 | def set_pr_body( |
62 | 71 | *, |
63 | | - task_keys: list[str], |
| 72 | + tasks: Dict, |
64 | 73 | pr: PullRequest, |
65 | 74 | ) -> None: |
66 | 75 | """ |
67 | 76 | Set PR description with a link to tracker task. |
68 | 77 | Args: |
69 | | - task_keys: list of Yandex tracker task keys. |
| 78 | + tasks: Dict with Yandex Tracker task number as key and task data as value. |
70 | 79 | pr: GitHub PullRequest object. |
71 | 80 | """ |
72 | | - description = _prepare_description(task_keys=task_keys, pr=pr) |
| 81 | + description = _prepare_description(tasks=tasks, pr=pr) |
73 | 82 | if description: |
74 | 83 | pr.edit(body=description) |
75 | 84 |
|
|
0 commit comments