Files
bifrost-registry/scripts/main.py
T
2025-05-09 16:16:37 +07:00

48 lines
1.4 KiB
Python

from gitea.api import GiteaApi
from gitea.config import GiteaConfig
import giteapy
import os
import json
def main():
gitea_instance = GiteaApi()
admin_instance = gitea_instance.admin_gitea_instance()
repo_instance = gitea_instance.repo_gitea_instance()
# Parameters
owner = "CDN" # Owner of the repository
repo = "bifrost-registry" # Repository name
release_id = 8845 # The ID of the release to attach to
attachment_path = (
"/root/dev/Bifrost/registry/registry.zip" # Path to the file you want to upload
)
get_release_response = repo_instance.repo_get_release(
owner=owner,
repo=repo,
id=release_id, # Release ID
)
assets = get_release_response.assets
attachment_id = None
for asset in assets:
if asset.name == "registry.zip":
attachment_id = asset.id
repo_instance.repo_delete_release_attachment(
owner=owner,
repo=repo,
id=release_id, # Release ID
attachment_id=attachment_id,
)
create_response = repo_instance.repo_create_release_attachment(
owner=owner,
repo=repo,
id=release_id, # Release ID
attachment=attachment_path,
name=os.path.basename(attachment_path), # Filename for the attachment
)
print(create_response)
if __name__ == "__main__":
main()