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
|
||||
|
||||
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):
|
||||
|
@ -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"))
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ import os
|
|||
import tempfile
|
||||
import subprocess
|
||||
|
||||
import requests
|
||||
|
||||
from typing import Union
|
||||
from pathlib import Path
|
||||
|
||||
|
@ -24,6 +26,19 @@ my_env["GITHUB_TOKEN"] = token
|
|||
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
|
||||
|
|
|
@ -7,7 +7,7 @@ from collections import defaultdict
|
|||
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):
|
||||
|
@ -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/")
|
||||
|
|
Loading…
Add table
Reference in a new issue