Add a script to check differences between translated and English version (#14731)
This script will query all the changes that happen to a reference document (in English) since the last time a given translation was merged (For instance in French). This could help all the translation team to keep up with the changes that happened inside the reference document.pull/14836/merge
parent
846de91040
commit
be946f210d
|
@ -0,0 +1,78 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import re
|
||||||
|
from subprocess import check_output
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
|
||||||
|
def last_commit(path, git):
|
||||||
|
"""
|
||||||
|
Find the hash of the last commit that touched a file.
|
||||||
|
"""
|
||||||
|
cmd = [git, "log", "-n", "1", "--pretty=format:%H", "--", path]
|
||||||
|
try:
|
||||||
|
return check_output(cmd)
|
||||||
|
except Exception as exc:
|
||||||
|
raise exc
|
||||||
|
|
||||||
|
|
||||||
|
def diff(reference_commit_hash, translation_commit_hash, reference_path, git):
|
||||||
|
"""
|
||||||
|
Returns the diff between two hashes on a specific file
|
||||||
|
"""
|
||||||
|
cmd = [git, "diff",
|
||||||
|
"%s...%s" % (translation_commit_hash, reference_commit_hash),
|
||||||
|
"--",
|
||||||
|
reference_path]
|
||||||
|
try:
|
||||||
|
return check_output(cmd)
|
||||||
|
except Exception as exc:
|
||||||
|
raise exc
|
||||||
|
|
||||||
|
|
||||||
|
def find_full_path(path, git):
|
||||||
|
cmd = [git, "ls-tree",
|
||||||
|
"--name-only", "--full-name", "HEAD",
|
||||||
|
path]
|
||||||
|
try:
|
||||||
|
return check_output(cmd).strip()
|
||||||
|
except Exception as exc:
|
||||||
|
raise exc
|
||||||
|
|
||||||
|
|
||||||
|
def find_reference(path, git):
|
||||||
|
abs_path = find_full_path(path, git=git)
|
||||||
|
return re.sub('content/(\w{2})/', 'content/en/', abs_path)
|
||||||
|
|
||||||
|
|
||||||
|
@click.command()
|
||||||
|
@click.argument("path")
|
||||||
|
@click.option("--reference", "reference",
|
||||||
|
help="Specify the reference version of the file. Default to the English one.",
|
||||||
|
default=None)
|
||||||
|
@click.option("--git-path",
|
||||||
|
"git",
|
||||||
|
help="Specify git path",
|
||||||
|
default="git")
|
||||||
|
def main(path, reference, git):
|
||||||
|
"""
|
||||||
|
Find what changes occurred between two versions
|
||||||
|
|
||||||
|
ex:
|
||||||
|
./upstream_changes.py content/fr/_index.html
|
||||||
|
"""
|
||||||
|
if reference is None:
|
||||||
|
reference = find_reference(path, git=git)
|
||||||
|
reference_commit_hash = last_commit(path=reference, git=git)
|
||||||
|
translation_commit_hash = last_commit(path=path, git=git)
|
||||||
|
|
||||||
|
print(diff(
|
||||||
|
reference_commit_hash=reference_commit_hash,
|
||||||
|
translation_commit_hash=translation_commit_hash,
|
||||||
|
reference_path=reference,
|
||||||
|
git=git
|
||||||
|
))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in New Issue