forked from isacarvid/PR-review-notification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (61 loc) · 2.08 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import smtplib, ssl
def sendEmail(username, password, domain, toAddress, msg):
port = 465
context = ssl.create_default_context()
server = ""
with smtplib.SMTP_SSL(domain, port, context=context) as server:
server.login(username, password)
server.sendmail(username, toAddress, msg)
def emailFinder(readme):
mails = []
for line in readme:
addr_prefix = ""
addr_suffix = ""
domain_index = 0
while domain_index < len(line):
domain_index = line.find("@", domain_index)
if domain_index == -1: # no emails on this line
break
start_index = domain_index
while start_index >= 0:
if line[start_index] == ' ':
start_index += 1
break
if start_index == 0:
break
start_index -= 1
end_index = domain_index
while end_index < len(line):
if line[end_index] == ' ':
break
if end_index == len(line)-1:
break
end_index += 1
mails.append(line[start_index:end_index])
domain_index += 1 # 1 is len("@")
return mails
def main():
file_path = os.environ["INPUT_FILEPATH"]
username = os.environ["INPUT_USERNAMESECRET"]
pwd = os.environ["INPUT_PASSWORDSECRET"]
domain = os.environ["INPUT_DOMAINSECRET"]
keyword = os.environ["INPUT_KEYWORD"]
message = """\
Subject: Kth devops
You recieved a comment on your PR."""
readme = []
for file in file_path.splitlines():
if file.find("README") != -1:
readme = open(file).readlines()
notify = False
for line in readme:
if keyword in line:
notify = True
break
if notify:
mails = emailFinder(readme)
for to_addr in mails:
sendEmail(username, pwd, domain, to_addr, message)
if __name__ == "__main__":
main()