This commit is contained in:
2025-05-09 16:38:42 +07:00
parent 9ca58e6e8a
commit 131757ce31
+58 -37
View File
@@ -6,51 +6,72 @@ import json
from datetime import datetime
def update_release(repo_instance, **params):
try:
repo_instance.repo_edit_release(
owner=params["owner"],
repo=params["repo"],
id=params["release_id"], # Release ID
body=giteapy.EditReleaseOption(
name=f"Bifrost Registry {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
),
)
print("Update release success")
except Exception as e:
print(f"Update release failed: {e}")
def get_release(repo_instance, **params):
return repo_instance.repo_get_release(
owner=params["owner"],
repo=params["repo"],
id=params["release_id"], # Release ID
)
def delete_release_attachment(repo_instance, **params):
repo_instance.repo_delete_release_attachment(
owner=params["owner"],
repo=params["repo"],
id=params["release_id"], # Release ID
attachment_id=params["attachment_id"],
)
def create_release_attachment(repo_instance, **params):
repo_instance.repo_create_release_attachment(
owner=params["owner"],
repo=params["repo"],
id=params["release_id"], # Release ID
attachment=params["attachment_path"],
)
def main():
gitea_instance = GiteaApi()
admin_instance = gitea_instance.admin_gitea_instance()
repo_instance = gitea_instance.repo_gitea_instance()
current_file_path = os.path.abspath(__file__)
# 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
owner = "CDN"
repo = "bifrost-registry"
release_id = 8845
attachment_path = os.path.abspath(
os.path.join(os.path.dirname(current_file_path), "..", "registry.zip")
)
get_release_response = repo_instance.repo_get_release(
owner=owner,
repo=repo,
id=release_id, # Release ID
)
update_release_response = repo_instance.repo_edit_release(
owner=owner,
repo=repo,
id=release_id, # Release ID
body=giteapy.EditReleaseOption(
name=f"Bifrost Registry {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
),
)
assets = get_release_response.assets
attachment_id = None
params = {
"owner": owner,
"repo": repo,
"release_id": release_id,
"attachment_path": attachment_path,
}
assets = get_release(repo_instance, **params).assets
update_release(repo_instance, **params)
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)
params["attachment_id"] = asset.id
delete_release_attachment(repo_instance, **params)
create_release_attachment(repo_instance, **params)
if __name__ == "__main__":