in rotation.py [0:0]
def add_gcal_reminder(is_production, rotation, generated_next_week):
"""Adds a triage reminder event to the Performance Team Google Calendar based on the rotation.
See the top-of-file comment in gcal.py for requirements to run this function.
This function may raise HttpError for google API or network failures and
FileNotFoundError if the GCloud Project secrets are missing.
"""
# TODO: the states (is_production, generated_next_week, & CI envvar) seem confusing - is there a cleaner solution?
dry_run_mode = False
if not generated_next_week:
dry_run_mode = True
print(
(
"INFO: for this script to be idempotent, we only add calendar reminders when we "
"generate new rotations for next week. We did not generate it this time so we "
"run add_gcal_reminder in dry run mode."
)
)
if not is_production:
dry_run_mode = True
print(
"INFO: --production was not specified so running add_gcal_reminder in dry run mode."
)
if not dry_run_mode:
credentials = gcal.auth_as_user()
service = gcal.get_calendar_service(credentials)
# N.B.: for simplicity, this code assumes this script executes on Monday
# or Tuesday the week before we want to set the reminder.
#
# Our reminders appear one week in advance. Note that we don't use the time fields.
reminder_date = DATE + timedelta(weeks=1)
# Show the reminder on Tuesday: we want the reminder to appear as early in
# the week as possible but add a buffer day in case Monday is a holiday.
while reminder_date.weekday() != 1: # 1 == Tuesday
reminder_date += timedelta(days=1)
# To save time in changing the original implementation,
# send_triage_reminder takes a yyyy-mm-dd instead of a datetime.
reminder_date = reminder_date.strftime("%Y-%m-%d")
addresses = get_addresses_from_rotation(rotation)
if not dry_run_mode:
gcal.send_triage_reminder(service, reminder_date, addresses)
else:
if os.getenv("CI"):
# Don't print full email addresses to CI logs.
addresses = [a.split("@")[0] for a in addresses]
print(
(
"\nadd_gcal_reminder dry-run mode: would have created calendar "
"invite with date {} and invitees {}"
).format(reminder_date, addresses)
)