Skip to content

Commit

Permalink
chore: cleanup unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gcharest authored Aug 8, 2024
1 parent 2e2b18f commit 0047106
Showing 1 changed file with 0 additions and 128 deletions.
128 changes: 0 additions & 128 deletions app/integrations/google_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,6 @@ def get_google_service(service, version):
return build(service, version, credentials=creds)


def add_metadata(file_id, key, value):
service = get_google_service("drive", "v3")
result = (
service.files()
.update(
fileId=file_id,
body={"appProperties": {key: value}},
fields="name, appProperties",
supportsAllDrives=True,
)
.execute()
)
return result


def create_folder(name):
service = get_google_service("drive", "v3")
results = (
service.files()
.create(
body={
"name": name,
"mimeType": "application/vnd.google-apps.folder",
"parents": [SRE_INCIDENT_FOLDER],
},
supportsAllDrives=True,
fields="name",
)
.execute()
)
return f"Created folder {results['name']}"


def create_new_folder(name, parent_folder):
# Creates a new folder in the parent_folder directory
service = get_google_service("drive", "v3")
Expand Down Expand Up @@ -140,21 +107,6 @@ def copy_file_to_folder(file_id, name, parent_folder_id, destination_folder_id):
return updated_file["id"]


def delete_metadata(file_id, key):
service = get_google_service("drive", "v3")
result = (
service.files()
.update(
fileId=file_id,
body={"appProperties": {key: None}},
fields="name, appProperties",
supportsAllDrives=True,
)
.execute()
)
return result


def create_new_docs_file(name, parent_folder_id):
# Creates a new google docs file in the parent_folder directory
service = get_google_service("drive", "v3")
Expand Down Expand Up @@ -193,24 +145,6 @@ def create_new_sheets_file(name, parent_folder_id):
return results["id"]


def get_document_by_channel_name(channel_name):
service = get_google_service("drive", "v3")
results = (
service.files()
.list(
pageSize=1,
supportsAllDrives=True,
includeItemsFromAllDrives=True,
corpora="drive",
q="trashed=false and name='{}'".format(channel_name),
driveId=SRE_DRIVE_ID,
fields="files(appProperties, id, name)",
)
.execute()
)
return results.get("files", [])


def list_folders():
service = get_google_service("drive", "v3")
results = (
Expand Down Expand Up @@ -294,38 +228,6 @@ def merge_data(file_id, name, product, slack_channel, on_call_names):
return result




# Update the incident document with status of "Closed"
def close_incident_document(file_id):
# List of possible statuses to be replaced
possible_statuses = ["In Progress", "Open", "Ready to be Reviewed", "Reviewed"]

# Replace all possible statuses with "Closed"
changes = {
"requests": [
{
"replaceAllText": {
"containsText": {"text": f"Status: {status}", "matchCase": "false"},
"replaceText": "Status: Closed",
}
}
for status in possible_statuses
]
}
# Execute the batchUpdate request
service = get_google_service("docs", "v1")
result = (
service.documents()
.batchUpdate(
documentId=file_id,
body=changes,
)
.execute()
)
return result


def update_incident_list(document_link, name, slug, product, channel_url):
service = get_google_service("sheets", "v4")
list = [
Expand Down Expand Up @@ -354,36 +256,6 @@ def update_incident_list(document_link, name, slug, product, channel_url):
return result


def update_spreadsheet_close_incident(channel_name):
# Find the row in the spreadsheet with the channel_name and update it's status to Closed
# Read the data from the sheet
service = get_google_service("sheets", "v4")
sheet_name = "Sheet1"
result = (
service.spreadsheets()
.values()
.get(spreadsheetId=INCIDENT_LIST, range=sheet_name)
.execute()
)
values = result.get("values", [])
# Find the row with the search value
for i, row in enumerate(values):
if channel_name in row:
# Update the 4th column (index 3) of the found row
update_range = (
f"{sheet_name}!D{i+1}" # Column D, Rows are 1-indexed in Sheets
)
body = {"values": [["Closed"]]}
service.spreadsheets().values().update(
spreadsheetId=INCIDENT_LIST,
range=update_range,
valueInputOption="USER_ENTERED",
body=body,
).execute()
return True
return False


def healthcheck():
"""Check if the bot can interact with Google Drive."""
healthy = False
Expand Down

0 comments on commit 0047106

Please sign in to comment.