mirror of
https://github.com/YunoHost/apps.git
synced 2024-09-03 20:06:07 +02:00
feat(translate_apps): use testing branch if it exists
This commit is contained in:
parent
5ba6232cfc
commit
1fd3f96d0e
3 changed files with 43 additions and 2 deletions
|
@ -5,7 +5,7 @@ from pathlib import Path
|
|||
|
||||
import tomlkit
|
||||
|
||||
from base import Repository, login, token
|
||||
from base import Repository, login, token, WORKING_BRANCH
|
||||
|
||||
|
||||
def extract_strings_to_translate_from_apps(apps, translations_repository):
|
||||
|
@ -43,6 +43,23 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
|
|||
if not repository.file_exists("manifest.toml"):
|
||||
continue
|
||||
|
||||
if repository.run_command_as_if(["git", "rev-parse", "--verify", "origin/testing"]):
|
||||
repository.run_command(["git", "checkout", "-b", WORKING_BRANCH, "--track", "origin/testing"])
|
||||
if repository.run_command_as_if(
|
||||
["git", "rev-parse", "--verify", "origin/testing"]
|
||||
):
|
||||
repository.run_command(
|
||||
[
|
||||
"git",
|
||||
"checkout",
|
||||
"-b",
|
||||
WORKING_BRANCH,
|
||||
"--track",
|
||||
"origin/testing",
|
||||
]
|
||||
)
|
||||
repository.run_command(["git", "checkout", "-b", WORKING_BRANCH])
|
||||
|
||||
manifest = tomlkit.loads(repository.read_file("manifest.toml"))
|
||||
|
||||
for translation in translations_path.glob("*.json"):
|
||||
|
@ -77,7 +94,7 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
|
|||
repository.run_command("git diff")
|
||||
repository.run_command("git add manifest.toml")
|
||||
repository.run_command(["git", "commit", "-m", "feat(i18n): update translations for manifest.toml"])
|
||||
repository.run_command(["git", "push", "-f", "origin", "master:manifest_toml_i18n"])
|
||||
repository.run_command(["git", "push", "-f", "origin", f"{WORKING_BRANCH}:manifest_toml_i18n"])
|
||||
|
||||
# if no PR exist, create one
|
||||
if not repository.run_command("hub pr list -h manifest_toml_i18n", capture_output=True):
|
||||
|
|
|
@ -21,6 +21,8 @@ my_env["GIT_COMMITTER_EMAIL"] = "yunohost@yunohost.org"
|
|||
my_env["GITHUB_USER"] = login
|
||||
my_env["GITHUB_TOKEN"] = token
|
||||
|
||||
WORKING_BRANCH = "manifest_toml_i18n"
|
||||
|
||||
|
||||
class Repository:
|
||||
def __init__(self, url, branch):
|
||||
|
@ -63,6 +65,20 @@ class Repository:
|
|||
print(f"\033[1;31m>>\033[0m \033[0;34m{command}\033[0m")
|
||||
return subprocess.check_call(**kwargs)
|
||||
|
||||
def run_command_as_if(self, command: Union[str, list]) -> bool:
|
||||
if isinstance(command, str):
|
||||
kwargs = {
|
||||
"args": f"cd {self.path} && {command}",
|
||||
"shell": True,
|
||||
"env": my_env,
|
||||
}
|
||||
|
||||
elif isinstance(command, list):
|
||||
kwargs = {"args": command, "cwd": self.path, "env": my_env}
|
||||
|
||||
print(f"\033[1;31m>>\033[0m \033[0;34m{command}\033[0m")
|
||||
return subprocess.run(**kwargs).returncode == 0
|
||||
|
||||
def file_exists(self, file_name: str) -> bool:
|
||||
return (self.path / file_name).exists()
|
||||
|
||||
|
|
|
@ -41,6 +41,14 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
|
|||
if not repository.file_exists("manifest.toml"):
|
||||
continue
|
||||
|
||||
# base our work on the testing branch if it exists
|
||||
if repository.run_command_as_if(
|
||||
["git", "rev-parse", "--verify", "origin/testing"]
|
||||
):
|
||||
repository.run_command(
|
||||
["git", "checkout", "-b", "testing", "--track", "origin/testing"]
|
||||
)
|
||||
|
||||
manifest = tomlkit.loads(repository.read_file("manifest.toml"))
|
||||
|
||||
translations_path = Path(f"translations/apps/{app}/manifest/")
|
||||
|
|
Loading…
Add table
Reference in a new issue