Initial autobuilder work
This commit is contained in:
commit
5899d3baa6
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/venv
|
||||||
|
/.env
|
||||||
|
/work
|
46
autobuilder.py
Normal file
46
autobuilder.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import gitea as gt
|
||||||
|
import os
|
||||||
|
import base64
|
||||||
|
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()
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
py-gitea
|
Loading…
x
Reference in New Issue
Block a user