Coverage for /home/delusionalinsanity/bbrepos/matyan/src/matyan/utils.py : 75%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
get_all_branch_types, get_other_branch_type, get_branch_types, get_unreleased, get_other_branch_type_key, get_unreleased_key, get_unreleased_key_label, get_ignore_commits_exact_words, ) REGEX_PATTERN_BRANCH_NAME, REGEX_PATTERN_MERGED_BRANCH_NAME, REGEX_PATTERN_COMMIT, REGEX_PATTERN_COMMIT_LINE, REGEX_PATTERN_TAG, )
'create_config_file', 'generate_changelog_cli', 'generate_empty_tree', 'get_branch_type', 'get_logs', 'json_changelog_cli', 'prepare_changelog', 'prepare_releases_changelog', 'validate_between', )
'"commit_hash": "%H", ' \ '"commit_abbr": "%h", ' \ '"datetime": "%ci", ' \ '"title": "%s",' \ '"author": "%an", ' \ '"author_email": "%ae", ' \ '"merge": "%P"' \ '}'
# BRANCH_TYPES = { # 'other': "Other", # 'feature': "Features", # 'bugfix': "Bugfixes", # 'hotfix': "Hotfixes", # 'deprecation': "Deprecations", # } # UNRELEASED = 'unreleased'
"""Get lots of logs.
:param between: :return: """ try: rev_list_text = REPOSITORY.rev_list(between) rev_list = rev_list_text.split('\n') if len(rev_list) >= 2: upper = rev_list[0] lower = rev_list[-1] except GitCommandError as err: pass
# Merges log text_log_merges_args.append( "{}..{}".format(lower, upper) ) "--pretty={}".format(PRETTY_FORMAT), "--source", # "--all", "--merges", ])
# Commits log text_log_args.append( "{}..{}".format(lower, upper) ) "--pretty={}".format(PRETTY_FORMAT), "--source", # "--all" # TODO: remove ])
# Tags log "--tags", "--source", "--oneline" )
'TEXT_LOG_MERGES': text_log_merges, 'LOG_MERGES': log_merges, 'TEXT_LOG': text_log, 'LOG': log, 'TEXT_LOG_TAGS': text_log_tags, 'LOG_TAGS': log_tags, 'COMMIT_TAGS': commit_tags, }
"""Get branch type.
:param branch_type: :return: """
"""Generate empty tree.
Example:
{ 'feature': {}, 'bugfix': {}, 'hotfix': {}, 'deprecation': {}, 'other': { TICKET_NUMBER_OTHER: { # 'title': '', 'commits': {} } }, }
:return: """
between: str = None, unique_commit_messages: bool = False ) -> Dict[ str, Dict[str, Dict[str, Union[str, Dict[str, Union[str, str]]]]] ]: """Prepare changelog.
:param between: :param unique_commit_messages: :return: """
# First fill feature branches only
# Skip strange feature branches continue
# If no pattern found, use other branch except AttributeError: branch_type = BRANCH_TYPE_OTHER
# If no pattern found, use other ticket number except AttributeError: ticket_number = TICKET_NUMBER_OTHER
# For normal tree 'commit_hash': entry['commit_hash'], 'commit_abbr': entry['commit_abbr'], 'ticket_number': ticket_number, 'branch_type': branch_type, 'slug': branch_title, 'title': branch_title.replace('-', ' ').title(), 'commits': {}, 'release': release, }
# Now go through commits except json.decoder.JSONDecodeError: continue # TODO: fix this (when commit message contains " symbols)
# Skip strange feature branches continue
except AttributeError: branch_type = BRANCH_TYPE_OTHER
except AttributeError: ticket_number = TICKET_NUMBER_OTHER
else: except AttributeError: ticket_number = '' commit_message = entry['title'][:]
# Ignore the following messages continue
if unique_commit_messages \ else entry['commit_hash']
'commit_hash': entry['commit_hash'], 'commit_abbr': entry['commit_abbr'], 'author': entry['author'], 'date': entry['datetime'], 'ticket_number': ticket_number, 'title': commit_message, } else: ticket_number, BRANCH_TYPE_OTHER ) 'commit_hash': entry['commit_hash'], 'commit_abbr': entry['commit_abbr'], 'author': entry['author'], 'date': entry['datetime'], 'ticket_number': ticket_number, 'title': commit_message, } # TODO: Anything here? else: tree[BRANCH_TYPE_OTHER][TICKET_NUMBER_OTHER]['commits'][commit_hash] = { # NOQA 'commit_hash': entry['commit_hash'], 'commit_abbr': entry['commit_abbr'], 'author': entry['author'], 'date': entry['datetime'], 'ticket_number': ticket_number, 'title': commit_message, }
between: str = None, unique_commit_messages: bool = False ) -> Dict[ str, Dict[str, Dict[str, Union[str, Dict[str, Union[str, str]]]]] ]: """Prepare releases changelog.
:param between: :param unique_commit_messages: :return: """
# First fill feature branches only
# Skip strange feature branches continue
# If no pattern found, use other branch except AttributeError: branch_type = BRANCH_TYPE_OTHER
# If no pattern found, use other ticket number except AttributeError: ticket_number = TICKET_NUMBER_OTHER
# For normal tree release = UNRELEASED
'commit_hash': entry['commit_hash'], 'commit_abbr': entry['commit_abbr'], 'ticket_number': ticket_number, 'branch_type': branch_type, 'slug': branch_title, 'title': branch_title.replace('-', ' ').title(), 'commits': {}, 'release': release, }
# Now go through commits except json.decoder.JSONDecodeError: continue # TODO: fix this (when commit message contains " symbols)
# Skip strange feature branches continue
except AttributeError: branch_type = BRANCH_TYPE_OTHER
except AttributeError: ticket_number = TICKET_NUMBER_OTHER
else: except AttributeError: ticket_number = '' commit_message = entry['title'][:]
# Ignore the following messages continue
if unique_commit_messages \ else entry['commit_hash']
release = UNRELEASED
'commit_hash': entry['commit_hash'], 'commit_abbr': entry['commit_abbr'], 'author': entry['author'], 'date': entry['datetime'], 'ticket_number': ticket_number, 'title': commit_message, } else: ticket_number, BRANCH_TYPE_OTHER ) 'commit_hash': entry['commit_hash'], 'commit_abbr': entry['commit_abbr'], 'author': entry['author'], 'date': entry['datetime'], 'ticket_number': ticket_number, 'title': commit_message, } # TODO: Anything here? else: releases_tree[release][BRANCH_TYPE_OTHER][TICKET_NUMBER_OTHER]['commits'][commit_hash] = { # NOQA 'commit_hash': entry['commit_hash'], 'commit_abbr': entry['commit_abbr'], 'author': entry['author'], 'date': entry['datetime'], 'ticket_number': ticket_number, 'title': commit_message, }
"""Validate between.
:param between: :return: """ pass # TODO
"""Generate changelog (JSON format).""" parser = argparse.ArgumentParser(description='Generate JSON changelog') parser.add_argument( 'between', nargs='?', default=None, help="Range, might be tag or a commit or a branch.", ) parser.add_argument( '--no-other', dest="no_other", default=False, action='store_true', help="No `Other` section", ) parser.add_argument( '--show-releases', dest="show_releases", default=False, action='store_true', help="Show releases", ) args = parser.parse_args(sys.argv[1:]) between = args.between if validate_between(args.between) else None include_other = not args.no_other show_releases = args.show_releases
if not show_releases: tree = prepare_changelog( between=between, unique_commit_messages=True ) pprint(tree) else: releases_tree = prepare_releases_changelog( between=between, unique_commit_messages=True ) pprint(releases_tree)
# if not include_other: # tree.pop(BRANCH_TYPE_OTHER) # pprint(tree)
"""Generate changelog (markdown format).""" 'between', nargs='?', default=None, help="Range, might be tag or a commit or a branch.", ) '--no-other', dest="no_other", default=False, action='store_true', help="No `Other` section", ) '--show-releases', dest="show_releases", default=False, action='store_true', help="Show releases", ) '--output-file', dest="show_releases", default=False, action='store_true', help="Show releases", )
between=between, unique_commit_messages=True ) # Skip adding orphaned commits if explicitly asked not to. continue
# Do not add branch type if no related branches found
# Add tickets "\n*{} {}*\n".format(ticket_number, ticket_data['title']) ) else:
"- {} [{}]".format( commit_data['title'], commit_data['author'] ) ) else: between=between, unique_commit_messages=True ) if release == UNRELEASED \ else release
# Skip adding orphaned commits if explicitly asked not to. continue
# Do not add branch type if no related branches found "\n**{}**".format(BRANCH_TYPES.get(branch_type)))
# Add tickets "\n*{} {}*\n".format(ticket_number, ticket_data['title']) ) else:
"- {} [{}]".format( commit_data['title'], commit_data['author'] ) )
"""Create config file.
:return: """ source_filename = project_dir('.matyan.ini') dest_filename = os.path.join(os.getcwd(), '.matyan.ini') try: copyfile(source_filename, dest_filename) return True except Exception as err: return False
return not create_config_file() |