Skip to content

Commit

Permalink
Get rid of commit sha in emails
Browse files Browse the repository at this point in the history
  • Loading branch information
dostuffthatmatters committed Feb 17, 2023
1 parent a2cebac commit dbd7a1a
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions packages/core/utils/exception_email_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import smtplib, ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import subprocess
import traceback
from typing import Optional
from packages.core import types

dir = os.path.dirname
Expand All @@ -20,26 +18,6 @@ def get_pyra_version() -> str:
return pyra_version


def get_commit_sha() -> Optional[str]:
"""Get the current commit sha of the PYRA codebase
Returns None if git is not installed or directory is
a git repository."""
commit_sha_process = subprocess.run(
["git", "rev-parse", "--verify", "HEAD", "--short"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
if commit_sha_process.returncode == 0:
stdout = commit_sha_process.stdout.decode()
commit_sha = stdout.replace("\n", "").replace(" ", "")
assert len(commit_sha) > 0
if "fatal: not a git repository" in stdout:
return None
return commit_sha
else:
return None


def get_current_log_lines() -> list[str]:
"""Get the log line from the current info.log file. Only
returns the log lines from the latest two iterations.
Expand Down Expand Up @@ -129,7 +107,6 @@ def handle_occured_exception(config: types.ConfigDict, exception: Exception) ->
return

pyra_version = get_pyra_version()
commit_sha = get_commit_sha()
current_log_lines = get_current_log_lines()

tb = "\n".join(traceback.format_exception(exception))
Expand All @@ -138,9 +115,7 @@ def handle_occured_exception(config: types.ConfigDict, exception: Exception) ->
text = (
f"{type(exception).__name__} has occured. Details:\n"
+ f"{tb}\nLast 2 iteration's log lines:{logs}\n"
+ f"This email has been generated by Pyra {pyra_version} "
+ (f"(commit {commit_sha}) " if commit_sha is not None else "")
+ "automatically."
+ f"This email has been generated by Pyra {pyra_version}."
)

pre_tag = '<pre style="background-color: #f1f5f9; color: #334155; padding: 8px 8px 12px 12px; border-radius: 3px; max-width: full; overflow-x: scroll;">'
Expand All @@ -152,7 +127,7 @@ def handle_occured_exception(config: types.ConfigDict, exception: Exception) ->
+ f" {pre_tag}<code>{tb}</code></pre>"
+ " <p><strong>Last 2 iteration's log lines:</strong></p>"
+ f" {pre_tag}<code>{logs}</code></pre>"
+ f" <p><em>This email has been generated by Pyra {pyra_version} (commit {commit_sha}) automatically.</em></p>"
+ f" <p><em>This email has been generated by Pyra {pyra_version}.</em></p>"
+ " </body>"
+ "</html>"
)
Expand Down

0 comments on commit dbd7a1a

Please sign in to comment.