in bugbot/rules/reminder.py [0:0]
def handle_bug(self, bug, data):
bugid = str(bug["id"])
new_whiteboard = whiteboard = bug["whiteboard"]
matches = DATE_MATCH.findall(whiteboard)
# We support having multiple reminders that expire on a single day.
# (I'm not sure why, but I guess we should.)
reminders = []
for m in matches:
tag, date = m
# If we can't parse the date, do a little hack to throw it back
# at the user.
try:
parsed_date = lmdutils.get_date_ymd(date)
except ParserError:
replace_string = f"[reminder-{tag} {date}]"
new_whiteboard = new_whiteboard.replace(replace_string, "")
reminders.append({"full_tag": replace_string, "invalid_date": True})
continue
if parsed_date <= self.today:
replace_string = f"[reminder-{tag} {date}]"
new_whiteboard = new_whiteboard.replace(replace_string, "")
reminders.append({"full_tag": replace_string})
if new_whiteboard == whiteboard:
return
target_entries = []
for entry in bug["history"]:
for field in entry["changes"]:
if field["field_name"] == "whiteboard":
# Check to see if any of the replace strings appeared in this change.
for r in reminders:
if (
r["full_tag"] in field["added"]
and r["full_tag"] not in field["removed"]
):
entry["full_tag"] = r["full_tag"]
target_entries.append(entry)
break
if not target_entries:
# If the history shows no changes, it indicates that the reminders
# were added when the bug was filed.
target_entries.extend(
{
"who": bug["creator"],
"when": bug["creation_time"],
"full_tag": reminder["full_tag"],
}
for reminder in reminders
)
user_emails_to_names = self._get_user_emails_to_names(target_entries)
for r in reminders:
for entry in target_entries:
if r["full_tag"] == entry["full_tag"]:
if user_emails_to_names[entry["who"]] == "Invalid User":
reminders.remove(r)
else:
r["who"] = user_emails_to_names[entry["who"]]
r["when"] = utils.get_human_lag(entry["when"])
if not reminders:
return
data[bugid] = {
"full_tags": ", ".join([r["full_tag"] for r in reminders]),
}
self.autofix_whiteboard[bugid] = {
"whiteboard": new_whiteboard,
}
self.extra_ni[bugid] = {"reminders": reminders}
return bug