Compare commits

...

2 commits

Author SHA1 Message Date
Benjamin Renard
1f2ae28cf0 Try to auto-detect revision in append mode if not specified
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2022-12-13 10:45:28 +01:00
Benjamin Renard
bc072ccf32 Fix release notes generation even if no new version is detected 2022-12-13 10:44:33 +01:00

60
gitdch
View file

@ -10,6 +10,7 @@ import sys
import textwrap import textwrap
import git import git
from git.exc import GitCommandError
VERSION = '0.0' VERSION = '0.0'
DEFAULT_GIT_PATCH = './' DEFAULT_GIT_PATCH = './'
@ -227,14 +228,6 @@ if not options.quiet or not options.logfile:
repo = git.Repo(options.git_path) repo = git.Repo(options.git_path)
log.info('Generate changelog from git commits')
versions = []
tag_commits = dict(
(tag.commit.binsha, tag)
for tag in repo.tags
)
def clean_deb_version(version_name): def clean_deb_version(version_name):
""" Clean debian version name """ """ Clean debian version name """
@ -246,6 +239,45 @@ def clean_deb_version(version_name):
return version_name return version_name
if not options.version:
log.info('Detect current version from git tags & commits')
options.version = clean_deb_version(
repo.git.describe('--always', '--tags')
)
log.info('Currrent version detected: %s', options.version)
if options.output and options.append and not options.revision:
log.info(
'Append mode enabled but no revision specify, try to detect it from '
'last modification of the changelog file')
try:
last_change_commit = next(repo.iter_commits(paths=options.output))
# pylint: disable=consider-using-f-string
options.revision = '{0}..HEAD'.format(last_change_commit)
log.info(
'Last change commit of the output file is "%s": use revision "%s"',
last_change_commit, options.revision)
except StopIteration:
log.warning(
'Fail to auto-detect last change commit of changelog file: it '
'seem not tracked. Continue without revision.')
except GitCommandError:
log.warning(
"Fail to auto-detect last change commit of changelog file. May "
"be it's outside of the git repository. Continue without "
"revision.")
# Reset repo object of to avoid BrokenPipeError
repo = git.Repo(options.git_path)
log.info('Generate changelog from git commits')
versions = []
tag_commits = dict(
(tag.commit.binsha, tag)
for tag in repo.tags
)
def add_version(): def add_version():
""" Add version info """ """ Add version info """
global messages # pylint: disable=global-statement global messages # pylint: disable=global-statement
@ -264,12 +296,7 @@ def add_version():
tag = None tag = None
version_commit = None version_commit = None
version = ( version = options.version
options.version or
clean_deb_version(
repo.git.describe('--always', '--tags')
)
)
messages = [] messages = []
for commit in repo.iter_commits(rev=options.revision): for commit in repo.iter_commits(rev=options.revision):
log.debug('Commit %s (%s)', commit, commit.summary) log.debug('Commit %s (%s)', commit, commit.summary)
@ -350,10 +377,15 @@ else:
if options.release_notes: if options.release_notes:
log.info('Generate Markdown release notes') log.info('Generate Markdown release notes')
release_notes_lines = ['# Changelog:\n\n'] release_notes_lines = ['# Changelog:\n\n']
if versions:
release_notes_lines.extend([ release_notes_lines.extend([
'* {0}\n'.format(message) '* {0}\n'.format(message)
for message in versions[0]['messages'] for message in versions[0]['messages']
]) ])
else:
release_notes_lines.extend([
'* Release version {0}\n'.format(options.version)
])
log.info( log.info(
'Write generated Markdown release notes in file %s', 'Write generated Markdown release notes in file %s',
options.release_notes) options.release_notes)