Skip to content

Commit

Permalink
Auto-translate README
Browse files Browse the repository at this point in the history
  • Loading branch information
Lin-jun-xiang committed Oct 17, 2023
1 parent 5bd81dc commit ba1a5df
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
PROVIDER = None


def run_shell_command(command: str) -> tuple:
def get_diff_files(command: str) -> tuple:
result = subprocess.run(
command,
shell=True,
Expand All @@ -29,6 +29,15 @@ def run_shell_command(command: str) -> tuple:
return result.returncode, result.stdout, result.stderr


def get_last_commit_message():
result = subprocess.run(
['git', 'show', '-s', '--format=%s'],
stdout=subprocess.PIPE,
text=True
)
return result.stdout.strip()


@retry(stop=stop_after_attempt(15))
async def chat_completion(query: str) -> str:
response = await g4f.ChatCompletion.create_async(
Expand Down Expand Up @@ -81,8 +90,14 @@ def extract_prefix(filename: str) -> str:


async def main():
last_commit_message = get_last_commit_message()

if last_commit_message == "Auto-translate README":
print('Auto translated, skip translate...')
return

git_diff_command = "git diff --name-only HEAD~1 HEAD"
return_code, stdout, stderr = run_shell_command(git_diff_command)
return_code, stdout, stderr = get_diff_files(git_diff_command)

if return_code != 0:
print('no file changed.')
Expand Down

0 comments on commit ba1a5df

Please sign in to comment.