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
1 merge request!144CI: Move changelog_generator to gitlab-ci project
Pipeline #17491 waiting for manual action with stages
in 50 seconds
......@@ -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
......
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