Skip to content

Commit

Permalink
[bugzillarest] Add time to first attention on enriched indices
Browse files Browse the repository at this point in the history
The time to first attention is the time expressed in days
between the ticket creation and the first comment from a
contributor different from the author creating the bug.
The field added to the indices is 'time_to_fist_attention'.

Signed-off-by: Santiago Dueñas <sduenas@bitergia.com>
  • Loading branch information
sduenas committed Oct 10, 2024
1 parent 44c8812 commit 147faf0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
29 changes: 29 additions & 0 deletions grimoire_elk/enriched/bugzillarest.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def get_rich_item(self, item):
eitem['comments'] = 0
eitem['number_of_comments'] = 0
eitem['time_to_last_update_days'] = None
eitem['time_to_first_attention'] = None
eitem['url'] = None

# Add the field to know if the ticket is open
Expand All @@ -155,6 +156,9 @@ def get_rich_item(self, item):
if 'is_open' in issue and not issue['is_open']:
eitem['timeopen_days'] = eitem['time_to_last_update_days']

eitem['time_to_first_attention'] = \
get_time_diff_days(eitem['creation_ts'], self.get_time_to_first_attention(issue))

eitem['changes'] = 0
for history in issue['history']:
if 'changes' in history:
Expand All @@ -177,3 +181,28 @@ def get_rich_item(self, item):
self.add_repository_labels(eitem)
self.add_metadata_filter_raw(eitem)
return eitem

def get_time_to_first_attention(self, item):
"""Set the time to first attention.
This date is defined as the first date at which a comment by someone
other than the user who created the issue.
"""
if 'comments' not in item:
return None

comment_dates = []
creator = item['creator']

# First comment is the description of the issue
# Real comments start at the second position (index 1)
for comment in item['comments'][1:]:
user = comment['creator']
if user == creator:
continue
comment_dates.append(str_to_datetime(comment['time']).replace(tzinfo=None))

if comment_dates:
return min(comment_dates)
else:
return None
12 changes: 12 additions & 0 deletions tests/test_bugzillarest.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ def test_enrich_keywords(self):
eitem = enrich_backend.get_rich_item(item)
self.assertEqual(eitem['keywords'], ['crash', 'regression'])

def test_time_to_first_attention(self):
"""Test whether time_to_first_attention is calculated"""

self._test_raw_to_enrich()
enrich_backend = self.connectors[self.connector][2]()

expected = [7.23, 0.03, 0.2, 2.31, 9.88, None, None]

for index in range(0, len(self.items)):
eitem = enrich_backend.get_rich_item(self.items[index])
self.assertEqual(eitem['time_to_first_attention'], expected[index])

def test_raw_to_enrich_sorting_hat(self):
"""Test enrich with SortingHat"""

Expand Down

0 comments on commit 147faf0

Please sign in to comment.