Skip to content

Commit

Permalink
#patched update version 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ducminhgd committed Dec 17, 2020
1 parent d11f373 commit 785cc03
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 140 deletions.
8 changes: 4 additions & 4 deletions git_operator/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ def bump_version(current: str, major: bool = False, minor: bool = False, patch:
def get_changelog_markdown(ver: str, changelog: Dict) -> str:
changelog_lines = [f'# Release version {ver}', ]

if bool(changelog['Major']):
if bool(changelog.get('Major', [])):
changelog_lines.append('## Major changes')
for line in changelog['Major']:
changelog_lines.append(f'- {line["short_id"]} {line["title"]}')
if bool(changelog['Minor']):
if bool(changelog.get('Minor', [])):
changelog_lines.append('## Minor changes')
for line in changelog['Minor']:
changelog_lines.append(f'- {line["short_id"]} {line["title"]}')
if bool(changelog['Patch']):
if bool(changelog.get('Patch', [])):
changelog_lines.append('## Patches')
for line in changelog['Patch']:
changelog_lines.append(f'- {line["short_id"]} {line["title"]}')
if bool(changelog['Missing']):
if bool(changelog.get('Missing', [])):
changelog_lines.append('## Missing definition')
for line in changelog['Missing']:
changelog_lines.append(f'- {line["short_id"]} {line["title"]}')
Expand Down
62 changes: 20 additions & 42 deletions git_operator/main.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,41 @@
import os
import argparse
from repository import GitLabRepo
from changelog import get_latest_version


def release(service: GitLabRepo, args_ref: str = None):
tags = service.get_tags_as_string()
latest_vname = get_latest_version(list(tags.keys()))
if not bool(tags):
success = service.create_first_release(latest_vname)
exit(1 - int(success))
latest_v = tags[latest_vname]

latest_commit = service.get_commit(latest_v.target)
if not bool(args_ref):
args_ref = 'master'
ref = service.get_commit(args_ref)

if ref is None:
print('Cannot find ref')
exit(0)

diff = service.get_diff(to_ref=ref.id, from_ref=latest_commit.id)

if not bool(diff['commits']):
print('There is no change')
exit(0)
success = service.create_release(ref, latest_vname, diff)
exit(1 - int(success))


def hotfix(service: GitLabRepo, version: str, ref: str = None):
return service.create_hotfix(version, ref)


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Git operator service')
parser.add_argument('service', help='Service name', choices=['gitlab', 'github'])
parser.add_argument('project_id', help='ID of Project', type=int)
parser.add_argument('command', help='Command', choices=['release', 'hotfix'])
parser.add_argument('command', help='Command', choices=['create-branch', 'tag', 'release'])

parser.add_argument('--host', help='Git host', required=False, dest='host', default=os.getenv('GIT_HOST', ''))
parser.add_argument('--token', help='Token for authentication', required=False,
dest='token', default=os.getenv('GIT_PRIVATE_TOKEN', ''))
parser.add_argument('--ref', help='Ref name or commit hash', required=False, dest='ref')
parser.add_argument('--version', help='Version needs hotfixing', required=False, dest='version')
parser.add_argument('--version', help='Desired version', required=False, dest='version')

args = parser.parse_args()
if not bool(args.host):
host = 'https://gitlab.com'
service = GitLabRepo(args.host, args.token)
service.set_project(args.project_id)
success = 0 # Unknown error
if args.command == 'release':
success = release(service, args.ref)

if args.command == 'hotfix':
if not bool(args.version):
parser.error('version is required if command=hotfix')
success = hotfix(service, args.version, args.ref)

exit(1 - int(success))
if not(args.ref):
ref_name = 'master'
else:
ref_name = args.ref

if args.command == 'create-branch' or args.command == 'release':
version, changes_log = service.get_next_version(ref_name, args.version)
if version is None:
exit(1)
success = service.create_version_branch(version, ref_name)
if not success:
exit(1)

if args.command == 'tag' or args.command == 'release':
success = service.create_tag(ref_name, args.version)
if not success:
exit(1)
exit(0)
Loading

0 comments on commit 785cc03

Please sign in to comment.