mirror of
https://github.com/YunoHost/apps.git
synced 2024-09-03 20:06:07 +02:00
fix(translate_apps): testing branch existance needed to be checked before cloning
This commit is contained in:
parent
b5771aeefc
commit
20c65d0d22
3 changed files with 33 additions and 24 deletions
|
@ -5,7 +5,7 @@ from pathlib import Path
|
||||||
|
|
||||||
import tomlkit
|
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):
|
def extract_strings_to_translate_from_apps(apps, translations_repository):
|
||||||
|
@ -39,13 +39,15 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
|
||||||
|
|
||||||
translations_path = translations_repository.path / translations_path
|
translations_path = translations_repository.path / translations_path
|
||||||
|
|
||||||
|
if "testing" in get_repository_branches(repository_uri, token):
|
||||||
|
branch = "testing"
|
||||||
|
|
||||||
with Repository(
|
with Repository(
|
||||||
f"https://{login}:{token}@github.com/{repository_uri}", branch
|
f"https://{login}:{token}@github.com/{repository_uri}", branch
|
||||||
) as repository:
|
) as repository:
|
||||||
if not repository.file_exists("manifest.toml"):
|
if not repository.file_exists("manifest.toml"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if repository.run_command_as_if(["git", "rev-parse", "--verify", "origin/testing"]):
|
|
||||||
repository.run_command(
|
repository.run_command(
|
||||||
[
|
[
|
||||||
"git",
|
"git",
|
||||||
|
@ -53,12 +55,9 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
|
||||||
"-b",
|
"-b",
|
||||||
WORKING_BRANCH,
|
WORKING_BRANCH,
|
||||||
"--track",
|
"--track",
|
||||||
"origin/testing",
|
"origin/{branch}",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
branch = "testing"
|
|
||||||
else:
|
|
||||||
repository.run_command(["git", "checkout", "-b", WORKING_BRANCH])
|
|
||||||
|
|
||||||
manifest = tomlkit.loads(repository.read_file("manifest.toml"))
|
manifest = tomlkit.loads(repository.read_file("manifest.toml"))
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@ import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
from typing import Union
|
from typing import Union
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -24,6 +26,19 @@ my_env["GITHUB_TOKEN"] = token
|
||||||
WORKING_BRANCH = "manifest_toml_i18n"
|
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:
|
class Repository:
|
||||||
def __init__(self, url, branch):
|
def __init__(self, url, branch):
|
||||||
self.url = url
|
self.url = url
|
||||||
|
|
|
@ -7,7 +7,7 @@ from collections import defaultdict
|
||||||
import wlc
|
import wlc
|
||||||
import tomlkit
|
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):
|
def get_weblate_component(weblate, component_path):
|
||||||
|
@ -40,20 +40,15 @@ def extract_strings_to_translate_from_apps(apps, translations_repository):
|
||||||
print("=" * len(app))
|
print("=" * len(app))
|
||||||
print(f"{repository_uri} -> branch '{branch}'")
|
print(f"{repository_uri} -> branch '{branch}'")
|
||||||
|
|
||||||
|
if "testing" in get_repository_branches(repository_uri, token):
|
||||||
|
branch = "testing"
|
||||||
|
|
||||||
with Repository(
|
with Repository(
|
||||||
f"https://{login}:{token}@github.com/{repository_uri}", branch
|
f"https://{login}:{token}@github.com/{repository_uri}", branch
|
||||||
) as repository:
|
) as repository:
|
||||||
if not repository.file_exists("manifest.toml"):
|
if not repository.file_exists("manifest.toml"):
|
||||||
continue
|
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"))
|
manifest = tomlkit.loads(repository.read_file("manifest.toml"))
|
||||||
|
|
||||||
translations_path = Path(f"translations/apps/{app}/manifest/")
|
translations_path = Path(f"translations/apps/{app}/manifest/")
|
||||||
|
|
Loading…
Add table
Reference in a new issue