@@ -95,56 +95,17 @@ def format_repo_event(repo, action):
9595 updated_at = convert_to_utc4 (repo .get ("updated_at" ))
9696 url = repo .get ("html_url" , "" )
9797
98- # Special cases for visibility changes
99- if action == "publicized" :
100- subject = f"[GitHub Alert] Repository changed from PRIVATE → PUBLIC: { repo_name } "
101- body = (
102- f"The repository visibility has been changed.\n \n "
103- f"➡️ Now PUBLIC\n \n "
104- f"📌 Repository Name: { repo_name } \n "
105- f"{ visibility_icon } \n "
106- f"👤 Owner: { owner } \n "
107- f"🌿 Default branch: { default_branch } \n "
108- f"🕒 Created at: { created_at } \n "
109- f"🕒 Last updated: { updated_at } \n "
110- f"🌍 URL: { url } \n "
111- )
112- elif action == "privatized" :
113- subject = f"[GitHub Alert] Repository changed from PUBLIC → PRIVATE: { repo_name } "
114- body = (
115- f"The repository visibility has been changed.\n \n "
116- f"➡️ Now PRIVATE\n \n "
117- f"📌 Repository Name: { repo_name } \n "
118- f" Visibility: { visibility_icon } \n "
119- f"👤 Owner: { owner } \n "
120- f"🌿 Default branch: { default_branch } \n "
121- f"🕒 Created at: { created_at } \n "
122- f"🕒 Last updated: { updated_at } \n "
123- f"🌍 URL: { url } \n "
124- )
125- else :
126- # Generic events
127- action_labels = {
128- "created" : "Repository created" ,
129- "deleted" : "Repository deleted" ,
130- "archived" : "Repository archived" ,
131- "unarchived" : "Repository unarchived" ,
132- "edited" : "Repository edited" ,
133- "renamed" : "Repository renamed" ,
134- "transferred" : "Repository transferred"
135- }
136- subject = f"[GitHub Alert] { action_labels .get (action , action )} : { repo_name } "
137- body = (
138- f"A repository event occurred: { action_labels .get (action , action )} \n \n "
139- f"📌 Repository Name: { repo_name } \n "
140- f"{ visibility_icon } \n "
141- f"👤 Owner: { owner } \n "
142- f"🌿 Default branch: { default_branch } \n "
143- f"🕒 Created at: { created_at } \n "
144- f"🕒 Last updated: { updated_at } \n "
145- f"🌍 URL: { url } \n "
146- )
147-
98+ subject = f"[GitHub Alert] Repository { action } : { repo_name } "
99+ body = (
100+ f"A repository was { action } in your GitHub organization.\n \n "
101+ f"📌 Repository Name: { repo_name } \n "
102+ f"{ visibility_icon } \n "
103+ f"👤 Owner: { owner } \n "
104+ f"🌿 Default branch: { default_branch } \n "
105+ f"🕒 Created at: { created_at } \n "
106+ f"🕒 Last updated: { updated_at } \n "
107+ f"🌍 URL: { url } \n "
108+ )
148109 return subject , body
149110
150111# --- GitHub Webhook + Health Handlers ---
@@ -170,19 +131,13 @@ def github_webhook():
170131 return "❌ Bad payload" , 400
171132
172133 event = request .headers .get ("X-GitHub-Event" , "" )
173- action = data .get ("action" )
174-
175- repo_actions = [
176- "created" , "deleted" , "archived" , "unarchived" ,
177- "publicized" , "privatized" , "edited" , "renamed" , "transferred"
178- ]
179134
180- if event == "repository" and action in repo_actions :
181- subject , body = format_repo_event (data ["repository" ], action )
135+ if event == "repository" and data . get ( " action" ) in [ "created" , "deleted" ] :
136+ subject , body = format_repo_event (data ["repository" ], data [ " action" ] )
182137 print (f"📩 Sending email alert: { subject } " )
183138 send_email_via_graph (subject , body )
184139 else :
185- print (f"ℹ️ Ignored event: { event } , action: { action } " )
140+ print (f"ℹ️ Ignored event: { event } , action: { data . get ( ' action' ) } " )
186141
187142 return "OK" , 200
188143
@@ -195,17 +150,16 @@ def health_check():
195150 if TEST_MODE :
196151 print ("🔹 TEST_MODE: sending test email" )
197152 test_repo = {
198- "full_name" : "quantori/test-repo " ,
199- "private" : False ,
153+ "full_name" : "quantori/sadsrepo " ,
154+ "private" : True ,
200155 "owner" : {"login" : "quantori" },
201156 "default_branch" : "main" ,
202157 "created_at" : "2025-09-09T13:06:02Z" ,
203158 "updated_at" : "2025-09-09T13:09:20Z" ,
204- "html_url" : "https://github.com/quantori/test-repo "
159+ "html_url" : "https://github.com/quantori/sadsrepo "
205160 }
206- subject , body = format_repo_event (test_repo , "publicized " )
161+ subject , body = format_repo_event (test_repo , "created " )
207162 send_email_via_graph (subject , body )
208163 else :
209164 print ("✅ Flask is up and listening on /webhook and /health" )
210- port = int (os .environ .get ("PORT" , 8000 ))
211- app .run (host = "0.0.0.0" , port = port )
165+ app .run (host = "0.0.0.0" , port = 8000 )
0 commit comments