Skip to content

Commit

Permalink
tito: Update changelog automatically on release
Browse files Browse the repository at this point in the history
Fixes #983
  • Loading branch information
mgrabovsky committed Oct 18, 2021
1 parent 495da87 commit 1424673
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion .tito/custom/abrt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
from fileinput import FileInput
import os
import re
import shlex
from datetime import date
from fileinput import FileInput

from tito.common import info_out, run_command
from tito.tagger import VersionTagger


class Tagger(VersionTagger):
CHANGELOG_FILE = 'CHANGELOG.md'

def _update_changelog(self, new_version: str):
"""
Update changelog with the new version. This entails renaming headings
in the Markdown file and updating links to compare the corresponding
commits on GitHub.
"""
with FileInput(self.CHANGELOG_FILE, inplace=True) as changelog:
for line in changelog:
if line.startswith('## [Unreleased]'):
# Add a heading for the release right below "Unreleased",
# inheriting its contents. This means that changes that were
# unreleased until now have become released in this new version.
release_date = date.today().strftime('%Y-%m-%d')
line += f'\n## [{new_version}] - {release_date}\n'
elif line.startswith('[Unreleased]:'):
# Update link to comparison of changes on GitHub.
match = re.search(r'(https://.+/compare/)(.+)\.\.\.HEAD', line)
assert match is not None
url_prefix = match[1]
old_version = match[2]
line = (f'[Unreleased]: {url_prefix}{new_version}...HEAD\n'
f'[{new_version}]: {url_prefix}{new_version}...{old_version}\n')

print(line, end='')

run_command(f'git add -- {self.CHANGELOG_FILE}')

def _bump_version(self, release=False, zstream=False):
version = super()._bump_version().split('-', maxsplit=1)[0]
pattern = re.compile(r'(?<=^m4_define\(\[faf_version\], \[)'
Expand All @@ -27,6 +57,7 @@ def _tag_release(self):
version = self._bump_version()

self._check_tag_does_not_exist(version)
self._update_changelog(version)
self._clear_package_metadata()

metadata_file = os.path.join(self.rel_eng_dir, 'packages', self.project_name)
Expand Down

0 comments on commit 1424673

Please sign in to comment.