Skip to content

Commit

Permalink
fix(translate_apps): testing branch existance needed to be checked be…
Browse files Browse the repository at this point in the history
…fore cloning
  • Loading branch information
Psycojoker authored and Salamandar committed Sep 14, 2024
1 parent 66c968e commit ac41950
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
29 changes: 14 additions & 15 deletions translate_apps/apps_translations_to_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import tomlkit

from base import Repository, login, token, WORKING_BRANCH
from base import Repository, login, token, WORKING_BRANCH, get_repository_branches


def extract_strings_to_translate_from_apps(apps, translations_repository):
Expand Down Expand Up @@ -39,26 +39,25 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):

translations_path = translations_repository.path / translations_path

if "testing" in get_repository_branches(repository_uri, token):
branch = "testing"

with Repository(
f"https://{login}:{token}@github.com/{repository_uri}", branch
) as 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",
]
)
branch = "testing"
else:
repository.run_command(["git", "checkout", "-b", WORKING_BRANCH])
repository.run_command(
[
"git",
"checkout",
"-b",
WORKING_BRANCH,
"--track",
"origin/{branch}",
]
)

manifest = tomlkit.loads(repository.read_file("manifest.toml"))

Expand Down
15 changes: 15 additions & 0 deletions translate_apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import tempfile
import subprocess

import requests

from typing import Union
from pathlib import Path

Expand All @@ -24,6 +26,19 @@
WORKING_BRANCH = "manifest_toml_i18n"


def get_repository_branches(repository, token):
branches = requests.get(
f"https://api.github.com/repos/{repository}/branches",
headers={
"Authorization": f"Bearer {token}",
"X-GitHub-Api-Version": "2022-11-28",
"Accept": "application/vnd.github+json",
},
).json()

return {x["name"] for x in branches}


class Repository:
def __init__(self, url, branch):
self.url = url
Expand Down
13 changes: 4 additions & 9 deletions translate_apps/push_or_update_apps_on_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import wlc
import tomlkit

from base import Repository, login, token, weblate_token
from base import Repository, login, token, weblate_token, get_repository_branches


def get_weblate_component(weblate, component_path):
Expand Down Expand Up @@ -40,20 +40,15 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
print("=" * len(app))
print(f"{repository_uri} -> branch '{branch}'")

if "testing" in get_repository_branches(repository_uri, token):
branch = "testing"

with Repository(
f"https://{login}:{token}@github.com/{repository_uri}", branch
) as 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/")
Expand Down

0 comments on commit ac41950

Please sign in to comment.