Skip to content

Commit c61ea81

Browse files
authored
Merge pull request #26 from evrone-erp/feature/ERP-1756/add_title_for_link_in_description
[ERP-1756] Add title for link in description
2 parents ef891e9 + da1c569 commit c61ea81

4 files changed

Lines changed: 23 additions & 13 deletions

File tree

helpers/github.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
11
import logging
22
import re
33
import sys
4-
from typing import Optional
4+
from typing import Dict, Optional
55

66
from github.PullRequest import PullRequest
77

88
TASK_KEY_PATTERN = re.compile(r"[^[]*\[([^]]*)\]") # noqa
9+
TASK_LINK_TITLE_TEMPLATE = (
10+
"[[{task_key}] {task_title}](https://tracker.yandex.ru/{task_key})"
11+
)
912
logger = logging.getLogger(__name__)
1013

1114

1215
def _prepare_description(
1316
*,
14-
task_keys: list[str],
17+
tasks: Dict,
1518
pr: PullRequest,
1619
) -> Optional[str]:
1720
"""
1821
Update the existing PR description with links to the task keys.
1922
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.
2124
pr: GitHub PullRequest object.
2225
Return:
2326
Description in string format if exists or None.
2427
"""
2528
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+
]
2736

2837
task_links = ""
2938
for link in links:
@@ -60,16 +69,16 @@ def get_pr_commits(
6069

6170
def set_pr_body(
6271
*,
63-
task_keys: list[str],
72+
tasks: Dict,
6473
pr: PullRequest,
6574
) -> None:
6675
"""
6776
Set PR description with a link to tracker task.
6877
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.
7079
pr: GitHub PullRequest object.
7180
"""
72-
description = _prepare_description(task_keys=task_keys, pr=pr)
81+
description = _prepare_description(tasks=tasks, pr=pr)
7382
if description:
7483
pr.edit(body=description)
7584

helpers/yandex.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import sys
33
from http import HTTPStatus
4+
from typing import Dict
45

56
import requests
67
from github.PullRequest import PullRequest
@@ -42,7 +43,7 @@ def task_exists(
4243
is_yandex_cloud_org: bool,
4344
tasks: list[str],
4445
token: str,
45-
) -> list[str]:
46+
) -> Dict:
4647
"""
4748
Get Yandex API with task keys. If a task does not exist, remove from a list.
4849
Args:
@@ -76,8 +77,7 @@ def task_exists(
7677
)
7778
continue
7879
existing_tasks[task] = response.json()
79-
80-
return [k for (k, v) in existing_tasks.items() if "errors" not in v]
80+
return {k: v for (k, v) in existing_tasks.items() if "errors" not in v}
8181

8282

8383
def _get_all_transitions(

index.json

Whitespace-only changes.

main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import logging
33
import sys
4+
from typing import Dict
45

56
from environs import Env
67
from github import Github
@@ -58,7 +59,7 @@
5859
iam_token = get_iam_token(YANDEX_OAUTH2_TOKEN)
5960

6061
if any(task_keys):
61-
existing_tasks = task_exists(
62+
existing_tasks: Dict = task_exists(
6263
org_id=YANDEX_ORG_ID,
6364
is_yandex_cloud_org=IS_YANDEX_CLOUD_ORG,
6465
tasks=task_keys,
@@ -67,7 +68,7 @@
6768
else:
6869
logger.warning("[SKIPPED] No tasks found!")
6970
sys.exit(0)
70-
set_pr_body(task_keys=existing_tasks, pr=pr)
71+
set_pr_body(tasks=existing_tasks, pr=pr)
7172

7273
if TARGET_STATUS:
7374
target_status = TARGET_STATUS
@@ -90,7 +91,7 @@
9091
org_id=YANDEX_ORG_ID,
9192
is_yandex_cloud_org=IS_YANDEX_CLOUD_ORG,
9293
pr=pr,
93-
task_keys=existing_tasks,
94+
task_keys=list(existing_tasks),
9495
target_status=target_status,
9596
token=iam_token,
9697
)

0 commit comments

Comments
 (0)