Skip to content

Commit

Permalink
chore: fix git absorb mess
Browse files Browse the repository at this point in the history
  • Loading branch information
Psycojoker committed Mar 29, 2024
1 parent dc80205 commit d721ee4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 37 deletions.
57 changes: 30 additions & 27 deletions tools/translate_apps/apps_translations_to_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
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",
Expand All @@ -60,6 +56,8 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
"origin/testing",
]
)
branch = "testing"
else:
repository.run_command(["git", "checkout", "-b", WORKING_BRANCH])

manifest = tomlkit.loads(repository.read_file("manifest.toml"))
Expand All @@ -85,19 +83,6 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
if strings_to_translate not in manifest["install"][question]:
continue

one_of_the_existing_languages = list(manifest["install"][question][strings_to_translate].keys())[0]
current_identation = len(manifest["install"][question][strings_to_translate][one_of_the_existing_languages].trivia.indent)
manifest["install"][question][strings_to_translate][language] = translation[translation_key]
manifest["install"][question][strings_to_translate][language].indent(current_identation)

repository.write_file("manifest.toml", tomlkit.dumps(manifest))

if not repository.run_command("git status -s", capture_output=True).strip():
continue

# create or update merge request
repository.run_command("git diff")
repository.run_command("git add manifest.toml")
one_of_the_existing_languages = list(
manifest["install"][question][strings_to_translate].keys()
)[0]
Expand All @@ -112,19 +97,18 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
manifest["install"][question][strings_to_translate][
language
].indent(current_identation)
if not repository.run_command("hub pr list -h manifest_toml_i18n", capture_output=True):
repository.run_command(["hub", "pull-request", "-m", "Update translations for manifest.toml", "-b", branch, "-h", "manifest_toml_i18n", "-p", "-m", f"This pull request is automatically generated by scripts from the [YunoHost/apps](https://github.com/YunoHost/apps) repository.\n\nThe translation is pull from weblate and is located here: https://translate.yunohost.org/projects/yunohost-apps/{app}/\n\nIf you wish to modify the translation (other than in english), please do that directly on weblate since this is now the source of authority for it.\n\nDon't hesitate to reach the YunoHost team on [matrix](https://matrix.to/#/#yunohost:matrix.org) if there is any problem :heart:"])

time.sleep(2)
repository.write_file("manifest.toml", tomlkit.dumps(manifest))

if not repository.run_command("git status -s", capture_output=True).strip():
continue

if __name__ == "__main__":
apps = json.load(open("../../builds/default/v3/apps.json"))["apps"]
# create or update merge request
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", f"{WORKING_BRANCH}:manifest_toml_i18n"])

with Repository(
f"https://{login}:{token}@github.com/yunohost/apps_translations", "main"
) as repository:
extract_strings_to_translate_from_apps(apps, repository)
if not repository.run_command(
"hub pr list -h manifest_toml_i18n", capture_output=True
):
Expand All @@ -140,6 +124,25 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
"manifest_toml_i18n",
"-p",
"-m",
f"This pull request is automatically generated by scripts from the [YunoHost/apps](https://github.com/YunoHost/apps) repository.\n\nThe translation is pull from weblate and is located here: https://translate.yunohost.org/projects/yunohost-apps/{app}/\n\nIf you wish to modify the translation (other than in english), please do that directly on weblate since this is now the source of authority for it.\n\nDon't hesitate to reach the YunoHost team on [matrix](https://matrix.to/#/#yunohost:matrix.org) if there is any problem :heart:",
"This pull request is automatically generated by scripts from the "
"[YunoHost/apps](https://github.com/YunoHost/apps) repository.\n\n"
"The translation is pull from weblate and is located here: "
f"https://translate.yunohost.org/projects/yunohost-apps/{app}/\n\n"
"If you wish to modify the translation (other than in english), please do "
"that directly on weblate since this is now the source of authority for it."
"\n\nDon't hesitate to reach the YunoHost team on "
"[matrix](https://matrix.to/#/#yunohost:matrix.org) if there is any "
"problem :heart:",
]
)

time.sleep(2)


if __name__ == "__main__":
apps = json.load(open("../../builds/default/v3/apps.json"))["apps"]

with Repository(
f"https://{login}:{token}@github.com/yunohost/apps_translations", "main"
) as repository:
extract_strings_to_translate_from_apps(apps, repository)
18 changes: 8 additions & 10 deletions tools/translate_apps/push_or_update_apps_on_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
)
translations_repository.run_command(["git", "push"])

if newly_created_translation or not get_weblate_component(weblate, f"yunohost-apps/{app}"):
if newly_created_translation or not get_weblate_component(
weblate, f"yunohost-apps/{app}"
):
print("Creating component on weblate...")
weblate.create_component(
"yunohost-apps",
name=app,
slug=app,
if newly_created_translation or not get_weblate_component(
weblate, f"yunohost-apps/{app}"
):
filemask=f"translations/apps/{app}/*.json",
file_format="json",
filemask=f"translations/apps/{app}/manifest/*.json",
repo="https://github.com/yunohost/apps_translations",
new_base=f"translations/apps/{app}/en.json",
template=f"translations/apps/{app}/en.json",
new_base=f"translations/apps/{app}/manifest/en.json",
template=f"translations/apps/{app}/manifest/en.json",
push="[email protected]:yunohost/apps_translations.git",
)
print(f"Component created at https://translate.yunohost.org/projects/yunohost-apps/{app}/")
Expand All @@ -149,9 +149,7 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):


if __name__ == "__main__":
print(
f"Component created at https://translate.yunohost.org/projects/yunohost-apps/{app}/"
)
apps = json.load(open("../../builds/default/v3/apps.json"))["apps"]

with Repository(
f"https://{login}:{token}@github.com/yunohost/apps_translations", "main"
Expand Down

0 comments on commit d721ee4

Please sign in to comment.