Skip to content
Snippets Groups Projects
Commit aaac8d1c authored by Jonas Höppner's avatar Jonas Höppner
Browse files

changelog_generator: Use logging instead of print, fix black

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