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

Refactor/google drive module #392

Merged
merged 34 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
126832f
fix: render commands available in dev only
gcharest Feb 1, 2024
3f0aa59
fix: move google-service command to bottom
gcharest Feb 1, 2024
4355ba8
feat: make test command available in dev only
gcharest Feb 1, 2024
3cc40c7
fix: fix mypy path for current project structure
gcharest Feb 1, 2024
a1ad43f
fix: update pylint cwd
gcharest Feb 1, 2024
060b0bd
fix: ignore google.oauth2 missing stub warning
gcharest Feb 1, 2024
4774214
fix: config flake8 instead of pylint
gcharest Feb 1, 2024
f2ec771
feat: add a decorator to handle api calls errors
gcharest Feb 1, 2024
2555afb
feat: refactor basic drive functions
gcharest Feb 1, 2024
6070afe
feat: add get_file_by_name function
gcharest Feb 1, 2024
97fa78e
feat: add list metadata function
gcharest Feb 1, 2024
f875a9b
feat: use new drive module functions
gcharest Feb 1, 2024
c087c41
fix: shorten test command
gcharest Feb 1, 2024
cf65333
fix: handle invalid folder
gcharest Feb 1, 2024
b1b5de1
feat: modify wrapper to provide context
gcharest Feb 1, 2024
463464d
fix: add missing parameter to list_metadata
gcharest Feb 1, 2024
83f2fa6
fix: surround function name w/ single quotes
gcharest Feb 1, 2024
fead205
fix: google drive healthcheck
gcharest Feb 1, 2024
61d8c68
fix: matching error message
gcharest Feb 1, 2024
0011722
feat: add healtcheck message
gcharest Feb 1, 2024
890ff08
fix: update module docstrings w/ more details
gcharest Feb 2, 2024
6c344f6
fix: remove import from google_service
gcharest Feb 2, 2024
02788a7
fix: update module docstring
gcharest Feb 2, 2024
332a5fe
feat: add basic docstring for Docs module
gcharest Feb 2, 2024
aa88af7
fix: replicate current tests for conformity
gcharest Feb 2, 2024
24c101e
fix: add loop to handle pagination
gcharest Feb 2, 2024
2a0a993
fix: ensure all files are returned
gcharest Feb 2, 2024
68a262c
fix: add test to handle pagination
gcharest Feb 2, 2024
129fcdd
fix: log errors
gcharest Feb 2, 2024
dab733e
fix: remove unused variables
gcharest Feb 2, 2024
40d4413
feat: include ValueError logging in the wrapper function
gcharest Feb 2, 2024
3b73968
fix: adjust tests to handle logging errors
gcharest Feb 2, 2024
4ad41da
fix: test names
gcharest Feb 2, 2024
dda6090
fix: lint
gcharest Feb 2, 2024
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
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.flake8",
"ms-python.pylint",
"ms-python.mypy-type-checker",
"mtxr.sqltools",
"mtxr.sqltools-driver-pg",
Expand Down
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"python.pylintPath": "/usr/local/py-utils/bin/pylint",
"mypy-type-checker.cwd": "${workspaceFolder}/app",
"pylint.cwd": "${workspaceFolder}/app",
"pylint.path": [
"[\"../../usr/local/py-utils/bin/pylint\"]"
],
"flake8.cwd": "${workspaceFolder}/app"
}
37 changes: 12 additions & 25 deletions app/commands/google_service.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
"""Testing new google service (will be removed)"""
import os

from integrations.google_workspace.google_service import get_google_service
from integrations.google_workspace import google_drive
from dotenv import load_dotenv

load_dotenv()

SRE_DRIVE_ID = os.environ.get("SRE_DRIVE_ID")
SRE_INCIDENT_FOLDER = os.environ.get("SRE_INCIDENT_FOLDER")
INCIDENT_TEMPLATE = os.environ.get("INCIDENT_TEMPLATE")


def open_modal(client, body):
folders = list_folders()
def open_modal(client, body, folders):
if not folders:
return
folder_names = [i["name"] for i in folders]
blocks = [
{"type": "section", "text": {"type": "mrkdwn", "text": f"*{name}*"}}
Expand All @@ -25,25 +27,10 @@ def open_modal(client, body):
client.views_open(trigger_id=body["trigger_id"], view=view)


def google_service_command(client, body):
open_modal(client, body)


def list_folders():
service = get_google_service("drive", "v3")
results = (
service.files()
.list(
pageSize=25,
supportsAllDrives=True,
includeItemsFromAllDrives=True,
corpora="drive",
q="parents in '{}' and mimeType = 'application/vnd.google-apps.folder' and trashed=false and not name contains '{}'".format(
SRE_INCIDENT_FOLDER, "Templates"
),
driveId=SRE_DRIVE_ID,
fields="nextPageToken, files(id, name)",
)
.execute()
)
return results.get("files", [])
def google_service_command(client, body, respond):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nitpicky, but I would put some spacing between the end of the first function and the def googe_service_command

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is showing without space due to the way GitHub displays the changes inline 🤔

It shows like this in VSCode:
image

respond(f"Healthcheck status: {google_drive.healthcheck()}")
folders = google_drive.list_folders_in_folder(SRE_INCIDENT_FOLDER)
if not folders:
respond("The folder ID is invalid. Please check the environment variables.")
gcharest marked this conversation as resolved.
Show resolved Hide resolved
return
open_modal(client, body, folders)
10 changes: 8 additions & 2 deletions app/commands/sre.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
\n - show the version of the SRE Bot
\n - montre la version du bot SRE"""

PREFIX = os.environ.get("PREFIX", "")


def sre_command(ack, command, logger, respond, client, body):
ack()
Expand All @@ -47,8 +49,12 @@ def sre_command(ack, command, logger, respond, client, body):
webhook_helper.handle_webhook_command(args, client, body, respond)
case "version":
respond(f"SRE Bot version: {os.environ.get('GIT_SHA', 'unknown')}")
case "google-service":
google_service.google_service_command(client, body)
case "google":
if PREFIX == "dev-":
google_service.google_service_command(client, body, respond)
else:
respond("This command is only available in the dev environment.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you added this here!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I figured I should setup a toggle instead of just leaving it hanging in there in prod 😅

return
case _:
respond(
f"Unknown command: `{action}`. Type `/sre help` to see a list of commands. \nCommande inconnue: `{action}`. Entrez `/sre help` pour une liste des commandes valides"
Expand Down
4 changes: 4 additions & 0 deletions app/integrations/google_workspace/google_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Google Docs module.

This module provides functions to create and manipulate Google Docs.
"""
Loading
Loading