From 1eea9049ac71f8695511a311e51b8884a0a9cf65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Due=C3=B1as?= Date: Mon, 7 Oct 2024 18:47:48 +0200 Subject: [PATCH] [bugzilla] Add keywords field to enriched index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds the 'keywords' field to the enriched index. Signed-off-by: Santiago DueƱas --- grimoire_elk/enriched/bugzilla.py | 6 ++++++ tests/data/bugzilla.json | 8 ++++++-- tests/test_bugzilla.py | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/grimoire_elk/enriched/bugzilla.py b/grimoire_elk/enriched/bugzilla.py index dd53e12f8..8e955b997 100644 --- a/grimoire_elk/enriched/bugzilla.py +++ b/grimoire_elk/enriched/bugzilla.py @@ -153,6 +153,12 @@ def get_rich_item(self, item): if 'votes' in item['data']: eitem['votes'] = item['data']['votes'][0]['__text__'] + # Add keywords + if 'keywords' in item['data'] and '__text__' in item['data']['keywords'][0]: + eitem['keywords'] = item['data']['keywords'][0]['__text__'].split(',') + else: + eitem['keywords'] = [] + if "assigned_to" in issue: if "name" in issue["assigned_to"][0]: eitem["assigned"] = issue["assigned_to"][0]["name"] diff --git a/tests/data/bugzilla.json b/tests/data/bugzilla.json index 4d0f14dae..68612bbf3 100644 --- a/tests/data/bugzilla.json +++ b/tests/data/bugzilla.json @@ -92,7 +92,9 @@ } ], "keywords": [ - {} + { + "__text__": "robotics" + } ], "long_desc": [ { @@ -416,7 +418,9 @@ } ], "keywords": [ - {} + { + "__text__": "robotics, kernel, analytics" + } ], "long_desc": [ { diff --git a/tests/test_bugzilla.py b/tests/test_bugzilla.py index 1b60ce9a3..aaa0afd8e 100644 --- a/tests/test_bugzilla.py +++ b/tests/test_bugzilla.py @@ -75,6 +75,24 @@ def test_enrich_repo_labels(self): eitem = enrich_backend.get_rich_item(item) self.assertIn(REPO_LABELS, eitem) + def test_enrich_keywords(self): + """Test whether keywords are included on the enriched items""" + + self._test_raw_to_enrich() + enrich_backend = self.connectors[self.connector][2]() + + item = self.items[0] + eitem = enrich_backend.get_rich_item(item) + self.assertEqual(eitem['keywords'], ['robotics']) + + item = self.items[1] + eitem = enrich_backend.get_rich_item(item) + self.assertEqual(eitem['keywords'], ['robotics', 'kernel', 'analytics']) + + for item in self.items[2:]: + eitem = enrich_backend.get_rich_item(item) + self.assertEqual(eitem['keywords'], []) + def test_raw_to_enrich_sorting_hat(self): """Test enrich with SortingHat"""