Skip to content

Commit aa72013

Browse files
authored
Update get_email_webhook.py
1 parent 12637e8 commit aa72013

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

get_email_webhook.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import hashlib
55
import requests
66
from msal import ConfidentialClientApplication
7+
from datetime import datetime, timezone, timedelta
78

89
# --- Determine mode ---
910
TEST_MODE = os.getenv("TEST_MODE", "true").lower() == "true"
@@ -72,14 +73,26 @@ def verify_github_signature(payload_body, signature, secret):
7273
expected_signature = "sha256=" + mac.hexdigest()
7374
return hmac.compare_digest(expected_signature, signature)
7475

76+
# --- Convert UTC timestamp to UTC+4 ---
77+
def convert_to_utc4(timestamp):
78+
if not timestamp:
79+
return "N/A"
80+
try:
81+
dt_utc = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc)
82+
dt_utc4 = dt_utc.astimezone(timezone(timedelta(hours=4)))
83+
return dt_utc4.strftime("%Y-%m-%d %H:%M:%S")
84+
except Exception as e:
85+
print(f"⚠️ Failed to convert timestamp {timestamp}: {e}")
86+
return timestamp
87+
7588
# --- Format GitHub repository event for email ---
7689
def format_repo_event(repo, action):
7790
repo_name = repo["full_name"]
7891
visibility_icon = "🔒 Private" if repo.get("private") else "🌐 Public"
7992
owner = repo["owner"]["login"]
8093
default_branch = repo.get("default_branch", "N/A")
81-
created_at = repo.get("created_at", "").replace("T", " ").replace("Z", "")
82-
updated_at = repo.get("updated_at", "").replace("T", " ").replace("Z", "")
94+
created_at = convert_to_utc4(repo.get("created_at"))
95+
updated_at = convert_to_utc4(repo.get("updated_at"))
8396
url = repo.get("html_url", "")
8497

8598
subject = f"[GitHub Alert] Repository {action}: {repo_name}"

0 commit comments

Comments
 (0)