Skip to content

Commit

Permalink
notifier: adding basic oncall notifications (#29820)
Browse files Browse the repository at this point in the history
Since slack google calendar support is deprecated, adding it back in via the PR notifier.
(theoretically) notifying general and oncall of rotation switches. This won't work (but will post that it doesn't work) if we do overrides incorrectly.
Signed-off-by: Alyssa Wilk <[email protected]>
  • Loading branch information
alyssawilk authored Oct 2, 2023
1 parent f5253d8 commit c495291
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
25 changes: 25 additions & 0 deletions .github/actions/pr_notifier/pr_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import os
import sys

import requests
import github
import icalendar
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError

Expand All @@ -43,6 +45,9 @@
'soulxu': 'U01GNQ3B8AY',
}

# Oncall calendar
CALENDAR = "https://calendar.google.com/calendar/ical/d6glc0l5rc3v235q9l2j29dgovh3dn48%40import.calendar.google.com/public/basic.ics"

# First pass reviewers who are not maintainers should get
# notifications but not result in a PR not getting assigned a
# maintainer owner.
Expand Down Expand Up @@ -226,10 +231,30 @@ def post_to_oncall(client, unassigned_prs, out_slo_prs):
text=(
"*Untriaged Issues* (please tag and cc area experts)\n<%s|%s>" %
(issue_link, issue_link)))
# On Monday, post the new oncall.
if datetime.date.today().weekday() == 0:
oncall = parse_calendar()
client.chat_postMessage(channel='#envoy-maintainer-oncall', text=(oncall))
client.chat_postMessage(channel='#general', text=(oncall))
except SlackApiError as e:
print("Unexpected error %s", e.response["error"])


def parse_calendar():
ical = requests.get(CALENDAR)
parsed_calendar = icalendar.Calendar.from_ical(ical.text)
ical.close()

now = datetime.datetime.now()
sunday = now - datetime.timedelta(days=now.weekday() + 1)

for component in parsed_calendar.walk():
if component.name == "VEVENT":
if (sunday.date() == component.decoded("dtstart").date()):
return component.get("summary")
return "unable to find this week's oncall"


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down
2 changes: 2 additions & 0 deletions .github/actions/pr_notifier/requirements.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pygithub
slack_sdk
requests
icalendar
18 changes: 14 additions & 4 deletions .github/actions/pr_notifier/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# This file is autogenerated by pip-compile
# To update, run:
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --generate-hashes .github/actions/pr_notifier/requirements.txt
# pip-compile --allow-unsafe --generate-hashes requirements.in
#
certifi==2023.7.22 \
--hash=sha256:539cc1d13202e33ca466e88b2807e29f4c13049d6d87031a3c110744495cb082 \
Expand Down Expand Up @@ -167,6 +167,10 @@ deprecated==1.2.13 \
--hash=sha256:43ac5335da90c31c24ba028af536a91d41d53f9e6901ddb021bcc572ce44e38d \
--hash=sha256:64756e3e14c8c5eea9795d93c524551432a0be75629f8f29e67ab8caf076c76d
# via pygithub
icalendar==5.0.10 \
--hash=sha256:34f0ca020b804758ddf316eb70d1d46f769bce64638d5a080cb65dd46cfee642 \
--hash=sha256:6e392c2f301b6b5f49433e14c905db3de444b12876f3345f1856a75e9cd8be6f
# via -r requirements.in
idna==2.10 \
--hash=sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6 \
--hash=sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0
Expand Down Expand Up @@ -207,10 +211,16 @@ python-dateutil==2.8.2 \
--hash=sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86 \
--hash=sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9
# via pygithub
pytz==2023.3.post1 \
--hash=sha256:7b4fddbeb94a1eba4b557da24f19fdf9db575192544270a9101d8509f9f43d7b \
--hash=sha256:ce42d816b81b68506614c11e8937d3aa9e41007ceb50bfdcb0749b921bf646c7
# via icalendar
requests==2.31.0 \
--hash=sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f \
--hash=sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1
# via pygithub
# via
# -r requirements.in
# pygithub
six==1.16.0 \
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254
Expand Down

0 comments on commit c495291

Please sign in to comment.