-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #466 from ebmdatalab/add-dependabot-rota
Dependabot rota report for Team REX
- Loading branch information
Showing
5 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |