Skip to content

Commit 813de09

Browse files
authored
feat: add create issue link to summary table
1 parent e367c7f commit 813de09

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

.scripts/summarize_progress/main.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,23 @@
66
from pathlib import Path
77

88

9-
def entry_check(pofile: polib.POFile) -> str:
9+
def get_progress(pofile: polib.POFile) -> float:
1010
'''
1111
Check the po file with how many entries are translated or not.
1212
'''
1313

1414
lines_tranlated = len(pofile.translated_entries())
1515
lines_untranlated = len(pofile.untranslated_entries())
1616

17-
if lines_tranlated == 0:
18-
result = "❌"
19-
elif lines_untranlated == 0:
20-
result = "✅"
21-
else:
22-
lines_all = lines_tranlated + lines_untranlated
23-
progress = lines_tranlated / lines_all
24-
progress_percentage = round(progress * 100, 2)
25-
result = f"{progress_percentage} %"
26-
27-
return result
17+
# if lines_tranlated == 0:
18+
# result = "❌"
19+
# elif lines_untranlated == 0:
20+
# result = "✅"
21+
# else:
22+
lines_all = lines_tranlated + lines_untranlated
23+
progress = lines_tranlated / lines_all
24+
progress_percentage = round(progress * 100, 2)
25+
return progress_percentage
2826

2927

3028
def get_open_issues_count() -> int:
@@ -93,13 +91,21 @@ def format_line_table_header() -> list:
9391
f"|-------:|:-------|:----|:-------|\r\n"]
9492

9593

96-
def format_issue_link(url: str) -> str:
97-
return f"[{url.split('/')[-1]}]({url})" if len(url) > 0 else ''
94+
def format_line_po_issue_display(issue_link: str, issue_number: str, create_issue_link: str, progress: float) -> str:
95+
if issue_link:
96+
return f"[{issue_number}]({issue_link})"
97+
if progress != 100:
98+
return f"[create issue]({create_issue_link})"
99+
return ""
98100

99101

100-
def format_line_file(dirname: str, filename: str, data: dict) -> str:
101-
return f"|[`{filename}`](https://github.com/python/python-docs-zh-tw/tree/3.13/{dirname}/{filename})" + \
102-
f"|{data['progress']}|{format_issue_link(data['issue'])}|{data['assignee']}|\r\n"
102+
def format_line_po(filename: str, po_link: str, progress: str, issue_display: str, assignee: str) -> str:
103+
progress_display = f"{progress} %"
104+
if progress == 0:
105+
progress_display = "❌"
106+
elif progress == 100:
107+
progress_display = "✅"
108+
return f"|[`{filename}`]({po_link})|{progress_display}|{issue_display}|{assignee}|\r\n"
103109

104110

105111
def format_line_directory(dirname: str) -> str:
@@ -122,7 +128,7 @@ def format_line_directory(dirname: str) -> str:
122128
po = polib.pofile(filepath)
123129

124130
summary.setdefault(dirname, {})[filename] = {
125-
'progress': entry_check(po),
131+
'progress': get_progress(po),
126132
'issue': '',
127133
'assignee': '',
128134
}
@@ -153,7 +159,14 @@ def format_line_directory(dirname: str) -> str:
153159

154160
filedict_sorted = dict(sorted(filedict.items()))
155161
for filename, filedata in filedict_sorted.items():
156-
writeliner.append(format_line_file(dirname, filename, filedata))
162+
file_path = f"{dirname}/{filename}"
163+
po_link = f"https://github.com/python/python-docs-zh-tw/tree/3.13/{file_path}"
164+
issue_link = filedata['issue']
165+
issue_number = f"#{issue_link.split('/')[-1]}"
166+
create_issue_link = f"https://github.com/python/python-docs-zh-tw/issues/new?title=Translate `{file_path}`"
167+
issue_display = format_line_po_issue_display(issue_link, issue_number, filedata['progress'], create_issue_link)
168+
line_po = format_line_po(filename, po_link, filedata['progress'], issue_display, filedata['assignee'])
169+
writeliner.append(line_po)
157170

158171
with open(
159172
f"summarize_progress/result.md",

0 commit comments

Comments
 (0)