From b92a3a5d2a6f260c1f8555ffa406e95c7c05e7c7 Mon Sep 17 00:00:00 2001 From: Clement Verna Date: Mar 16 2020 07:53:16 +0000 Subject: Add labels to the issue creation. The consumer get the release_name, release_version and status from the fedora-messaging message and use these as labels when creating the issue in pagure. Signed-off-by: Clement Verna # Fixes #16. --- diff --git a/compose_tracker.py b/compose_tracker.py index b8a472c..e6df999 100755 --- a/compose_tracker.py +++ b/compose_tracker.py @@ -245,13 +245,11 @@ class Consumer(object): content+= f"Compose phase {p}: FAILED.\n" logger.debug(content) - # pull only part of the compose ID for the label to set - label = re.search('(.*)-\d{8}', msg['compose_id']).group(1) - #TODO set labels on issues when functionality is in ogr - # https://github.com/packit-service/ogr/issues/147 + labels = [msg.get("release_name"), msg.get("release_version"), msg.get("status")] + logger.debug(f"Adding Labels {labels}") if self.token: - issue = self.gitproject.create_issue(title=title, body=content) + issue = self.gitproject.create_issue(title=title, body=content, labels=labels) logger.info('Opened issue: %s' % issue.url) diff --git a/test_consumer.py b/test_consumer.py index 4243c80..1c2bf6e 100644 --- a/test_consumer.py +++ b/test_consumer.py @@ -165,3 +165,24 @@ def test_consumer_logfile_parsing_failures(mocker, caplog): con.process(msg) assert "Ostree (variant Silverblue, arch x86_64) failed, but going on anyway." in caplog.text assert "Ostree (variant Silverblue, arch ppc64le) failed, but going on anyway." in caplog.text + +def test_adding_labels(mocker, caplog): + "Test that we get the correct labels from the fedora-messaging message." + + mocker.patch("compose_tracker.PagureService") + + # set logs at DEBUG and capture this level + caplog.set_level(logging.DEBUG) + mocker.patch("compose_tracker.logger.level", logging.DEBUG) + + req = mocker.patch("compose_tracker.requests.get", autospec=True) + text_mock = mocker.MagicMock() + text_mock.text.splitlines.return_value = EXAMPLE_PUNGI_LOG_INCOMPLETE.splitlines() + req.return_value = text_mock + + con = Consumer() + msg = fedora_messaging.api.Message( + topic="org.fedoraproject.prod.pungi.compose.status.change", body=EXAMPLE_MESSAGE_BODY, + ) + con.process(msg) + assert "Adding Labels ['Fedora', 'Rawhide', 'DOOMED']" in caplog.text