45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
import gitea as gt
|
|
import os
|
|
import subprocess
|
|
import shutil
|
|
|
|
class BadEncodingException(Exception):
|
|
pass
|
|
|
|
class CloneException(Exception):
|
|
pass
|
|
|
|
TOKEN = os.environ['TOKEN']
|
|
|
|
gitea = gt.Gitea("https://gitea.seeseepuff.be", TOKEN)
|
|
org = gt.Organization.request(gitea, "archlinux")
|
|
workDir = "./work/"
|
|
|
|
def main() -> None:
|
|
repositories = org.get_repositories()
|
|
for repository in repositories:
|
|
print(repository.get_full_name())
|
|
|
|
try:
|
|
# Check if the repository has a PKGBUILD file.
|
|
# If it does, clone it.
|
|
metadata = gitea.requests_get(f"/repos/{repository.owner.username}/{repository.name}/contents/PKGBUILD")
|
|
# Empty repositories will just return an empty dict.
|
|
if metadata == {}:
|
|
continue
|
|
|
|
clone_repository(repository)
|
|
except gt.NotFoundException:
|
|
print("PKGBUILD not found")
|
|
continue
|
|
|
|
def clone_repository(repository: gt.Repository) -> None:
|
|
process = subprocess.Popen(["git", "clone", repository.clone_url, f"{workDir}{repository.name}"])
|
|
result = process.wait()
|
|
if result != 0:
|
|
raise CloneException(f"Failed to clone {repository.name}")
|
|
|
|
if __name__ == "__main__":
|
|
shutil.rmtree(workDir, ignore_errors=True)
|
|
os.makedirs(workDir, exist_ok=True)
|
|
main() |