Files
dsk-version-management/dashboard/settings.py
dsk-minchulahn 23d373a903 Add git config
2023-08-16 15:55:17 +09:00

68 lines
2.0 KiB
Python

import json, requests, os
from git import Repo
repo = Repo('.')
file_path = './version.json'
api_url = 'https://api.github.com/repos/cloudmoa/sample-app/releases'
github_token = os.environ.get('GITHUB_TOKEN')
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():
return repo.tags
def get_github_releases():
headers = {'Authorization': f'Bearer {github_token}', 'Accept': 'application/vnd.github.v3+json'}
releases = requests.get(api_url, headers=headers).json()
return releases
def get_user_name_list():
users = ['', 'dsk-minchulahn', 'Ose-Exem', 'deukjin', 'pparkssi3']
return users
def set_git_config(username):
repo.config_writer().set_value('user', 'name', username).release()
repo.config_writer().set_value('user', 'email', 'minchulahn@ex-em.com').release()
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):
headers = {'Authorization': f'Bearer {github_token}', 'Accept': 'application/vnd.github.v3+json'}
release_data = {
'tag_name': selected_tag,
'name': release_title,
'body': release_describe,
'draft': False,
'prerelease': False
}
return requests.post(api_url, json=release_data, headers=headers)