Skip to content

Commit

Permalink
Include the management chain in the nagging emails
Browse files Browse the repository at this point in the history
  • Loading branch information
suhaibmujahid committed May 19, 2022
1 parent 7ffd1bc commit 694696a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
9 changes: 7 additions & 2 deletions auto_nag/multinaggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ def gather(self):
for m in mails:
manager = m["manager"]
if manager not in all_mails:
all_mails[manager] = {"to": m["to"], "body": m["body"]}
all_mails[manager] = {
"to": m["to"],
"management_chain": m["management_chain"],
"body": m["body"],
}
else:
all_mails[manager]["to"] |= m["to"]
all_mails[manager]["management_chain"] |= m["management_chain"]
all_mails[manager]["body"] += "\n" + m["body"]

for manager, m in all_mails.items():
Cc = Default_Cc.copy()
Cc = Default_Cc | m["management_chain"]
Cc.add(manager)
body = common.render(message=m["body"], has_table=True)
mail.send(
Expand Down
14 changes: 12 additions & 2 deletions auto_nag/nag_me.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def send_mails(self, title, dryrun=False):
mails = self.prepare_mails()

for m in mails:
Cc = Default_Cc.copy()
Cc = Default_Cc | m["management_chain"]
if m["manager"]:
Cc.add(m["manager"])
body = common.render(message=m["body"], query_url=None)
Expand Down Expand Up @@ -210,6 +210,7 @@ def prepare_mails(self):
data = []
To = sorted(info.keys())
components = set()
management_chain = set()
for person in To:
data += [
bug_data
Expand All @@ -220,6 +221,10 @@ def prepare_mails(self):
if person in self.triage_owners_components:
components |= self.triage_owners_components[person]

management_chain |= self.people.get_management_chain_mails(
person, manager
)

if components:
query_url = self.get_query_url_for_components(sorted(components))
else:
Expand All @@ -237,7 +242,12 @@ def prepare_mails(self):
nag_preamble=self.nag_preamble(),
)

m = {"manager": manager, "to": set(To), "body": body}
m = {
"manager": manager,
"management_chain": management_chain,
"to": set(To),
"body": body,
}
mails.append(m)

return mails
Expand Down
18 changes: 18 additions & 0 deletions auto_nag/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import re
from math import sqrt
from typing import Set

import numpy as np
import six
Expand Down Expand Up @@ -302,6 +303,23 @@ def get_nth_manager_mail(self, mail, rank):
return prev
return mail

def get_management_chain_mails(self, person: str, superior: str) -> Set[str]:
"""Get the mails of people in the management chain between a person and
their superior.
Note: the person and the superior will not be returned in result.
"""
result = set()

manager = self.get_manager_mail(person)
while manager != superior:
result.add(manager)
manager = self.get_manager_mail(manager)
if not manager or manager in result:
raise Exception(f"Cannot identify {superior} as a superior of {person}")

return result

def get_director_mail(self, mail):
"""Get the director of the person with this mail"""
directors = self.get_directors()
Expand Down

0 comments on commit 694696a

Please sign in to comment.