From 7e5133a0b9717f2b6bcfeee25ad16c5bb07ced76 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Tue, 11 Oct 2022 10:44:21 +0200 Subject: [PATCH] MT#33006 hotfix: add force param to be able to process again * when we find issues, later we want to be able to send the task again * more logging Change-Id: I48aabcbd893185a689a31f2c97e5ac26efa21a2f --- hotfix/models.py | 10 ++++++++-- hotfix/tasks.py | 4 ++-- hotfix/utils.py | 9 ++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/hotfix/models.py b/hotfix/models.py index f7f401d..72fb4ed 100644 --- a/hotfix/models.py +++ b/hotfix/models.py @@ -14,6 +14,7 @@ # with this program. If not, see . import re +import structlog from django.db import models from .conf import settings @@ -24,6 +25,7 @@ from tracker.models import TrackerInfo from tracker.models import WorkfrontInfo hotfix_re_release = re.compile(r".+~(mr[0-9]+\.[0-9]+\.[0-9]+.[0-9]+)$") +logger = structlog.get_logger(__name__) class NoteInfo(TrackerInfo): @@ -52,18 +54,22 @@ class NoteInfo(TrackerInfo): return NoteInfo @staticmethod - def create(wid, projectname, version): + def create(wid, projectname, version, force=False): note, created = NoteInfo.get_or_create( field_id=wid, projectname=projectname, version=version ) - if created: + if created or force: msg = "hotfix %s.git %s triggered" % ( note.projectname, note.version, ) note.send(msg) target_release = note.target_release + structlog.contextvars.bind_contextvars( + target_release=target_release + ) if target_release: + logger.info("set_target_release") note.set_target_release() @classmethod diff --git a/hotfix/tasks.py b/hotfix/tasks.py index bc50a96..6c9a557 100644 --- a/hotfix/tasks.py +++ b/hotfix/tasks.py @@ -22,7 +22,7 @@ logger = structlog.get_logger(__name__) @shared_task(ignore_result=True) -def hotfix_released(jbi_id, path): +def hotfix_released(jbi_id, path, force=False): JenkinsBuildInfo = apps.get_model("repoapi", "JenkinsBuildInfo") jbi = JenkinsBuildInfo.objects.get(pk=jbi_id) - process_hotfix(str(jbi), jbi.projectname, path) + process_hotfix(str(jbi), jbi.projectname, path, force) diff --git a/hotfix/utils.py b/hotfix/utils.py index 5fcb89c..78ea65a 100644 --- a/hotfix/utils.py +++ b/hotfix/utils.py @@ -20,12 +20,15 @@ from debian.changelog import Changelog logger = structlog.get_logger(__name__) -def process_hotfix(jbi_info, projectname, path): +def process_hotfix(jbi_info, projectname, path, force=False): model = NoteInfo.get_model() - logger.info(f"hotfix_released[{jbi_info}] {path}") ids, changelog = parse_changelog(path, model) + structlog.contextvars.bind_contextvars( + ids=ids, project=projectname, release=changelog.full_version + ) + logger.info(f"hotfix_released[{jbi_info}] {path}") for wid in ids: - model.create(wid, projectname, changelog.full_version) + model.create(wid, projectname, changelog.full_version, force) def parse_changelog(path, model=None):