Skip to content

Commit 6313439

Browse files
committed
fix(translate_apps): testing branch existance needed to be checked before cloning
1 parent 530e13a commit 6313439

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

tools/translate_apps/apps_translations_to_apps.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import tomlkit
77

8-
from base import Repository, login, token, WORKING_BRANCH
8+
from base import Repository, login, token, WORKING_BRANCH, get_repository_branches
99

1010

1111
def extract_strings_to_translate_from_apps(apps, translations_repository):
@@ -39,26 +39,25 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
3939

4040
translations_path = translations_repository.path / translations_path
4141

42+
if "testing" in get_repository_branches(repository_uri, token):
43+
branch = "testing"
44+
4245
with Repository(
4346
f"https://{login}:{token}@github.com/{repository_uri}", branch
4447
) as repository:
4548
if not repository.file_exists("manifest.toml"):
4649
continue
4750

48-
if repository.run_command_as_if(["git", "rev-parse", "--verify", "origin/testing"]):
49-
repository.run_command(
50-
[
51-
"git",
52-
"checkout",
53-
"-b",
54-
WORKING_BRANCH,
55-
"--track",
56-
"origin/testing",
57-
]
58-
)
59-
branch = "testing"
60-
else:
61-
repository.run_command(["git", "checkout", "-b", WORKING_BRANCH])
51+
repository.run_command(
52+
[
53+
"git",
54+
"checkout",
55+
"-b",
56+
WORKING_BRANCH,
57+
"--track",
58+
"origin/{branch}",
59+
]
60+
)
6261

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

tools/translate_apps/base.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import tempfile
33
import subprocess
44

5+
import requests
6+
57
from typing import Union
68
from pathlib import Path
79

@@ -24,6 +26,19 @@
2426
WORKING_BRANCH = "manifest_toml_i18n"
2527

2628

29+
def get_repository_branches(repository, token):
30+
branches = requests.get(
31+
f"https://api.github.com/repos/{repository}/branches",
32+
headers={
33+
"Authorization": f"Bearer {token}",
34+
"X-GitHub-Api-Version": "2022-11-28",
35+
"Accept": "application/vnd.github+json",
36+
},
37+
).json()
38+
39+
return {x["name"] for x in branches}
40+
41+
2742
class Repository:
2843
def __init__(self, url, branch):
2944
self.url = url

tools/translate_apps/push_or_update_apps_on_repository.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import wlc
88
import tomlkit
99

10-
from base import Repository, login, token, weblate_token
10+
from base import Repository, login, token, weblate_token, get_repository_branches
1111

1212

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

43+
if "testing" in get_repository_branches(repository_uri, token):
44+
branch = "testing"
45+
4346
with Repository(
4447
f"https://{login}:{token}@github.com/{repository_uri}", branch
4548
) as repository:
4649
if not repository.file_exists("manifest.toml"):
4750
continue
4851

49-
# base our work on the testing branch if it exists
50-
if repository.run_command_as_if(
51-
["git", "rev-parse", "--verify", "origin/testing"]
52-
):
53-
repository.run_command(
54-
["git", "checkout", "-b", "testing", "--track", "origin/testing"]
55-
)
56-
5752
manifest = tomlkit.loads(repository.read_file("manifest.toml"))
5853

5954
translations_path = Path(f"translations/apps/{app}/manifest/")

0 commit comments

Comments
 (0)