Skip to content

Commit

Permalink
[changelog] An option to show only merge commits. (#297)
Browse files Browse the repository at this point in the history
* [capability][changelog] An option to show only merge commits.

Cleaner logic (address https://github.com/plusone-robotics/catkin_pkg/pull/1/files#r454458598, and https://github.com/ros-infrastructure/catkin_pkg/pull/297/files#r496031733).

* [gen_changelog] Handling mutually exclusive args.
[gen_changelog] Replace custom logic with add_mutually_exclusive_group (address #297 (comment)).
  • Loading branch information
130s authored Sep 29, 2020
1 parent 0660801 commit db9f907
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/catkin_pkg/changelog_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@
FORTHCOMING_LABEL = 'Forthcoming'


def get_all_changes(vcs_client, skip_merges=False):
def get_all_changes(vcs_client, skip_merges=False, only_merges=False):
tags = _get_version_tags(vcs_client)

# query all log entries per tag range
tag2log_entries = {}
previous_tag = Tag(None)
for tag in sorted_tags(tags):
log_entries = vcs_client.get_log_entries(
from_tag=previous_tag.name, to_tag=tag.name, skip_merges=skip_merges)
from_tag=previous_tag.name, to_tag=tag.name, skip_merges=skip_merges, only_merges=only_merges)
tag2log_entries[previous_tag] = log_entries
previous_tag = tag
log_entries = vcs_client.get_log_entries(
from_tag=previous_tag.name, to_tag=None, skip_merges=skip_merges)
from_tag=previous_tag.name, to_tag=None, skip_merges=skip_merges, only_merges=only_merges)
tag2log_entries[previous_tag] = log_entries
return tag2log_entries


def get_forthcoming_changes(vcs_client, skip_merges=False):
def get_forthcoming_changes(vcs_client, skip_merges=False, only_merges=False):
tags = _get_version_tags(vcs_client)
latest_tag_name = _get_latest_version_tag_name(vcs_client)

Expand All @@ -79,7 +79,7 @@ def get_forthcoming_changes(vcs_client, skip_merges=False):
# ignore non-forthcoming log entries but keep version to identify injection point of forthcoming
tag2log_entries[tag] = None
log_entries = vcs_client.get_log_entries(
from_tag=from_tag.name, to_tag=to_tag.name, skip_merges=skip_merges)
from_tag=from_tag.name, to_tag=to_tag.name, skip_merges=skip_merges, only_merges=only_merges)
tag2log_entries[from_tag] = log_entries
return tag2log_entries

Expand Down
10 changes: 7 additions & 3 deletions src/catkin_pkg/changelog_generator_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get_tags(self):
def get_latest_tag_name(self):
raise NotImplementedError()

def get_log_entries(self, from_tag, to_tag, skip_merges=False):
def get_log_entries(self, from_tag, to_tag, skip_merges=False, only_merges=False):
raise NotImplementedError()

def replace_repository_references(self, line):
Expand Down Expand Up @@ -179,14 +179,18 @@ def get_latest_tag_name(self):
tag_name = result_describe['output']
return tag_name

def get_log_entries(self, from_tag, to_tag, skip_merges=False):
def get_log_entries(self, from_tag, to_tag, skip_merges=False, only_merges=False):
# query all hashes in the range
cmd = [self._executable, 'log']
if from_tag or to_tag:
cmd.append('%s%s' % ('%s..' % to_tag if to_tag else '', from_tag if from_tag else ''))
cmd.append('--format=format:%H')
if skip_merges and only_merges:
raise RuntimeError('Both "skip_merges" and "only_merges" are set to True, which contradicts.')
if skip_merges:
cmd.append('--no-merges')
if only_merges:
cmd.append('--merges')
result = self._run_command(cmd)
if result['returncode']:
raise RuntimeError('Could not fetch commit hashes:\n%s' % result['output'])
Expand Down Expand Up @@ -348,7 +352,7 @@ def get_latest_tag_name(self):
raise RuntimeError('Could not find latest tagn')
return tag_name

def get_log_entries(self, from_tag, to_tag, skip_merges=False):
def get_log_entries(self, from_tag, to_tag, skip_merges=False, only_merges=False):
# query all hashes in the range
# ascending chronological order since than it is easier to handle empty tag names
revrange = '%s:%s' % ((to_tag if to_tag else ''), (from_tag if from_tag else 'tip'))
Expand Down
14 changes: 9 additions & 5 deletions src/catkin_pkg/cli/generate_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,20 @@ def prompt_continue(msg, default):

def main(sysargs=None):
parser = argparse.ArgumentParser(description='Generate a REP-0132 %s' % CHANGELOG_FILENAME)
group_merge = parser.add_mutually_exclusive_group()
parser.add_argument(
'-a', '--all', action='store_true', default=False,
help='Generate changelog for all versions instead of only the forthcoming one (only supported when no changelog file exists yet)')
group_merge.add_argument(
'--only-merges', action='store_true', default=False,
help='Only add merge commits to the changelog')
parser.add_argument(
'--print-root', action='store_true', default=False,
help='Output changelog content to the console as if there would be only one package in the root of the repository')
parser.add_argument(
'--skip-contributors', action='store_true', default=False,
help='Skip adding the list of contributors to the changelog')
parser.add_argument(
group_merge.add_argument(
'--skip-merges', action='store_true', default=False,
help='Skip adding merge commits to the changelog')
parser.add_argument(
Expand All @@ -66,11 +70,11 @@ def main(sysargs=None):
# printing status messages to stderr to allow piping the changelog to a file
if args.all:
print('Querying all tags and commit information...', file=sys.stderr)
tag2log_entries = get_all_changes(vcs_client, skip_merges=args.skip_merges)
tag2log_entries = get_all_changes(vcs_client, skip_merges=args.skip_merges, only_merges=args.only_merges)
print('Generating changelog output with all versions...', file=sys.stderr)
else:
print('Querying commit information since latest tag...', file=sys.stderr)
tag2log_entries = get_forthcoming_changes(vcs_client, skip_merges=args.skip_merges)
tag2log_entries = get_forthcoming_changes(vcs_client, skip_merges=args.skip_merges, only_merges=args.only_merges)
print('Generating changelog files with forthcoming version...', file=sys.stderr)
print('', file=sys.stderr)
data = generate_changelog_file('repository-level', tag2log_entries, vcs_client=vcs_client)
Expand Down Expand Up @@ -106,12 +110,12 @@ def main(sysargs=None):

if args.all:
print('Querying all tags and commit information...')
tag2log_entries = get_all_changes(vcs_client, skip_merges=args.skip_merges)
tag2log_entries = get_all_changes(vcs_client, skip_merges=args.skip_merges, only_merges=args.only_merges)
print('Generating changelog files with all versions...')
generate_changelogs(base_path, packages, tag2log_entries, logger=logging, vcs_client=vcs_client, skip_contributors=args.skip_contributors)
else:
print('Querying commit information since latest tag...')
tag2log_entries = get_forthcoming_changes(vcs_client, skip_merges=args.skip_merges)
tag2log_entries = get_forthcoming_changes(vcs_client, skip_merges=args.skip_merges, only_merges=args.only_merges)
# separate packages with/without a changelog file
packages_without = {pkg_path: package for pkg_path, package in packages.items() if package.name in missing_changelogs}
if packages_without:
Expand Down

0 comments on commit db9f907

Please sign in to comment.