-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added notifier and notify command
- Loading branch information
Showing
5 changed files
with
285 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from outdated.outdated.models import Project | ||
from outdated.outdated.notifier import send | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Sends email notification to maintainers when project outdated/warning" | ||
|
||
def handle(self, *args, **options): | ||
for project in Project.objects.all(): | ||
send(project) | ||
print("Finished") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from datetime import date | ||
|
||
from django.core.mail import EmailMessage | ||
|
||
from outdated.outdated import models | ||
|
||
|
||
def _get_day_difference(version: models.Version) -> str: | ||
values = [(version.end_of_life, "in"), (date.today(), "since")] | ||
if version.status == "OUTDATED": | ||
values = values[::-1] | ||
return f"{values[0][1]} {(values[0][0] - values[1][0]).days} days" | ||
|
||
|
||
def send(project: models.Project): | ||
if not project.maintainers or project.status in ["UP_TO_DATE", "UNDEFINED"]: | ||
return | ||
|
||
is_outdated = project.status == "OUTDATED" | ||
|
||
to = [project.maintainers.get(is_primary=True).user.email] | ||
cc = [ | ||
maintainer.user.email | ||
for maintainer in project.maintainers.filter(is_primary=False) | ||
if is_outdated | ||
] | ||
|
||
subject = ( | ||
"Your project is out of date!" | ||
if is_outdated | ||
else "Your project will be out of date soon!" | ||
) | ||
|
||
project_info = f"Project: {project.name}\nRepo: {project.repo}\n" | ||
message = ( | ||
"Your project has some dependencies that have reached their EOL. This means they are no longer stable or supported and may have security vulnerabilities or compatibility problems. You should update them to the next LTS version immediately to fix these issues." | ||
if is_outdated | ||
else "Your project has some dependencies that will reach their EOL soon. You should consider updating them as soon as possible to avoid potential issues." | ||
) | ||
|
||
dependency_lines = [ | ||
# make it so current LTS version alighs with itself on all occasions | ||
f"{str(vd.dependency) + ':': <26s} current LTS version {str(vd.version)+',': <9s} EOL {_get_day_difference(vd)}" | ||
for vd in project.versioned_dependencies.all() | ||
if vd.status in ["OUTDATED", "WARNING"] | ||
] | ||
|
||
body = f"{project_info}{message}\nHere is a list of the dependencies:\n\n" | ||
body += "\n".join(dependency_lines) | ||
|
||
email_message = EmailMessage(subject, body, to=to, cc=cc) | ||
return email_message.send() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,10 +177,10 @@ def default(default_dev=env.NOTSET, default_prod=env.NOTSET): | |
SERVER_EMAIL = env.str("SERVER_EMAIL", EMAIL_HOST_USER) | ||
EMAIL_HOST_PASSWORD = env.str("EMAIL_HOST_PASSWORD", "") | ||
EMAIL_USE_TLS = env.bool("EMAIL_USE_TLS", False) | ||
|
||
from_name = env.str("MAILING_FROM_NAME", "outdated") | ||
from_mail = env.str("MAILING_FROM_MAIL", "[email protected]") | ||
MAILING = {"from_email": from_mail, "from_name": from_name} | ||
MAILING_SENDER = f"{from_name} <{from_mail}>" | ||
DEFAULT_FROM_EMAIL = f"{from_name} <{from_mail}>" | ||
|
||
# Syncproject settings | ||
RELEVANT_DEPENDENCIES = [ | ||
|
Oops, something went wrong.