Skip to content

Commit 19039a0

Browse files
authoredFeb 21, 2024
Merge pull request #816 from rockleona/feat/summarize-table
feat: update summarize list to table
2 parents 4de0f94 + ea15224 commit 19039a0

File tree

3 files changed

+43
-517
lines changed

3 files changed

+43
-517
lines changed
 

‎.github/workflows/summarize_progress.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66

77
jobs:
88
ci:
9+
if: github.repository == 'python/python-docs-zh-tw'
910
runs-on: ubuntu-latest
1011
permissions:
1112
# Give the default GITHUB_TOKEN write permission to commit and push the
@@ -32,7 +33,7 @@ jobs:
3233

3334
- name: Copy content
3435
run: |
35-
cp .scripts/summarize_progress/dist/summarize_progress.md markdown/各檔案翻譯進度清單.md
36+
cp .scripts/summarize_progress/result.md markdown/各檔案翻譯進度清單.md
3637
shell: bash
3738

3839
- name: Commit wiki code

‎.scripts/summarize_progress/dist/summarize_progress.md

-498
This file was deleted.

‎.scripts/summarize_progress/main.py

+41-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import re
22
import polib
33
import glob
4-
import datetime
54
import requests
65

76
from pathlib import Path
@@ -23,7 +22,7 @@ def entry_check(pofile: polib.POFile) -> str:
2322
lines_all = lines_tranlated + lines_untranlated
2423
progress = lines_tranlated / lines_all
2524
progress_percentage = round(progress * 100, 2)
26-
result = f"Ongoing, {progress_percentage} %"
25+
result = f"{progress_percentage} %"
2726

2827
return result
2928

@@ -51,9 +50,11 @@ def get_github_issues() -> list:
5150
5251
Steps:
5352
1. Fetch GitHub API and get open issue list
54-
2. Filter the issue if it have no assignee
55-
3. Filter the issue if it have no "Translate" in the title
56-
4. Filter the issue if it have no correct filepath in the title
53+
2. Filter the issue if it have no "Translate" in the title
54+
3. Filter the issue if it have no correct filepath in the title
55+
56+
Expected Output:
57+
[ ((dirname, filename), assignee_id, issue_url), ... ]
5758
'''
5859
NUMBER_OF_ISSUES = get_open_issues_count()
5960

@@ -67,31 +68,41 @@ def get_github_issues() -> list:
6768

6869
result_list = []
6970
for issue in result["items"]:
70-
if issue["assignee"] is None:
71-
continue
71+
assignee = issue["assignee"]["login"] if issue["assignee"] else ""
7272

7373
title = issue["title"]
7474
if "翻譯" not in title and "translate" not in title.lower():
7575
continue
7676

77-
match = re.search("(?P<dirname>[^\s`][a-zA-z-]+)/(?P<filename>[a-zA-Z0-9._-]+(.po)?)", title)
77+
match = re.search(
78+
"(?P<dirname>[^\s`][a-zA-z-]+)/(?P<filename>[a-zA-Z0-9._-]+(.po)?)", title)
7879
if not match:
7980
continue
8081

8182
dirname, filename = match.group('dirname', 'filename')
8283
if not filename.endswith('.po'):
8384
filename += '.po'
8485

85-
result_list.append(((dirname, filename), issue["assignee"]["login"]))
86+
result_list.append(((dirname, filename), assignee, issue["html_url"]))
8687

8788
return result_list
8889

89-
def format_line_file(filename: str, result: str) -> str:
90-
return f" - {filename.ljust(37, '-')}{result}\r\n"
90+
91+
def format_line_table_header() -> list:
92+
return [f"|Filename|Progress|Issue|Assignee|\r\n",
93+
f"|-------:|:-------|:----|:-------|\r\n"]
94+
95+
96+
def format_issue_link(url: str) -> str:
97+
return f"[{url.split('/')[-1]}]({url})" if len(url) > 0 else ''
98+
99+
100+
def format_line_file(filename: str, data: dict) -> str:
101+
return f"|`{filename}`|{data['progress']}|{format_issue_link(data['issue'])}|{data['assignee']}|\r\n"
91102

92103

93104
def format_line_directory(dirname: str) -> str:
94-
return f"- {dirname}/\r\n"
105+
return f"## {dirname}\r\n"
95106

96107

97108
if __name__ == "__main__":
@@ -108,17 +119,27 @@ def format_line_directory(dirname: str) -> str:
108119
filename = path.name
109120
dirname = path.parent.name if path.parent.name != BASE_DIR.name else '/'
110121
po = polib.pofile(filepath)
111-
summary.setdefault(dirname, {})[filename] = entry_check(po)
122+
123+
summary.setdefault(dirname, {})[filename] = {
124+
'progress': entry_check(po),
125+
'issue': '',
126+
'assignee': '',
127+
}
112128

113129
'''
114130
Unpack the open issue list, and add assignee after the progress
115131
'''
116-
for (category, filename), assignee in issue_list:
132+
for (category, filename), assignee, issue_url in issue_list:
117133
try:
118-
summary[category][filename] += f", 💻 {assignee}"
134+
summary[category][filename]['issue'] = issue_url
135+
summary[category][filename]['assignee'] = assignee
119136
except KeyError:
120137
pass
121138

139+
'''
140+
Adding Space for Formatting Markdown Link
141+
'''
142+
122143
'''
123144
Format the lines that will write into the markdown file,
124145
also sort the directory name and file name.
@@ -127,12 +148,14 @@ def format_line_directory(dirname: str) -> str:
127148
summary_sorted = dict(sorted(summary.items()))
128149
for dirname, filedict in summary_sorted.items():
129150
writeliner.append(format_line_directory(dirname))
151+
writeliner.extend(format_line_table_header())
152+
130153
filedict_sorted = dict(sorted(filedict.items()))
131-
for filename, result in filedict_sorted.items():
132-
writeliner.append(format_line_file(filename, result))
154+
for filename, filedata in filedict_sorted.items():
155+
writeliner.append(format_line_file(filename, filedata))
133156

134157
with open(
135-
f"summarize_progress/dist/summarize_progress.md",
158+
f"summarize_progress/result.md",
136159
"w",
137160
) as file:
138161
file.writelines(writeliner)

0 commit comments

Comments
 (0)
Please sign in to comment.