Skip to content

Commit

Permalink
[bugzilla] 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 ef7d581 commit 44c8812
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 16 deletions.
29 changes: 29 additions & 0 deletions grimoire_elk/enriched/bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ def get_rich_item(self, item):
get_time_diff_days(eitem['creation_date'], eitem['delta_ts'])
eitem['timeopen_days'] = \
get_time_diff_days(eitem['creation_date'], datetime_utcnow().replace(tzinfo=None))
eitem['time_to_first_attention'] = \
get_time_diff_days(eitem['creation_date'],
self.get_time_to_first_attention(issue))

if self.sortinghat:
eitem.update(self.get_item_sh(item, self.roles))
Expand All @@ -216,3 +219,29 @@ 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 'long_desc' not in item:
return None

comment_dates = []
reporter = item['reporter'][0]['__text__']

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

if comment_dates:
return min(comment_dates)
else:
return None
1 change: 1 addition & 0 deletions schema/bugzilla.csv
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ severity,keyword
status,keyword
tag,keyword
timeopen_days,float
time_to_first_attention,float
url,keyword
uuid,keyword
whiteboard,keyword
122 changes: 106 additions & 16 deletions tests/data/bugzilla.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@
],
"reporter": [
{
"__text__": "rocapal@example.org",
"name": "Roberto Calvo"
"__text__": "sduenas@example.org",
"name": "Santiago Due\u00f1as"
}
],
"reporter_accessible": [
Expand Down Expand Up @@ -507,8 +507,8 @@
],
"reporter": [
{
"__text__": "rocapal@example.org",
"name": "Roberto Calvo"
"__text__": "sduenas@example.org",
"name": "Santiago Due\u00f1as"
}
],
"reporter_accessible": [
Expand Down Expand Up @@ -668,8 +668,8 @@
],
"who": [
{
"__text__": "sduenas@example.org",
"name": "Santiago Due\u00f1as"
"__text__": "dizquierdo@example.org",
"name": "Daniel Izquierdo Cortazar"
}
]
}
Expand Down Expand Up @@ -1026,8 +1026,8 @@
],
"reporter": [
{
"__text__": "rocapal@example.com",
"name": "Roberto Calvo"
"__text__": "sduenas@example.org",
"name": "Santiago Due\u00f1as"
}
],
"reporter_accessible": [
Expand Down Expand Up @@ -1251,8 +1251,8 @@
],
"reporter": [
{
"__text__": "rocapal@example.org",
"name": "Roberto Calvo"
"__text__": "sduenas@example.org",
"name": "Santiago Due\u00f1as"
}
],
"reporter_accessible": [
Expand Down Expand Up @@ -1446,8 +1446,8 @@
],
"reporter": [
{
"__text__": "dizquierdo@example.org",
"name": "Daniel Izquierdo Cortazar"
"__text__": "sduenas@example.org",
"name": "Santiago Due\u00f1as"
}
],
"reporter_accessible": [
Expand Down Expand Up @@ -1661,7 +1661,7 @@
],
"creation_ts": [
{
"__text__": "2015-05-23 06:06:06 +0200"
"__text__": "2013-06-25 11:49:36 +0200"
}
],
"delta_ts": [
Expand Down Expand Up @@ -1720,7 +1720,7 @@
],
"bug_when": [
{
"__text__": "2013-06-25 11:55:46 +0200"
"__text__": "2013-07-01 12:00:00 +0200"
}
],
"commentid": [
Expand All @@ -1740,6 +1740,96 @@
"name": "Santiago Due\u00f1as"
}
]
},
{
"__text__": "\n ",
"attachid": [
{
"__text__": "172"
}
],
"bug_when": [
{
"__text__": "2014-06-25 11:55:46 +0200"
}
],
"commentid": [
{
"__text__": "1086"
}
],
"isprivate": "0",
"thetext": [
{
"__text__": "This patch is great"
}
],
"who": [
{
"__text__": "lcanas@example.org",
"name": "Luis Ca\u00f1as"
}
]
},
{
"__text__": "\n ",
"attachid": [
{
"__text__": "172"
}
],
"bug_when": [
{
"__text__": "2014-06-25 11:55:46 +0200"
}
],
"commentid": [
{
"__text__": "1086"
}
],
"isprivate": "0",
"thetext": [
{
"__text__": "Thanks!"
}
],
"who": [
{
"__text__": "sduenas@example.org",
"name": "Santiago Due\u00f1as"
}
]
},
{
"__text__": "\n ",
"attachid": [
{
"__text__": "172"
}
],
"bug_when": [
{
"__text__": "2014-08-01 11:55:46 +0200"
}
],
"commentid": [
{
"__text__": "1086"
}
],
"isprivate": "0",
"thetext": [
{
"__text__": "Applied"
}
],
"who": [
{
"__text__": "sduenas@example.org",
"name": "Santiago Due\u00f1as"
}
]
}
],
"op_sys": [
Expand Down Expand Up @@ -1770,8 +1860,8 @@
],
"reporter": [
{
"__text__": "carlosgc@example.com",
"name": "Carlos Garcia Campos"
"__text__": "sduenas@example.org",
"name": "Santiago Due\u00f1as"
}
],
"reporter_accessible": [
Expand Down
12 changes: 12 additions & 0 deletions tests/test_bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ def test_enrich_keywords(self):
eitem = enrich_backend.get_rich_item(item)
self.assertEqual(eitem['keywords'], [])

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 = [None, None, None, None, None, None, 365]

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 44c8812

Please sign in to comment.