Compare commits
3 commits
0c3ddea197
...
0824d02cd6
Author | SHA1 | Date | |
---|---|---|---|
|
0824d02cd6 | ||
|
5c5481ea57 | ||
|
e71611f17a |
1 changed files with 40 additions and 6 deletions
46
gitdch
46
gitdch
|
@ -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:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# pylint: disable=consider-using-f-string
|
for message in version['messages']:
|
||||||
changelog_lines.extend([
|
for idx, line in enumerate(
|
||||||
' * {0}\n'.format(message)
|
textwrap.wrap(message, 76, break_long_words=True)
|
||||||
for message in version['messages']
|
):
|
||||||
])
|
# pylint: disable=consider-using-f-string
|
||||||
|
changelog_lines.append(
|
||||||
|
'{0}{1}\n'.format(
|
||||||
|
' * ' 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:
|
||||||
|
|
Loading…
Reference in a new issue