diff --git a/changelog_generator.py b/changelog_generator.py index c6aea7f0e486292a8d8aca0847ed3a1cacee6a7c..901cd8abc45cbe7c5891c4aaa67fdd63ab18d816 100755 --- a/changelog_generator.py +++ b/changelog_generator.py @@ -14,10 +14,11 @@ in comparison with the tags timestamp. """ -import sys +import argparse import datetime +import logging +import sys import gitlab as gl -import argparse __author__ = "Jonas Höppner" __email__ = "jonas.hoeppner@garz-fricke.com" @@ -34,17 +35,10 @@ DEFAULTBRANCH = "dunfell" GITLAB_TIMEFORMAT = "%Y-%m-%dT%H:%M:%S.%f%z" TIMEFORMAT = "%Y-%m-%d %H:%M" -TIMEFORMAT_DEBUG = "%Y-%m-%d %H:%M.%f %z" verbose = 0 -def print_dbg(*args, **kwargs): - if verbose < 1: - return - print(*args, file=sys.stderr, **kwargs) - - def decode_timestamp(t): timestamp = datetime.datetime.strptime(t, GITLAB_TIMEFORMAT) return timestamp @@ -88,7 +82,7 @@ class Tag: with V5 Api: https://docs.gitlab.com/ee/api/commits.html#list-merge-requests-associated-with-a-commit """ self.mergerequest = None - print_dbg(self.name + " -- " + self.commit["id"]) + logging.debug(self.name + " -- " + self.commit["id"]) def __str__(self): return self.name + " " + self.timestamp.strftime(TIMEFORMAT) @@ -103,9 +97,9 @@ class Tag: # as the commit, so the merged_at date is relevant. Otherwise the tagged commit and may be # more end up in the wrong release new_timestamp = decode_timestamp(self.mergerequest.mr.merged_at) - print_dbg("Found matching merge request for ", self) - print_dbg(" - " + self.timestamp.strftime(TIMEFORMAT)) - print_dbg(" - " + new_timestamp.strftime(TIMEFORMAT)) + logging.debug("Found matching merge request for %s", self) + logging.debug(" - %s", self.timestamp.strftime(TIMEFORMAT)) + logging.debug(" - %s", new_timestamp.strftime(TIMEFORMAT)) self.timestamp = new_timestamp def header(self): @@ -156,10 +150,9 @@ class Release: # As it is not possible to change the owner back # to gitbot we need an extra filter here on the # branch name - if m.mr.source_branch.startswith('integrate/'): + if m.mr.source_branch.startswith("integrate/"): return False - # Timestamp is not in this release if self.tag.timestamp < m.timestamp: return False @@ -193,22 +186,18 @@ class MergeRequest: self.mr = mr self.project = p self.timestamp = decode_timestamp(self.mr.merged_at) - print_dbg("\nMergeRequest:") - print_dbg(mr) + logging.debug("\nMergeRequest:") + logging.debug(mr) def __str__(self): return self.mr.title def withlink(self): out = self.mr.title + " [" + self.mr.reference + "](" + self.mr.web_url + ")" - if verbose > 1: - out += " " + self.timestamp.strftime(TIMEFORMAT) return out def main(args): - global verbose - global TIMEFORMAT parser = argparse.ArgumentParser(description=__doc__, usage="%(prog)s [OPTIONS]") @@ -244,11 +233,10 @@ def main(args): ) options = parser.parse_args(args) - verbose = options.verbose - if verbose > 1: - TIMEFORMAT = TIMEFORMAT_DEBUG + if options.verbose: + logging.basicConfig(level=logging.DEBUG) - print_dbg(options) + logging.debug(options) gitlab = gl.Gitlab(options.gitlab_url, private_token=options.token) # Speed up, complete project lookup takes much longer