Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependabot rota report for Team REX #466

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion ebmbot/job_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,25 @@
"job_type": "all",
},
],
}
},
"dependabot": {
"description": "The Team REX Dependabot rota",
"jobs": {
"rota_report": {
"run_args_template": "python jobs.py",
"report_stdout": True,
"report_format": "blocks",
},
},
"slack": [
{
"command": "rota report",
"help": "Report who's next on Dependabot PR checking duty",
"action": "schedule_job",
"job_type": "rota_report",
},
],
},
}
# fmt: on

Expand Down
52 changes: 52 additions & 0 deletions tests/test_dependabot_rota.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import csv
import json
from unittest.mock import patch

from workspace.dependabot.jobs import report_rota


@patch("workspace.dependabot.jobs.get_rota_data_from_sheet")
def test_rota_report_on_monday(get_rota_data_from_sheet, freezer):
freezer.move_to("2024-03-25")
with open("tests/workspace/dependabot-rota.csv") as f:
get_rota_data_from_sheet.return_value = list(csv.reader(f))
blocks = json.loads(report_rota())
assert blocks == [
{"text": {"text": "Dependabot rota", "type": "plain_text"}, "type": "header"},
{
"text": {
"text": "To review dependabot PRs this week: Lucy",
"type": "mrkdwn",
},
"type": "section",
},
]


@patch("workspace.dependabot.jobs.get_rota_data_from_sheet")
def test_rota_report_on_monday_with_no_future_dates(get_rota_data_from_sheet, freezer):
freezer.move_to("2024-10-07")
with open("tests/workspace/dependabot-rota.csv") as f:
get_rota_data_from_sheet.return_value = list(csv.reader(f))
blocks = json.loads(report_rota())
assert blocks == [
{"text": {"text": "Dependabot rota", "type": "plain_text"}, "type": "header"},
{
"text": {
"text": "No rota data found for this week",
"type": "mrkdwn",
},
"type": "section",
},
]


@patch("workspace.dependabot.jobs.get_rota_data_from_sheet")
def test_rota_report_on_tuesday(get_rota_data_from_sheet, freezer):
freezer.move_to("2023-07-25")
with open("tests/workspace/dependabot-rota.csv") as f:
get_rota_data_from_sheet.return_value = list(csv.reader(f))
blocks = json.loads(report_rota())
assert blocks == [
{"text": {"text": "Dependabot rota", "type": "plain_text"}, "type": "header"},
]
5 changes: 5 additions & 0 deletions tests/workspace/dependabot-rota.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Week commencing,Checker
2024-03-18,Iain
2024-03-25,Lucy
2024-04-01,Jon
2024-04-08,Steve
Empty file.
69 changes: 69 additions & 0 deletions workspace/dependabot/jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import json
from datetime import date
from os import environ

from apiclient import discovery
from google.oauth2 import service_account


def report_rota():
rows = get_rota_data_from_sheet()
rota = {row[0]: row[1] for row in rows[1:]}

blocks = [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Dependabot rota",
},
},
]

today = date.today()
if today.weekday() == 0: # Monday
if str(today) in rota:
checker = rota[str(today)]
blocks.append(
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"To review dependabot PRs this week: {checker}",
},
}
)
else:
blocks.append(
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "No rota data found for this week",
},
}
)

return json.dumps(blocks, indent=2)


def get_rota_data_from_sheet(): # pragma: no cover
credentials = service_account.Credentials.from_service_account_file(
environ["GCP_CREDENTIALS_PATH"],
scopes=["https://www.googleapis.com/auth/spreadsheets.readonly"],
)
service = discovery.build("sheets", "v4", credentials=credentials)

return (
service.spreadsheets()
.values()
.get(
spreadsheetId="1mxAks8tfVEBTSarKoNREsdztW3bTqvIPgV-83GY6CFU",
range="Rota",
)
.execute()
)["values"]


if __name__ == "__main__":
print(report_rota())