Skip to content

Commit

Permalink
Fix/fix bugs plus heading (#389)
Browse files Browse the repository at this point in the history
* Tweaks to the SRE bot timeline to make it more consistent and to add it to a new section

* Removing unecessary print statements and formatting

* Changing start heading text
  • Loading branch information
sylviamclaughlin authored Feb 1, 2024
1 parent 754d476 commit 9a0aaab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
6 changes: 2 additions & 4 deletions app/commands/incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

INCIDENT_CHANNEL = os.environ.get("INCIDENT_CHANNEL")
SLACK_SECURITY_USER_GROUP_ID = os.environ.get("SLACK_SECURITY_USER_GROUP_ID")
START_HEADING = "Detailed Timeline"
START_HEADING = "DO NOT REMOVE this line as the SRE bot needs it as a placeholder."
END_HEADING = "Trigger"


Expand Down Expand Up @@ -401,7 +401,6 @@ def handle_reaction_added(client, ack, body, logger):
)
if document_id == "":
logger.error("No incident document found for this channel.")

for message in messages:
# convert the time which is now in epoch time to standard ET Time
message_date_time = convert_epoch_to_datetime_est(message["ts"])
Expand Down Expand Up @@ -476,7 +475,6 @@ def handle_reaction_removed(client, ack, body, logger):
)
if document_id == "":
logger.error("No incident document found for this channel.")

# Retrieve the current content of the timeline
content = get_timeline_section(document_id)

Expand All @@ -491,7 +489,7 @@ def handle_reaction_removed(client, ack, body, logger):

# Remove the message
if message_to_remove in content:
content = content.replace(message_to_remove, "")
content = content.replace(message_to_remove, "\n")

# Update the timeline content
result = replace_text_between_headings(
Expand Down
18 changes: 13 additions & 5 deletions app/integrations/google_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
SRE_INCIDENT_FOLDER = os.environ.get("SRE_INCIDENT_FOLDER")
INCIDENT_TEMPLATE = os.environ.get("INCIDENT_TEMPLATE")
INCIDENT_LIST = os.environ.get("INCIDENT_LIST")
START_HEADING = "Detailed Timeline"
START_HEADING = "DO NOT REMOVE this line as the SRE bot needs it as a placeholder."
END_HEADING = "Trigger"

PICKLE_STRING = os.environ.get("PICKLE_STRING", False)
Expand Down Expand Up @@ -298,7 +298,6 @@ def get_timeline_section(document_id):
service = get_google_service("docs", "v1")
document = service.documents().get(documentId=document_id).execute()
content = document.get("body").get("content")
print("In google, content is", content)

timeline_content = ""
record = False
Expand Down Expand Up @@ -354,8 +353,17 @@ def replace_text_between_headings(doc_id, new_content, start_heading, end_headin
break

if start_index is not None and end_index is not None:
# Format new content with new lines for proper insertion
formatted_content = "\n" + new_content + "\n"
# Format new content with new lines for proper insertion. We need to make sure that the formatted string contains only one
# leading and trailing newline character
# Split the string into three parts: leading newlines, core content, and trailing newlines
leading_newlines = len(new_content) - len(new_content.lstrip("\n"))
trailing_newlines = len(new_content) - len(new_content.rstrip("\n"))
core_content = new_content[
leading_newlines : len(new_content) - trailing_newlines
]

# Ensure only one newline at the start and one at the end, preserving internal newlines
formatted_content = "\n" + core_content + "\n"
content_length = len(formatted_content)

# Perform the replacement
Expand Down Expand Up @@ -395,7 +403,7 @@ def replace_text_between_headings(doc_id, new_content, start_heading, end_headin
{
"updateParagraphStyle": {
"range": {
"startIndex": start_index + 1,
"startIndex": start_index,
"endIndex": (
start_index + content_length
), # Adjust this index based on the length of the text
Expand Down
3 changes: 1 addition & 2 deletions app/tests/intergrations/test_google_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from unittest.mock import patch

# Constants for the test
START_HEADING = "Detailed Timeline"
START_HEADING = "DO NOT REMOVE this line as the SRE bot needs it as a placeholder."
END_HEADING = "Trigger"


Expand Down Expand Up @@ -251,7 +251,6 @@ def test_extract_timeline_content(mock_service):
# Mock document content
content = [START_HEADING, "Timeline content", END_HEADING]
mock_document = create_mock_document(content)
print("Mock document is ", mock_document)
mock_service.return_value.documents().get().execute.return_value = mock_document

result = google_drive.get_timeline_section("document_id")
Expand Down

0 comments on commit 9a0aaab

Please sign in to comment.