mirror of
https://github.com/YunoHost/yunodevtools.git
synced 2024-09-03 20:16:19 +02:00
refactor(clone_packages): reduce indentation for lisibility (and fix two bugs)
This commit is contained in:
parent
e2d3856dd5
commit
eaf1b3f99e
1 changed files with 49 additions and 50 deletions
|
@ -55,63 +55,62 @@ def generate_mirrors():
|
||||||
if app[0] not in mirror_list:
|
if app[0] not in mirror_list:
|
||||||
print(f"A mirror for '{repo_name}' must be created.")
|
print(f"A mirror for '{repo_name}' must be created.")
|
||||||
|
|
||||||
api_header = {
|
print(f"A mirror for '{repo_name}' must be created.")
|
||||||
"Content-type": "application/json",
|
|
||||||
"Authorization": "{FORGEJO_TOKEN}",
|
|
||||||
}
|
|
||||||
|
|
||||||
create_mirror_data = {
|
api_header = {
|
||||||
"clone_addr": repo_url,
|
"Content-type": "application/json",
|
||||||
"auth_token": GITHUB_TOKEN,
|
"Authorization": "{FORGEJO_TOKEN}",
|
||||||
"mirror": True,
|
}
|
||||||
"repo_name": repo_name,
|
|
||||||
"repo_owner": "YunoHost-Apps",
|
|
||||||
"service": "github",
|
|
||||||
}
|
|
||||||
|
|
||||||
create_mirror = requests.post(
|
create_mirror_data = {
|
||||||
"https://git.yunohost.org/api/v1/repos/migrate",
|
"clone_addr": repo_url,
|
||||||
headers=api_header,
|
"auth_token": GITHUB_TOKEN,
|
||||||
params=f"access_token={FORGEJO_TOKEN}",
|
"mirror": True,
|
||||||
json=create_mirror_data,
|
"repo_name": repo_name,
|
||||||
|
"repo_owner": "YunoHost-Apps",
|
||||||
|
"service": "github",
|
||||||
|
}
|
||||||
|
|
||||||
|
create_mirror = requests.post(
|
||||||
|
"https://git.yunohost.org/api/v1/repos/migrate",
|
||||||
|
headers=api_header,
|
||||||
|
params=f"access_token={FORGEJO_TOKEN}",
|
||||||
|
json=create_mirror_data,
|
||||||
|
)
|
||||||
|
|
||||||
|
if create_mirror.status_code == 409:
|
||||||
|
print(f"A repo named '{repo_name}' is already existing.")
|
||||||
|
continue
|
||||||
|
|
||||||
|
if create_mirror.status_code == 422:
|
||||||
|
print("We're rate limited. Waiting for 1 minute before continuing.")
|
||||||
|
time.sleep(60)
|
||||||
|
|
||||||
|
if create_mirror.status_code not in (201, 422):
|
||||||
|
raise Exception(
|
||||||
|
"Request failed:", create_mirror.status_code, create_mirror.text
|
||||||
)
|
)
|
||||||
|
|
||||||
if create_mirror.status_code != 201:
|
# configuring properly the new repository
|
||||||
if create_mirror.status_code == 409:
|
settings_mirror_data = {
|
||||||
print(f"A repo named '{repo_name}' is already existing.")
|
"has_packages": False,
|
||||||
|
"has_projects": False,
|
||||||
|
"has_releases": False,
|
||||||
|
"has_wiki": False,
|
||||||
|
}
|
||||||
|
|
||||||
if create_mirror.status_code == 422:
|
settings_mirror = requests.patch(
|
||||||
print(
|
f"https://git.yunohost.org/api/v1/repos/YunoHost-Apps/{repo_name}",
|
||||||
f"We're rate limited. Waiting for 1 minute before continuing."
|
headers=api_header,
|
||||||
)
|
params=f"access_token={FORGEJO_TOKEN}",
|
||||||
time.sleep(60)
|
json=settings_mirror_data,
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
if settings_mirror.status_code != 200:
|
||||||
raise Exception(
|
raise Exception("Request failed:", settings_mirror.text)
|
||||||
"Request failed:", create_mirror.status_code, create_mirror.text
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
print("Repository cloned and configured.")
|
||||||
# configuring properly the new repository
|
time.sleep(5) # Sleeping for 5 seconds to cooldown the API
|
||||||
settings_mirror_data = {
|
|
||||||
"has_packages": False,
|
|
||||||
"has_projects": False,
|
|
||||||
"has_releases": False,
|
|
||||||
"has_wiki": False,
|
|
||||||
}
|
|
||||||
|
|
||||||
settings_mirror = requests.patch(
|
|
||||||
f"https://git.yunohost.org/api/v1/repos/YunoHost-Apps/{repo_name}",
|
|
||||||
headers=api_header,
|
|
||||||
params=f"access_token={FORGEJO_TOKEN}",
|
|
||||||
json=settings_mirror_data,
|
|
||||||
)
|
|
||||||
|
|
||||||
if settings_mirror.status_code != 200:
|
|
||||||
raise Exception("Request failed:", settings_mirror.text)
|
|
||||||
else:
|
|
||||||
print("Repository cloned and configured.")
|
|
||||||
time.sleep(5) # Sleeping for 5 seconds to cooldown the API
|
|
||||||
|
|
||||||
|
|
||||||
generate_mirrors()
|
generate_mirrors()
|
||||||
|
|
Loading…
Add table
Reference in a new issue