-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.py
157 lines (111 loc) · 4.82 KB
/
script.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Included Python modules
import requests
import smtplib
from email import message
import datetime
import os
# Modules from pip
import libversion
import jira
from dotenv import load_dotenv
###############################################################################
load_dotenv()
# Misc
date = datetime.datetime.today().strftime('%Y-%m-%d')
ignored_packages = os.getenv('IGNORED_PACKAGES').split(',')
# SMTP Setup and Template
smtp_server = os.getenv('SMTP_SERVER')
smtp_port = os.getenv('SMTP_PORT')
sender = os.getenv('SENDER')
destination = os.getenv('DESTINATION')
smtp_username = os.getenv('SMTP_USERNAME')
smtp_password = os.getenv('SMTP_PASSWORD')
email_subtype = "plain"
email_subject = "yiffOS package updates for " + date
email_packages_that_need_updates = ""
email_packages_that_have_jira_issues = ""
email_packages_with_issues = ""
# Jira Setup
jira = jira.JIRA("https://yiffos.atlassian.net/", basic_auth=(os.getenv("JIRA_EMAIL"), os.getenv("JIRA_TOKEN")))
# API Setup
toolchain = "knot"
api_endpoint = "https://repology.org/api/v1/"
complete_query = api_endpoint + "projects/?search=&maintainer=&category=&inrepo=yiffos_knot¬inrepo=&repos=&families=&repos_newest=&families_newest=&outdated=on"
########################################################################################################################
complete_response = requests.get(complete_query).json()
complete_keys = list(complete_response.keys())
for i in range(len(complete_keys)):
if complete_keys[i] in ignored_packages:
continue
package_name = "";
yiffos_version = "";
newest_version = "";
update_needed = 0;
legacy_version = False;
project_response = requests.get(api_endpoint + "project/" + complete_keys[i]).json()
for x in project_response:
if x["repo"] == "yiffos_" + toolchain:
package_name = x["srcname"]
yiffos_version = x["version"]
if x["status"] == "legacy":
legacy_version = True
elif x["status"] == "newest":
newest_version = x["version"]
if legacy_version:
continue
if newest_version != "":
update_needed = libversion.version_compare2(newest_version, yiffos_version)
print(package_name)
print("yiffOS version: " + yiffos_version)
print("Newer version: " + newest_version)
match update_needed:
case -1:
email_packages_with_issues += package_name + ": v" + yiffos_version + " (libversion reports that it's newer than upstream, upstream version: " + newest_version + ")\n"
print("yiffOS package is newer?")
case 0:
email_packages_with_issues += package_name + ": v" + yiffos_version + " (libversion reports that it's up to date, upstream version: " + newest_version + ")\n"
print("No update needed.")
case 1:
print("Update needed!")
if jira.search_issues("project = PAC AND text ~ \"" + package_name + " " + newest_version + "\"", maxResults=1):
email_packages_that_have_jira_issues += package_name + ": v" + yiffos_version + " --> v" + newest_version + "\n"
print("Issue already exists.")
else:
jira.create_issue(project="PAC", summary="Update " + package_name + " to v" + newest_version, description="The package " + package_name + " is outdated. Please update it to version " + newest_version + ".", issuetype="Improvement")
email_packages_that_need_updates += package_name + ": v" + yiffos_version + " --> v" + newest_version + "\n"
print("Issue created.")
########################################################################################################################
print("Sending email...")
if email_packages_that_need_updates == "":
email_packages_that_need_updates = "None!"
if email_packages_that_have_jira_issues == "":
email_packages_that_have_jira_issues = "None!"
if email_packages_with_issues == "":
email_packages_with_issues = "None!"
email_content = """\
This is the daily yiffOS package update report for {}
-------------------------------------------------------
New packages that need updating:
{}
Packages that still need updating:
{}
Packages with issues:
{}
""".format(date, email_packages_that_need_updates, email_packages_that_have_jira_issues, email_packages_with_issues)
try:
msg = message.EmailMessage()
msg.set_content(email_content)
msg["Subject"] = email_subject
msg["From"] = sender
conn = smtplib.SMTP(smtp_server, smtp_port)
conn.set_debuglevel(False)
conn.ehlo()
conn.starttls()
conn.login(smtp_username, smtp_password)
try:
conn.sendmail(sender, destination, msg.as_string())
finally:
conn.quit()
except smtplib.SMTPException as e:
print("Error: unable to send email")
print(e)