Compare commits
3 commits
0c3ddea197
...
0824d02cd6
Author | SHA1 | Date | |
---|---|---|---|
|
0824d02cd6 | ||
|
5c5481ea57 | ||
|
e71611f17a |
1 changed files with 40 additions and 6 deletions
44
gitdch
44
gitdch
|
@ -7,6 +7,7 @@ import logging
|
|||
import os
|
||||
import re
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
import git
|
||||
|
||||
|
@ -69,6 +70,18 @@ parser.add_argument(
|
|||
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(
|
||||
'-n',
|
||||
'--package-name',
|
||||
|
@ -136,6 +149,17 @@ parser.add_argument(
|
|||
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()
|
||||
|
||||
|
@ -213,7 +237,7 @@ version = (
|
|||
)
|
||||
)
|
||||
messages = []
|
||||
for commit in repo.iter_commits():
|
||||
for commit in repo.iter_commits(rev=options.revision):
|
||||
if version_commit is None:
|
||||
version_commit = 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
|
||||
changelog_lines.extend([
|
||||
' * {0}\n'.format(message)
|
||||
for message in version['messages']
|
||||
])
|
||||
changelog_lines.append(
|
||||
'{0}{1}\n'.format(
|
||||
' * ' if not idx else ' ',
|
||||
line
|
||||
)
|
||||
)
|
||||
|
||||
# pylint: disable=consider-using-f-string
|
||||
changelog_lines.append(
|
||||
|
@ -266,6 +296,10 @@ for version in versions:
|
|||
|
||||
if 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:
|
||||
fd.writelines(changelog_lines)
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue