github-email-alert 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: github-email-alert
3
+ Version: 0.1.0
4
+ Summary: Reusable GitHub Email Alert package for CI/CD workflows
5
+ Author: Pandiyaraj Karuppasamy
6
+ Requires-Python: >=3.8
File without changes
@@ -0,0 +1,18 @@
1
+ [project]
2
+ name = "github-email-alert"
3
+ version = "0.1.0"
4
+ description = "Reusable GitHub Email Alert package for CI/CD workflows"
5
+ readme = "README.md"
6
+ requires-python = ">=3.8"
7
+ authors = [{ name = "Pandiyaraj Karuppasamy" }]
8
+ dependencies = []
9
+
10
+ [project.scripts]
11
+ github-email-alert = "github_email_alert.cli:main"
12
+
13
+ [build-system]
14
+ requires = ["hatchling"]
15
+ build-backend = "hatchling.build"
16
+
17
+ [tool.hatch.build.targets.wheel]
18
+ packages = ["src/github_email_alert"]
@@ -0,0 +1,51 @@
1
+ import os
2
+ import argparse
3
+ from .emailer import send_email
4
+ from .templates import build_email
5
+
6
+
7
+ def parse_list(value):
8
+ if not value:
9
+ return []
10
+ return [x.strip() for x in value.split(",") if x.strip()]
11
+
12
+
13
+ def main():
14
+ parser = argparse.ArgumentParser(description="GitHub Email Alert")
15
+ parser.add_argument("branch_ref")
16
+ parser.add_argument("event_type")
17
+
18
+ args = parser.parse_args()
19
+
20
+ context = {
21
+ "actor": os.getenv("GITHUB_ACTOR", "Unknown"),
22
+ "pr_title": os.getenv("PR_TITLE", "N/A"),
23
+ "branch_ref": args.branch_ref,
24
+ "base_ref": os.getenv("BASE_REF", "main"),
25
+ "repo_name": os.getenv("REPO_NAME", "Unknown"),
26
+ }
27
+
28
+ email_user = os.getenv("EMAIL_USER")
29
+ email_pass = os.getenv("EMAIL_PASS")
30
+ email_to = parse_list(os.getenv("EMAIL_TO"))
31
+ email_cc = parse_list(os.getenv("EMAIL_CC"))
32
+
33
+ if not all([email_user, email_pass, email_to]):
34
+ raise ValueError("EMAIL_USER, EMAIL_PASS, EMAIL_TO required")
35
+
36
+ subject, body = build_email(args.event_type, context)
37
+
38
+ send_email(
39
+ smtp_host=os.getenv("SMTP_HOST", "smtp.gmail.com"),
40
+ smtp_port=int(os.getenv("SMTP_PORT", 587)),
41
+ email_user=email_user,
42
+ email_pass=email_pass,
43
+ to_list=email_to,
44
+ cc_list=email_cc,
45
+ subject=subject,
46
+ body=body,
47
+ )
48
+
49
+
50
+ if __name__ == "__main__":
51
+ main()
@@ -0,0 +1,31 @@
1
+ import smtplib
2
+ from email.mime.multipart import MIMEMultipart
3
+ from email.mime.text import MIMEText
4
+
5
+
6
+ def send_email(
7
+ smtp_host,
8
+ smtp_port,
9
+ email_user,
10
+ email_pass,
11
+ to_list,
12
+ cc_list,
13
+ subject,
14
+ body,
15
+ ):
16
+ msg = MIMEMultipart()
17
+ msg["From"] = email_user
18
+ msg["To"] = ", ".join(to_list)
19
+
20
+ if cc_list:
21
+ msg["Cc"] = ", ".join(cc_list)
22
+
23
+ msg["Subject"] = subject
24
+ msg.attach(MIMEText(body, "html"))
25
+
26
+ recipients = to_list + cc_list
27
+
28
+ with smtplib.SMTP(smtp_host, smtp_port) as server:
29
+ server.starttls()
30
+ server.login(email_user, email_pass)
31
+ server.sendmail(email_user, recipients, msg.as_string())
@@ -0,0 +1,40 @@
1
+ def build_email(event_type, context):
2
+ templates = {
3
+ "new_pr": {
4
+ "subject": f"🆕 [NEW PR] {context['pr_title']}",
5
+ "header": "New Pull Request Created",
6
+ "color": "#0076D7",
7
+ },
8
+ "merge_pr": {
9
+ "subject": f"✅ [MERGED PR] {context['pr_title']}",
10
+ "header": "Pull Request Merged",
11
+ "color": "#28A745",
12
+ },
13
+ "conflict": {
14
+ "subject": f"⚠️ [CONFLICT] {context['branch_ref']}",
15
+ "header": "Merge Conflict Detected",
16
+ "color": "#DC3545",
17
+ },
18
+ }
19
+
20
+ template = templates.get(event_type)
21
+
22
+ if not template:
23
+ return f"[TEST] {event_type}", "<h2>Test Email</h2>"
24
+
25
+ body = f"""
26
+ <html>
27
+ <body>
28
+ <h2 style="color:{template['color']};">{template['header']}</h2>
29
+ <p><strong>Actor:</strong> {context['actor']}</p>
30
+ <p><strong>Title:</strong> {context['pr_title']}</p>
31
+ <p><strong>Source Branch:</strong> {context['branch_ref']}</p>
32
+ <p><strong>Target Branch:</strong> {context['base_ref']}</p>
33
+ <p><strong>Repository:</strong> {context['repo_name']}</p>
34
+ <hr>
35
+ <p><em>Automated GitHub Notification</em></p>
36
+ </body>
37
+ </html>
38
+ """
39
+
40
+ return template["subject"], body
@@ -0,0 +1,6 @@
1
+ def main():
2
+ print("Hello from github-email-alert!")
3
+
4
+
5
+ if __name__ == "__main__":
6
+ main()
@@ -0,0 +1,12 @@
1
+ version = 1
2
+ revision = 3
3
+ requires-python = ">=3.8"
4
+ resolution-markers = [
5
+ "python_full_version >= '3.9'",
6
+ "python_full_version < '3.9'",
7
+ ]
8
+
9
+ [[package]]
10
+ name = "github-email-alert"
11
+ version = "0.1.0"
12
+ source = { editable = "." }