1
1
import re
2
2
import polib
3
3
import glob
4
- import datetime
5
4
import requests
6
5
7
6
from pathlib import Path
@@ -23,7 +22,7 @@ def entry_check(pofile: polib.POFile) -> str:
23
22
lines_all = lines_tranlated + lines_untranlated
24
23
progress = lines_tranlated / lines_all
25
24
progress_percentage = round (progress * 100 , 2 )
26
- result = f"Ongoing, { progress_percentage } %"
25
+ result = f"{ progress_percentage } %"
27
26
28
27
return result
29
28
@@ -51,9 +50,11 @@ def get_github_issues() -> list:
51
50
52
51
Steps:
53
52
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), ... ]
57
58
'''
58
59
NUMBER_OF_ISSUES = get_open_issues_count ()
59
60
@@ -67,31 +68,41 @@ def get_github_issues() -> list:
67
68
68
69
result_list = []
69
70
for issue in result ["items" ]:
70
- if issue ["assignee" ] is None :
71
- continue
71
+ assignee = issue ["assignee" ]["login" ] if issue ["assignee" ] else ""
72
72
73
73
title = issue ["title" ]
74
74
if "翻譯" not in title and "translate" not in title .lower ():
75
75
continue
76
76
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 )
78
79
if not match :
79
80
continue
80
81
81
82
dirname , filename = match .group ('dirname' , 'filename' )
82
83
if not filename .endswith ('.po' ):
83
84
filename += '.po'
84
85
85
- result_list .append (((dirname , filename ), issue ["assignee" ][ "login " ]))
86
+ result_list .append (((dirname , filename ), assignee , issue ["html_url " ]))
86
87
87
88
return result_list
88
89
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 "
91
102
92
103
93
104
def format_line_directory (dirname : str ) -> str :
94
- return f"- { dirname } / \r \n "
105
+ return f"## { dirname } \r \n "
95
106
96
107
97
108
if __name__ == "__main__" :
@@ -108,17 +119,27 @@ def format_line_directory(dirname: str) -> str:
108
119
filename = path .name
109
120
dirname = path .parent .name if path .parent .name != BASE_DIR .name else '/'
110
121
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
+ }
112
128
113
129
'''
114
130
Unpack the open issue list, and add assignee after the progress
115
131
'''
116
- for (category , filename ), assignee in issue_list :
132
+ for (category , filename ), assignee , issue_url in issue_list :
117
133
try :
118
- summary [category ][filename ] += f", 💻 { assignee } "
134
+ summary [category ][filename ]['issue' ] = issue_url
135
+ summary [category ][filename ]['assignee' ] = assignee
119
136
except KeyError :
120
137
pass
121
138
139
+ '''
140
+ Adding Space for Formatting Markdown Link
141
+ '''
142
+
122
143
'''
123
144
Format the lines that will write into the markdown file,
124
145
also sort the directory name and file name.
@@ -127,12 +148,14 @@ def format_line_directory(dirname: str) -> str:
127
148
summary_sorted = dict (sorted (summary .items ()))
128
149
for dirname , filedict in summary_sorted .items ():
129
150
writeliner .append (format_line_directory (dirname ))
151
+ writeliner .extend (format_line_table_header ())
152
+
130
153
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 ))
133
156
134
157
with open (
135
- f"summarize_progress/dist/summarize_progress .md" ,
158
+ f"summarize_progress/result .md" ,
136
159
"w" ,
137
160
) as file :
138
161
file .writelines (writeliner )
0 commit comments