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

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_branch_types, # get_ignore_commits_exact_words, get_ignore_commits_prefixes, # get_other_branch_type, # get_other_branch_type_key, # get_unreleased, # get_unreleased_key, # get_unreleased_key_label, get_settings, BRANCH_TYPE_OTHER, BRANCH_TYPES, IGNORE_COMMITS_EXACT_WORDS, UNRELEASED, UNRELEASED_LABEL, ) BaseRenderer, HistoricalMarkdownRenderer, MarkdownRenderer, RendererRegistry, RestructuredTextRenderer, ) REGEX_PATTERN_BRANCH_NAME, REGEX_PATTERN_COMMIT, REGEX_PATTERN_COMMIT_LINE, REGEX_PATTERN_MERGED_BRANCH_NAME, REGEX_PATTERN_TAG, )
'generate_changelog', 'generate_changelog_cli', 'get_branch_type', 'get_logs', 'get_repository', 'json_changelog', 'json_changelog_cli', 'make_config_file', 'make_config_file_cli', 'prepare_changelog', 'prepare_releases_changelog', 'validate_between', )
"""Get lots of logs.
:param between: :param path: :return: """ except GitCommandError as err: pass
# Merges log # Note, that ~1 addition make sure the lower range is inclusive "{}~1..{}".format(lower, upper) ) "--pretty={}".format(PRETTY_FORMAT), "--source", # "--all", "--merges", ])
# Commits log # Note, that ~1 addition make sure the lower range is inclusive "{}~1..{}".format(lower, upper) ) "--pretty={}".format(PRETTY_FORMAT), "--source", # "--all" # TODO: remove ])
# Tags log # if lower and upper: # text_log_tags_args.append( # "{}..{}".format(lower, upper) # ) "--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: """
# def generate_empty_tree() -> Dict[str, dict]: # """Generate empty tree. # # Example: # # { # 'feature': {}, # 'bugfix': {}, # 'hotfix': {}, # 'deprecation': {}, # 'other': { # TICKET_NUMBER_OTHER: { # # 'title': '', # 'commits': {} # } # }, # } # # :return: # """ # empty_tree = {} # for key, value in BRANCH_TYPES.items(): # empty_tree.update({key: {}}) # # empty_tree[BRANCH_TYPE_OTHER][TICKET_NUMBER_OTHER] = {'commits': {}} # return empty_tree
between: str = None, unique_commit_messages: bool = False, headings_only: bool = False, unreleased_only: bool = False, fetch_title: bool = False, fetch_description: bool = False, path: str = None ) -> Dict[ str, Dict[str, Dict[str, Union[str, Dict[str, Union[str, str]]]]] ]: """Prepare changelog.
:param between: :param unique_commit_messages: :param headings_only: :param unreleased_only: :param fetch_title: :param fetch_description: :param path: :return: """ # tree = generate_empty_tree()
# First fill feature branches only except json.decoder.JSONDecodeError: continue # TODO: fix this (when commit message contains " symbols)
# 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
(fetch_title or fetch_description) and settings.get('fetchDataFrom') and settings.get('fetchDataFrom') in FetcherRegistry.REGISTRY and ticket_number != TICKET_NUMBER_OTHER ): fetcher_cls = FetcherRegistry.REGISTRY[settings.get('fetchDataFrom')] fetcher = fetcher_cls() fetcher_data = fetcher.fetch_issue_data(ticket_number) if fetch_title: branch_title = fetcher_data['title'] if fetch_description: branch_description = fetcher_data['description']
# For normal tree
'commit_hash': entry['commit_hash'], 'commit_abbr': entry['commit_abbr'], 'date': entry['datetime'], 'ticket_number': ticket_number, 'branch_type': branch_type, 'slug': branch_title, 'title': unslugify(branch_title), 'description': branch_description, '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
continue
if unique_commit_messages \ else entry['commit_hash']
tree[cur_branch_type] = {}
tree[cur_branch_type][cur_branch] = {}
tree[cur_branch_type][cur_branch]['commits'] = {}
'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, } except: # TODO: Anything here? pass else: if BRANCH_TYPE_OTHER not in tree: tree[BRANCH_TYPE_OTHER] = {}
if TICKET_NUMBER_OTHER not in tree[BRANCH_TYPE_OTHER]: tree[BRANCH_TYPE_OTHER][TICKET_NUMBER_OTHER] = {}
if 'commits' not in tree[BRANCH_TYPE_OTHER][TICKET_NUMBER_OTHER]: tree[BRANCH_TYPE_OTHER][TICKET_NUMBER_OTHER]['commits'] = {}
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, headings_only: bool = False, unreleased_only: bool = False, fetch_title: bool = False, fetch_description: bool = False, path: str = None ) -> Dict[ str, Dict[str, Dict[str, Union[str, Dict[str, Union[str, str]]]]] ]: """Prepare releases changelog.
:param between: :param unique_commit_messages: :param headings_only: :param unreleased_only: :param fetch_title: :param fetch_description: :param path: :return: """ # releases = [UNRELEASED] + [tag for tag in logs['COMMIT_TAGS'].values()] # releases_tree = {tag: generate_empty_tree() for tag in releases}
# First fill feature branches only except json.decoder.JSONDecodeError: continue # TODO: fix this (when commit message contains " symbols)
# Skip strange feature branches
# 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
(fetch_title or fetch_description) and settings.get('fetchDataFrom') and settings.get('fetchDataFrom') in FetcherRegistry.REGISTRY and ticket_number != TICKET_NUMBER_OTHER ): fetcher_cls = FetcherRegistry.REGISTRY[settings.get('fetchDataFrom')] fetcher = fetcher_cls() fetcher_data = fetcher.fetch_issue_data(ticket_number) if fetch_title: branch_title = fetcher_data['title'] if fetch_description: branch_description = fetcher_data['description']
# For normal tree
'commit_hash': entry['commit_hash'], 'commit_abbr': entry['commit_abbr'], 'date': entry['datetime'], 'ticket_number': ticket_number, 'branch_type': branch_type, 'slug': branch_title, 'title': unslugify(branch_title), 'description': branch_description, 'commits': {}, 'release': release, }
return {UNRELEASED: releases_tree.get(UNRELEASED, {})}
# Now go through commits except json.decoder.JSONDecodeError: continue # TODO: fix this (when commit message contains " symbols)
# Skip strange feature branches
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
continue
if unique_commit_messages \ else entry['commit_hash']
releases_tree[release] = {}
releases_tree[release][cur_branch_type] = {}
releases_tree[release][cur_branch_type][cur_branch] = {}
releases_tree[release][cur_branch_type][cur_branch]['commits'] = {}
'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 ) releases_tree[release] = {}
'commit_hash': entry['commit_hash'], 'commit_abbr': entry['commit_abbr'], 'author': entry['author'], 'date': entry['datetime'], 'ticket_number': ticket_number, 'title': commit_message, } except: # TODO: Anything here? pass else: if release not in releases_tree: releases_tree[release] = {}
if BRANCH_TYPE_OTHER not in releases_tree[release]: releases_tree[release][BRANCH_TYPE_OTHER] = {}
if TICKET_NUMBER_OTHER not in releases_tree[release][BRANCH_TYPE_OTHER]: releases_tree[release][BRANCH_TYPE_OTHER][TICKET_NUMBER_OTHER] = {}
if 'commits' not in releases_tree[release][BRANCH_TYPE_OTHER][TICKET_NUMBER_OTHER]: releases_tree[release][BRANCH_TYPE_OTHER][TICKET_NUMBER_OTHER]['commits'] = {}
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
# def get_latest_release(path: str = None) -> str: # """Get latest release. # # Command: # # git describe --match '*.*' --abbr=0 # # :return: # """ # repository = get_repository(path) # return repository.describe('--match', '*.*', '--abbr=0')
"""Get latest <limit> releases.
Command:
git tag --sort=-version:refname -l '*.*' | head -n <limit>
:return: """ '--sort=-version:refname', '--list', '*.*' ).split('\n')[:limit]
include_other: bool = True, show_releases: bool = False, latest_release: bool = False, headings_only: bool = False, fetch_title: bool = False, fetch_description: bool = False, path: str = None):
between=between, unique_commit_messages=True, headings_only=headings_only, path=path ) else: between=between, unique_commit_messages=True, headings_only=headings_only, path=path )
"""Generate changelog (JSON 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", ) '--latest-release', dest="latest_release", default=False, action='store_true', help="Generate changelog for the latest release only", ) '--headings-only', dest="headings_only", default=False, action='store_true', help="Generate headings only (no commit messages, only branch titles)", ) '--fetch-title', dest="fetch_title", default=False, action='store_true', help="Fetch title", ) '--fetch-description', dest="fetch_description", default=False, action='store_true', help="Fetch description", )
json_changelog( between=between, include_other=include_other, show_releases=show_releases, latest_release=latest_release, headings_only=headings_only, fetch_title=fetch_title, fetch_description=fetch_description ) )
include_other: bool = True, show_releases: bool = False, latest_release: bool = False, headings_only: bool = False, unreleased_only: bool = False, fetch_title: bool = False, fetch_description: bool = False, renderer_cls: Union[ Type[HistoricalMarkdownRenderer], Type[MarkdownRenderer], Type[RestructuredTextRenderer] ] = MarkdownRenderer, path: str = None) -> str: """Generate changelog (markdown format)."""
# if show_latest_release and between: # raise Exception( # "--show-latest-release can't be used in combination with specific" # "tags/commits/branches range." # )
between=between, unique_commit_messages=True, headings_only=headings_only, unreleased_only=unreleased_only and show_releases, fetch_title=fetch_title, fetch_description=fetch_description, path=path )
tree=tree, include_other=include_other, headings_only=headings_only, fetch_description=fetch_description ) else: between=between, unique_commit_messages=True, headings_only=headings_only, unreleased_only=unreleased_only and show_releases, fetch_title=fetch_title, fetch_description=fetch_description, path=path )
releases_tree=releases_tree, include_other=include_other, headings_only=headings_only, fetch_description=fetch_description )
'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", ) '--latest-release', dest="latest_release", default=False, action='store_true', help="Generate changelog for the latest release only", ) '--headings-only', dest="headings_only", default=False, action='store_true', help="Generate headings only (no commit messages, only branch titles)", ) '--unreleased-only', dest="unreleased_only", default=False, action='store_true', help="Show unreleased only. Works in combination with --show-releases", ) '--fetch-title', dest="fetch_title", default=False, action='store_true', help="Fetch title", ) '--fetch-description', dest="fetch_description", default=False, action='store_true', help="Fetch description", ) '--renderer', dest="renderer", default=MarkdownRenderer.uid, action='store', help="Renderer", choices=list(RendererRegistry.REGISTRY.keys()) )
generate_changelog( between=between, include_other=include_other, show_releases=show_releases, latest_release=latest_release, headings_only=headings_only, unreleased_only=unreleased_only, fetch_title=fetch_title, fetch_description=fetch_description, renderer_cls=renderer_cls ) )
"""Make (or overwrite) config file.
:return: """ except Exception as err: return False
|