update
This commit is contained in:
+58
-37
@@ -6,51 +6,72 @@ import json
|
|||||||
from datetime import datetime
|
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():
|
def main():
|
||||||
gitea_instance = GiteaApi()
|
gitea_instance = GiteaApi()
|
||||||
admin_instance = gitea_instance.admin_gitea_instance()
|
admin_instance = gitea_instance.admin_gitea_instance()
|
||||||
repo_instance = gitea_instance.repo_gitea_instance()
|
repo_instance = gitea_instance.repo_gitea_instance()
|
||||||
|
current_file_path = os.path.abspath(__file__)
|
||||||
# Parameters
|
# Parameters
|
||||||
owner = "CDN" # Owner of the repository
|
owner = "CDN"
|
||||||
repo = "bifrost-registry" # Repository name
|
repo = "bifrost-registry"
|
||||||
release_id = 8845 # The ID of the release to attach to
|
release_id = 8845
|
||||||
attachment_path = (
|
attachment_path = os.path.abspath(
|
||||||
"/root/dev/Bifrost/registry/registry.zip" # Path to the file you want to upload
|
os.path.join(os.path.dirname(current_file_path), "..", "registry.zip")
|
||||||
)
|
)
|
||||||
get_release_response = repo_instance.repo_get_release(
|
params = {
|
||||||
owner=owner,
|
"owner": owner,
|
||||||
repo=repo,
|
"repo": repo,
|
||||||
id=release_id, # Release ID
|
"release_id": release_id,
|
||||||
)
|
"attachment_path": attachment_path,
|
||||||
|
}
|
||||||
update_release_response = repo_instance.repo_edit_release(
|
assets = get_release(repo_instance, **params).assets
|
||||||
owner=owner,
|
update_release(repo_instance, **params)
|
||||||
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
|
|
||||||
for asset in assets:
|
for asset in assets:
|
||||||
if asset.name == "registry.zip":
|
if asset.name == "registry.zip":
|
||||||
attachment_id = asset.id
|
params["attachment_id"] = asset.id
|
||||||
repo_instance.repo_delete_release_attachment(
|
delete_release_attachment(repo_instance, **params)
|
||||||
owner=owner,
|
create_release_attachment(repo_instance, **params)
|
||||||
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user