Raxen/scripts/git_release.py
2023-04-25 19:49:51 +02:00

47 lines
No EOL
1.9 KiB
Python

import os
import argparse
import giteapy
from giteapy.rest import ApiException
parser = argparse.ArgumentParser(description="publish to git.unurled.me the release.")
parser.add_argument('--token', type=str, help="a token which have sufficient permission")
parser.add_argument('--message', type=str)
parser.add_argument('--prerelease', type=bool)
parser.add_argument('--tag', type=str)
args = parser.parse_args()
doc = vars(args)
print(doc)
configuration = giteapy.Configuration()
configuration.api_key['access_token'] = doc['token']
configuration.host = 'https://git.unurled.me/api/v1'
api_instance = giteapy.RepositoryApi(giteapy.ApiClient(configuration))
owner = "Elixium"
repo = "Raxen"
body = giteapy.CreateReleaseOption(body=doc['message'], draft=False, name=doc['tag'], prerelease=doc['prerelease'], tag_name=doc['tag'], target_commitish="string")
attachments = []
for file in os.listdir(os.getcwd() +"../build/libs"):
if file.endswith('.jar'):
if file.startswith('raxen'):
attachments.append(os.getcwd() + '../build/libs/' + file)
print(attachments)
attachment1 = attachments[0]
attachment2 = attachments[1]
attachment3 = attachments[2]
name1 = attachments[0].split("libs/")[1]
name2 = attachments[1].split("libs/")[1]
name3 = attachments[2].split("libs/")[1]
try:
# Create a release
api_response = api_instance.repo_create_release(owner, repo, body=body)
print(api_response.id)
attachement_response = api_instance.repo_create_release_attachment(owner, repo, api_response.id, attachment=attachment1, name=name1)
attachement_response = api_instance.repo_create_release_attachment(owner, repo, api_response.id, attachment=attachment2, name=name2)
attachement_response = api_instance.repo_create_release_attachment(owner, repo, api_response.id, attachment=attachment3, name=name3)
print(attachement_response)
except ApiException as e:
print("Exception when calling RepositoryApi->repo_create_release: %s\n" % e)