Skip to content

Commit 892fce4

Browse files
committed
[ADD] forwardport: email reminders
After 6 months of sitting unmerged, forward ports will now trigger a monthly email. Or would, if an email server was configured on the mergebot, but adding this now should allow debugging its working and tracking the generation of emails through the "Delivery Failed" collection. This way if we ever decide to actually do the thing we can just enable an SMTP server. Fixes #801
1 parent 8966246 commit 892fce4

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

forwardport/models/project.py

+36-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from __future__ import annotations
1515

1616
import builtins
17+
import collections
1718
import datetime
1819
import itertools
1920
import json
@@ -24,6 +25,7 @@
2425

2526
import dateutil.relativedelta
2627
import requests
28+
from markupsafe import Markup
2729

2830
from odoo import models, fields, api
2931
from odoo.exceptions import UserError
@@ -522,7 +524,8 @@ def _make_fp_message(self, commit):
522524
return msg
523525

524526
def _reminder(self):
525-
for _, prs in groupby(self.search([
527+
emails = collections.defaultdict(self.browse)
528+
for source, prs in groupby(self.search([
526529
('source_id', '!=', False),
527530
('blocked', '!=', False),
528531
('state', 'in', ['opened', 'validated', 'approved', 'ready', 'error']),
@@ -532,18 +535,49 @@ def _reminder(self):
532535
# will most likely lead to their parent being validated (?)
533536
for pr in set(prs).difference(p.parent_id for p in prs):
534537
# reminder every 7 days for the first 4 weeks, then every 4 weeks
535-
if (pr.reminder_next - pr.create_date) < datetime.timedelta(days=28):
538+
age = pr.reminder_next - pr.create_date
539+
if age < datetime.timedelta(days=28):
536540
pr.reminder_next += datetime.timedelta(days=7)
537541
else:
538542
pr.reminder_next += datetime.timedelta(days=28)
539543

544+
# after 6 months, start sending emails
545+
if age > datetime.timedelta(weeks=26):
546+
if author := source.author.email:
547+
emails[author] |= prs
548+
if reviewer := source.reviewed_by.email:
549+
emails[reviewer] |= prs
540550
self.env.ref('runbot_merge.forwardport.reminder')._send(
541551
repository=pr.repository,
542552
pull_request=pr.number,
543553
token_field='fp_github_token',
544554
format_args={'pr': pr, 'source': pr.source_id},
545555
)
546556

557+
try:
558+
self.env['mail.mail'].sudo().create([
559+
{
560+
'email_to': email,
561+
'subject': f"You have {len(prs)} outstanding forward ports",
562+
'body': Markup(
563+
"<p>The following forward-ports are more than 6 months old "
564+
"and were either created or approved by you.</p>"
565+
"<p>Please process them appropriately (merge or close them)"
566+
"at the earliest.</p>"
567+
"<ul>{}</ul>"
568+
).format(Markup("").join(
569+
Markup('<li><a href="{link}">{name}</a></li>').format(
570+
name=pr.display_name,
571+
link=pr.github_url,
572+
)
573+
for pr in prs
574+
))
575+
}
576+
for email, prs in emails.items()
577+
])
578+
except Exception:
579+
_logger.exception("Failed to create mail")
580+
547581

548582
map_author = operator.itemgetter('name', 'email', 'date')
549583
map_committer = operator.itemgetter('name', 'email')

0 commit comments

Comments
 (0)