forked from fastapi/fastapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslation_git.py
More file actions
47 lines (43 loc) · 1.28 KB
/
Copy pathtranslation_git.py
File metadata and controls
47 lines (43 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import subprocess
from pathlib import Path
def has_translation_changes(repo_path: Path) -> bool:
result = subprocess.run(
["git", "status", "--porcelain", "--", "docs"],
cwd=repo_path,
check=True,
capture_output=True,
encoding="utf-8",
)
return bool(result.stdout)
def commit_translation_changes(
*,
repo_path: Path,
bot_name: str,
language: str | None,
command: str | None,
) -> str | None:
if not has_translation_changes(repo_path):
print("No translation changes to commit")
return None
print("Setting up GitHub App git user")
subprocess.run(["git", "config", "user.name", bot_name], cwd=repo_path, check=True)
subprocess.run(
[
"git",
"config",
"user.email",
f"{bot_name}@users.noreply.github.com",
],
cwd=repo_path,
check=True,
)
print("Adding updated files")
subprocess.run(["git", "add", "docs"], cwd=repo_path, check=True)
message = "🌐 Update translations"
if language:
message += f" for {language}"
if command:
message += f" ({command})"
print("Committing updated files")
subprocess.run(["git", "commit", "-m", message], cwd=repo_path, check=True)
return message