Code cleaning
All checks were successful
Run tests / test-precommit (push) Successful in 56s

This commit is contained in:
Benjamin Renard 2024-04-22 19:20:25 +02:00
parent 81c05a244e
commit 95a013e74b
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

58
gitdch
View file

@ -25,9 +25,7 @@ parser.add_argument("-v", "--verbose", action="store_true", help="Show verbose m
parser.add_argument("-w", "--warning", action="store_true", help="Show warning messages")
parser.add_argument(
"-l", "--log-file", action="store", type=str, dest="logfile", help="Log file path"
)
parser.add_argument("-l", "--log-file", help="Log file path")
parser.add_argument(
"-q",
@ -39,17 +37,13 @@ parser.add_argument(
parser.add_argument(
"-p",
"--path",
type=str,
dest="git_path",
help="Git repository path (default: %s)" % DEFAULT_GIT_PATCH,
help=f"Git repository path (default: {DEFAULT_GIT_PATCH})",
default=DEFAULT_GIT_PATCH,
)
parser.add_argument(
"-o",
"--output",
type=str,
dest="output",
help="Generated Debian changelog output path (default: stdout)",
)
@ -57,7 +51,6 @@ 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 beginning of the file (optional, "
@ -65,72 +58,58 @@ parser.add_argument(
),
)
parser.add_argument("-n", "--package-name", type=str, dest="package_name", help="Package name")
parser.add_argument("-n", "--package-name", help="Package name")
parser.add_argument(
"-V",
"--version",
type=str,
dest="version",
help=("Current version (default: autodetected using git describe " "--always --tags)"),
)
parser.add_argument(
"--version-suffix", type=str, dest="version_suffix", help="Suffix for autodetected version"
"--version-suffix",
help="Suffix for autodetected version",
)
parser.add_argument(
"-c",
"--code-name",
type=str,
dest="code_name",
help="Debian code name (default: %s)" % DEFAULT_CODE_NAME,
help=f"Debian code name (default: {DEFAULT_CODE_NAME})",
default=DEFAULT_CODE_NAME,
)
parser.add_argument(
"-u",
"--urgency",
type=str,
dest="urgency",
help="Package urgency (default: %s)" % DEFAULT_URGENCY,
help=f"Package urgency (default: {DEFAULT_URGENCY})",
default=DEFAULT_URGENCY,
)
parser.add_argument(
"-N",
"--maintainer-name",
type=str,
dest="maintainer_name",
help="Maintainer name (default: last commit author name)",
)
parser.add_argument(
"-E",
"--maintainer-email",
type=str,
dest="maintainer_email",
help="Maintainer email (default: last commit author email)",
)
parser.add_argument(
"-R",
"--release-notes",
type=str,
dest="release_notes",
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,
)
parser.add_argument(
@ -138,7 +117,6 @@ parser.add_argument(
"--clean-tags-regex",
action="append",
type=re.compile,
dest="clean_tags_regex",
help=(
"Clean tags regex: you could specify regex to clean tag names when "
'computing package versions. For instance, to drop a "-eeXXX" suffix '
@ -153,7 +131,6 @@ parser.add_argument(
"--exclude",
action="append",
type=re.compile,
dest="exclude",
help=(
"Commit exclusion regex: you could specify regex to exclude some "
"commits from generated changelog entries. For instance, to exclude "
@ -184,19 +161,19 @@ elif options.verbose:
elif options.warning:
log_level = logging.WARNING
if options.logfile:
logfile = logging.FileHandler(options.logfile)
logfile.setFormatter(logformat)
logfile.setLevel(log_level if log_level is not None else logging.INFO)
log.addHandler(logfile)
if options.log_file:
log_file = logging.FileHandler(options.log_file)
log_file.setFormatter(logformat)
log_file.setLevel(log_level if log_level is not None else logging.INFO)
log.addHandler(log_file)
if not options.quiet or not options.logfile:
if not options.quiet or not options.log_file:
logconsole = logging.StreamHandler()
logconsole.setLevel(log_level if log_level is not None else logging.FATAL)
logconsole.setFormatter(logformat)
log.addHandler(logconsole)
repo = git.Repo(options.git_path)
repo = git.Repo(options.path)
def clean_deb_version(version_name):
@ -240,7 +217,7 @@ if options.output and options.append and not options.revision:
"revision."
)
# Reset repo object of to avoid BrokenPipeError
repo = git.Repo(options.git_path)
repo = git.Repo(options.path)
log.info("Generate changelog from git commits")
@ -283,7 +260,10 @@ for commit in repo.iter_commits(rev=options.revision):
if regex.search(commit.summary):
excluded = True
log.debug(
'Exclude commit %s ("%s", match with "%s")', commit, commit.summary, regex.pattern
'Exclude commit %s ("%s", match with "%s")',
commit,
commit.summary,
regex.pattern,
)
if not excluded:
messages.append(commit.summary)