Compare commits

...

3 commits

Author SHA1 Message Date
Benjamin Renard
0824d02cd6 Split long commit message to multiple lines to respect the maximun of 80 characters per line imposed by Lantian
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-12-12 11:32:27 +01:00
Benjamin Renard
5c5481ea57 Add --revision parameter to allow to control the commits used to generate the changelog 2022-12-12 11:19:08 +01:00
Benjamin Renard
e71611f17a Add -A/--append parameter to append generated changelog lines to existing file instead of overwriting it 2022-12-12 11:17:01 +01:00

44
gitdch
View file

@ -7,6 +7,7 @@ import logging
import os import os
import re import re
import sys import sys
import textwrap
import git import git
@ -69,6 +70,18 @@ parser.add_argument(
help='Generated Debian changelog output path (default: stdout)', help='Generated Debian changelog output path (default: stdout)',
) )
parser.add_argument(
'-A',
'--append',
action='store_true',
dest='append',
help=(
'Append mode: if the output changelog file already exists, append '
'generated changelog lines at the begining of the file (optional, '
'default: overwriting the file)'
)
)
parser.add_argument( parser.add_argument(
'-n', '-n',
'--package-name', '--package-name',
@ -136,6 +149,17 @@ parser.add_argument(
help='Specify an optional Markdown release notes output path' help='Specify an optional Markdown release notes output path'
) )
parser.add_argument(
'--revision',
type=str,
dest='revision',
help=(
'Specify the revision to use to generate the changelog (see '
'git-rev-parse for viable options, optional, default: generate the '
'changelog with all commits of the current branch) '
),
default=None
)
options = parser.parse_args() options = parser.parse_args()
@ -213,7 +237,7 @@ version = (
) )
) )
messages = [] messages = []
for commit in repo.iter_commits(): for commit in repo.iter_commits(rev=options.revision):
if version_commit is None: if version_commit is None:
version_commit = commit version_commit = commit
log.debug('Commit %s', commit) log.debug('Commit %s', commit)
@ -244,11 +268,17 @@ for version in versions:
) )
) )
for message in version['messages']:
for idx, line in enumerate(
textwrap.wrap(message, 76, break_long_words=True)
):
# pylint: disable=consider-using-f-string # pylint: disable=consider-using-f-string
changelog_lines.extend([ changelog_lines.append(
' * {0}\n'.format(message) '{0}{1}\n'.format(
for message in version['messages'] ' * ' if not idx else ' ',
]) line
)
)
# pylint: disable=consider-using-f-string # pylint: disable=consider-using-f-string
changelog_lines.append( changelog_lines.append(
@ -266,6 +296,10 @@ for version in versions:
if options.output: if options.output:
log.info('Write generated Debian changelog in file %s', options.output) log.info('Write generated Debian changelog in file %s', options.output)
if options.append and os.path.exists(options.output):
with open(options.output, 'r', encoding='utf8') as fd:
changelog_lines += [""]
changelog_lines += fd.readlines()
with open(options.output, 'w', encoding='utf8') as fd: with open(options.output, 'w', encoding='utf8') as fd:
fd.writelines(changelog_lines) fd.writelines(changelog_lines)
else: else: