89 lines
2.9 KiB
Python
89 lines
2.9 KiB
Python
import os, json, requests, subprocess
|
|
from datetime import datetime, timedelta
|
|
from git import Repo
|
|
|
|
repo = Repo('.')
|
|
file_path = './version.json'
|
|
release_url = 'https://api.github.com/repos/cloudmoa/dsk-version-management/releases'
|
|
delivery_url = 'https://api.github.com/repos/CloudMOA/dsk-version-management/hooks/412710389/deliveries'
|
|
github_token = os.environ.get('GITHUB_TOKEN')
|
|
headers = {'Authorization': f"Bearer {github_token}", 'Accept': 'application/vnd.github.v3+json'}
|
|
|
|
def get_datasaker():
|
|
return json.load(open(file_path, 'r'))['datasaker']
|
|
|
|
def get_service():
|
|
return json.load(open(file_path, 'r'))['service']
|
|
|
|
def get_commit_id():
|
|
return repo.head.commit
|
|
|
|
def get_tags():
|
|
latest_tags = sorted(repo.tags, key=lambda t: t.commit.committed_date, reverse=True)
|
|
return latest_tags
|
|
|
|
def get_releases():
|
|
releases = requests.get(release_url, headers=headers).json()
|
|
return releases
|
|
|
|
def get_delivery():
|
|
return requests.get(delivery_url, headers=headers).json()
|
|
|
|
def get_user_name_list():
|
|
users = ['', 'dsk-minchulahn', 'Ose-Exem', 'deukjin', 'pparkssi3']
|
|
return users
|
|
|
|
def get_user_email(username):
|
|
if username == 'dsk-minchulahn': return 'minchulahn@ex-em.com'
|
|
elif username == 'Ose-Exem': return 'ose@ex-em.com'
|
|
elif username == 'deukjin': return 'djkim@ex-em.com'
|
|
elif username == 'pparkssi3': return 'pparkssi@ex-em.com'
|
|
else: return ''
|
|
|
|
def set_git_config(username, email):
|
|
subprocess.run(["git", "config", "--global", "user.name", username], check=True)
|
|
subprocess.run(["git", "config", "--global", "user.email", email], check=True)
|
|
|
|
def diff():
|
|
if len(repo.index.diff(repo.head.commit)) > 0:
|
|
return True
|
|
return False
|
|
|
|
def diff_remote_head():
|
|
repo.remote().fetch()
|
|
remote_head = repo.remote().refs['main'].commit
|
|
|
|
if repo.head.commit == remote_head:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def git_pull():
|
|
repo.remote().fetch()
|
|
repo.remotes.origin.pull()
|
|
|
|
def git_push(commit_message, extended_description):
|
|
repo.git.add('version.json')
|
|
|
|
if len(repo.index.diff(repo.head.commit)) > 0:
|
|
repo.index.commit(f"{commit_message}\n\n{extended_description}")
|
|
repo.git.push(force=False)
|
|
|
|
def publish_release(selected_tag, release_title, release_describe):
|
|
publish_release_data = {
|
|
'tag_name': selected_tag,
|
|
'name': release_title,
|
|
'body': release_describe,
|
|
'draft': False,
|
|
'prerelease': False
|
|
}
|
|
return requests.post(release_url, json=publish_release_data, headers=headers)
|
|
|
|
def redeliver(delivery_id):
|
|
redeliver_url = f"{delivery_url}/{delivery_id}/attempts"
|
|
return requests.post(redeliver_url, headers=headers)
|
|
|
|
def convert_utc_to_korea_time(utc_time_str):
|
|
utc_time = datetime.fromisoformat(utc_time_str[:-1])
|
|
korea_time = utc_time + timedelta(hours=9)
|
|
return korea_time.strftime("%Y-%m-%d %H:%M:%S") |