|
11 | 11 | # files. |
12 | 12 | # * recreate_readme: recreate readme to update translation progress. |
13 | 13 | # * regenerate_tx_config: recreate configuration for all resources. |
| 14 | +# * generate_commit_msg: generates commit message with co-authors |
14 | 15 |
|
15 | 16 | fromargparseimportArgumentParser |
16 | 17 | fromcollectionsimportCounter |
17 | 18 | importos |
18 | 19 | fromdataclassesimportdataclass |
19 | 20 | frompathlibimportPath |
20 | 21 | fromreimportmatch,search |
21 | | -fromsubprocessimportcall,run |
| 22 | +fromsubprocessimportcall,run,CalledProcessError |
22 | 23 | importsys |
23 | 24 | fromtypingimportSelf |
24 | 25 | fromurllib.parseimportunquote |
25 | 26 | fromwarningsimportwarn |
26 | 27 |
|
| 28 | +frompolibimportpofile,POFile |
| 29 | + |
27 | 30 | LANGUAGE='pl' |
28 | 31 |
|
29 | 32 |
|
@@ -271,8 +274,62 @@ def average(averages, weights): |
271 | 274 | ) |
272 | 275 |
|
273 | 276 |
|
| 277 | +defgenerate_commit_msg(): |
| 278 | +"""Generate a commit message |
| 279 | + Parses staged files and generates a commit message with Last-Translator's as |
| 280 | + co-authors. |
| 281 | + """ |
| 282 | +translators:set[str]=set() |
| 283 | + |
| 284 | +result=run( |
| 285 | + ['git','diff','--cached','--name-only','--diff-filter=ACM'], |
| 286 | +capture_output=True, |
| 287 | +text=True, |
| 288 | +check=True, |
| 289 | + ) |
| 290 | +staged= [ |
| 291 | +filenameforfilenameinresult.stdout.splitlines()iffilename.endswith('.po') |
| 292 | + ] |
| 293 | + |
| 294 | +forfileinstaged: |
| 295 | +staged_file=run( |
| 296 | + ['git','show',f':{file}'],capture_output=True,text=True,check=True |
| 297 | + ).stdout |
| 298 | +try: |
| 299 | +old_file=run( |
| 300 | + ['git','show',f'HEAD:{file}'], |
| 301 | +capture_output=True, |
| 302 | +text=True, |
| 303 | +check=True, |
| 304 | + ).stdout |
| 305 | +exceptCalledProcessError: |
| 306 | +old_file='' |
| 307 | + |
| 308 | +new_po=pofile(staged_file) |
| 309 | +old_po=pofile(old_file)ifold_fileelsePOFile() |
| 310 | +old_entries= {entry.msgid:entry.msgstrforentryinold_po} |
| 311 | + |
| 312 | +forentryinnew_po: |
| 313 | +ifentry.msgstrand ( |
| 314 | +entry.msgidnotinold_entries |
| 315 | +orold_entries[entry.msgid]!=entry.msgstr |
| 316 | + ): |
| 317 | +translator=new_po.metadata.get('Last-Translator') |
| 318 | +translator=translator.split(',')[0].strip() |
| 319 | +iftranslator: |
| 320 | +translators.add(f'Co-Authored-By:{translator}') |
| 321 | +break |
| 322 | + |
| 323 | +print('Update translation from Transifex\n\n'+'\n'.join(translators)) |
| 324 | + |
| 325 | + |
274 | 326 | if__name__=="__main__": |
275 | | -RUNNABLE_SCRIPTS= ('fetch','recreate_tx_config','recreate_readme','warn_about_files_to_delete') |
| 327 | +RUNNABLE_SCRIPTS= ( |
| 328 | +'fetch', |
| 329 | +'recreate_tx_config', |
| 330 | +'recreate_readme','warn_about_files_to_delete', |
| 331 | +'generate_commit_msg', |
| 332 | + ) |
276 | 333 |
|
277 | 334 | parser=ArgumentParser() |
278 | 335 | parser.add_argument('cmd',choices=RUNNABLE_SCRIPTS) |
|