update
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
from .config import GiteaConfig
|
||||
from .api import GiteaApi
|
||||
|
||||
__all__ = ["GiteaConfig", "GiteaApi"]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,26 @@
|
||||
import giteapy
|
||||
from .config import GiteaConfig
|
||||
|
||||
|
||||
class GiteaApi:
|
||||
|
||||
def __init__(self):
|
||||
self.config = GiteaConfig().configuration
|
||||
|
||||
def admin_gitea_instance(self):
|
||||
return giteapy.AdminApi(giteapy.ApiClient(self.config))
|
||||
|
||||
def repo_gitea_instance(self):
|
||||
return giteapy.RepositoryApi(giteapy.ApiClient(self.config))
|
||||
|
||||
def user_gitea_instance(self):
|
||||
return giteapy.UserApi(giteapy.ApiClient(self.config))
|
||||
|
||||
def org_gitea_instance(self):
|
||||
return giteapy.OrganizationApi(giteapy.ApiClient(self.config))
|
||||
|
||||
def misc_gitea_instance(self):
|
||||
return giteapy.MiscellaneousApi(giteapy.ApiClient(self.config))
|
||||
|
||||
def issue_gitea_instance(self):
|
||||
return giteapy.IssueApi(giteapy.ApiClient(self.config))
|
||||
@@ -0,0 +1,14 @@
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
import giteapy
|
||||
|
||||
# Automatically look for .env in the project root
|
||||
load_dotenv()
|
||||
|
||||
|
||||
class GiteaConfig:
|
||||
def __init__(self):
|
||||
self.configuration = giteapy.Configuration()
|
||||
self.configuration.host = os.getenv("GITEA_HOST")
|
||||
self.configuration.api_key["Authorization"] = os.getenv("GITEA_ACCESS_TOKEN")
|
||||
self.configuration.api_key_prefix["Authorization"] = "Bearer"
|
||||
@@ -0,0 +1,47 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user