Last active
March 25, 2024 19:07
-
-
Save gochist/8654460717b4bbb4ac490dda79a547fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
DEVNULL = open(os.devnull, 'w') | |
BASE_CONTENT = "content/en" | |
WORK_CONTENT = "content/ko" | |
L_COMMIT = "website/dev-1.13-ko.3" | |
R_COMMIT = "website/master" | |
def get_changed_contents(l_commit, r_commit): | |
strip_index = len(BASE_CONTENT)+1 | |
cmd = ["git", "diff", l_commit, r_commit, "--name-only", "--", BASE_CONTENT] | |
changed_files = subprocess.check_output(cmd).decode("UTF-8").splitlines() | |
ret = [f[strip_index:] for f in changed_files] | |
return ret | |
def git_diff(filepath): | |
cmd = ["git", "diff", L_COMMIT, R_COMMIT, "--shortstat", "--", os.path.join(BASE_CONTENT, filepath)] | |
return subprocess.check_output(cmd).decode("UTF-8") | |
def git_exists(path, filepath): | |
cmd = ["git", "cat-file", "-e", "{}:{}".format(path, filepath)] | |
ret_code = subprocess.call(cmd, stderr=DEVNULL) | |
return ret_code == 0 | |
if __name__ == "__main__": | |
changed_contents = get_changed_contents(L_COMMIT, R_COMMIT) | |
outdated_contents = [f for f in changed_contents if git_exists(R_COMMIT, os.path.join(WORK_CONTENT, f))] | |
print("{} files in {} are changed".format(len(changed_contents), BASE_CONTENT)) | |
print("{} files in {} are outdated".format(len(outdated_contents), WORK_CONTENT)) | |
if outdated_contents: | |
print() | |
for c in outdated_contents: | |
print("- [ ] ", c, git_diff(c).strip()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output example
400 files in content/en are changed
23 files in content/ko are outdated