Skip to content

Commit 14f7e5d

Browse files
authored
Merge pull request #25602 from seokho-son/master
Enhance diff_l10n_branches script output
2 parents cff3f17 + 8f776e2 commit 14f7e5d

File tree

1 file changed

+68
-11
lines changed

1 file changed

+68
-11
lines changed

scripts/diff_l10n_branches.py

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
1414
### {{ files_to_be_modified | count }} files to be modified
1515
{% for m_file in files_to_be_modified -%}
16-
1. [ ] {{ m_file.filepath }} {{ m_file.shortstat }}
16+
1. [ ] {{ m_file.fileindex }} `{{ m_file.filepath }}` {{ m_file.stat }}
1717
{% endfor %}
1818
1919
### {{ files_to_be_renamed | count }} files to be renamed
2020
{% for r_file in files_to_be_renamed -%}
21-
1. [ ] {{ r_file.diff_status_letter }} {{ r_file.src_filepath }} -> {{ r_file.dest_filepath }}
21+
1. [ ] {{ r_file.fileindex }} {{ r_file.diff_status_letter }} `{{ r_file.src_filepath }}` -> `{{ r_file.dest_filepath }}`
2222
{% endfor %}
2323
2424
### {{ files_to_be_deleted | count }} files to be deleted
2525
{% for d_file in files_to_be_deleted -%}
26-
1. [ ] {{ d_file }}
26+
1. [ ] {{ d_file.fileindex }} `{{ d_file.filepath }}`
2727
{% endfor %}
2828
2929
## Proposed Solution
@@ -51,18 +51,23 @@
5151
5252
## Pages to Update
5353
54+
Pages in {{ l10n_lang_path }}
55+
5456
"""
5557

5658
files_to_be_deleted = []
5759
files_to_be_renamed = []
5860
files_to_be_modified = []
5961

62+
index_to_be_deleted = 0
63+
index_to_be_renamed = 0
64+
index_to_be_modified = 0
6065

61-
def git_diff(filepath, l_commit, r_commit, shortstat=False):
66+
def git_diff(filepath, l_commit, r_commit, stat=False):
6267
cmd = ["git", "diff", l_commit, r_commit, "--", filepath]
6368

64-
if shortstat:
65-
cmd = ["git", "diff", l_commit, r_commit, "--shortstat", "--", filepath]
69+
if stat:
70+
cmd = ["git", "diff", l_commit, r_commit, "--stat", "--", filepath]
6671

6772
return subprocess.check_output(cmd).decode("UTF-8").strip()
6873

@@ -78,18 +83,70 @@ def process_diff_status(diff_status, l_commit, r_commit, src_lang_path,
7883
status_letter = diff_status[0]
7984
filepath = diff_status[1]
8085

86+
size_xs = 10
87+
size_s = 30
88+
size_m = 100
89+
size_l = 500
90+
size_xl = 1000
91+
8192
if git_exists(r_commit, filepath.replace(src_lang_path, l10n_lang_path)):
8293
if status_letter == 'D':
83-
files_to_be_deleted.append(filepath)
94+
global index_to_be_deleted
95+
index_to_be_deleted += 1
96+
fileindex = "D" + str(index_to_be_deleted) + '. '
97+
deleted = {"fileindex": fileindex,
98+
"filepath": filepath }
99+
files_to_be_deleted.append(deleted)
84100
elif status_letter.startswith('R'):
85-
replaced = {"diff_status_letter": diff_status[0],
101+
global index_to_be_renamed
102+
index_to_be_renamed += 1
103+
fileindex = "R" + str(index_to_be_renamed) + '. '
104+
replaced = {"fileindex": fileindex,
105+
"diff_status_letter": diff_status[0],
86106
"src_filepath": diff_status[1],
87107
"dest_filepath": diff_status[2]}
88108
files_to_be_renamed.append(replaced)
89109
elif status_letter == 'M':
90-
modified = {"filepath": filepath,
91-
"shortstat": git_diff(filepath, l_commit, r_commit,
92-
shortstat=True),
110+
global index_to_be_modified
111+
index_to_be_modified += 1
112+
diff_string = git_diff(filepath, l_commit, r_commit, stat=True)
113+
diff_string_tmp= diff_string.split("|")
114+
diff_string_r = diff_string_tmp[1]
115+
116+
res = [int(i) for i in diff_string_r.split() if i.isdigit()]
117+
if len(res) < 4 :
118+
res.append(0)
119+
120+
insertions = res[2]
121+
deletions = res[3]
122+
123+
bold_condition = size_m
124+
if insertions < size_xs :
125+
insertion_size = "XS"
126+
elif insertions < size_s :
127+
insertion_size = "S"
128+
elif insertions < size_m :
129+
insertion_size = "M"
130+
elif insertions < size_l :
131+
insertion_size = "L"
132+
elif insertions < size_xl :
133+
insertion_size = "XL"
134+
else :
135+
insertion_size = "XXL"
136+
137+
stat_output = str(insertions) + "(+" + insertion_size + ") " + str(deletions) + "(-)"
138+
139+
if insertions >= bold_condition :
140+
fileindex = "**M" + str(index_to_be_modified) + ".** "
141+
stat_output = "**" + stat_output + "**"
142+
else :
143+
fileindex = "M" + str(index_to_be_modified) + ". "
144+
145+
stat_output = " | " + stat_output
146+
147+
modified = {"fileindex": fileindex,
148+
"filepath": filepath,
149+
"stat": stat_output,
93150
"diff": git_diff(filepath, l_commit, r_commit)}
94151
files_to_be_modified.append(modified)
95152

0 commit comments

Comments
 (0)