Skip to content

Commit

Permalink
feat: added management commands for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
c0rydoras committed Oct 24, 2023
1 parent 575b4a8 commit 7eb2835
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
Empty file.
Empty file.
18 changes: 18 additions & 0 deletions api/outdated/notifications/management/commands/notify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from outdated.commands import ProjectCommand
from outdated.notifications.notifier import Notifier


class Command(ProjectCommand):
help = "Send notifications to given projects."

def _handle(self, project):
if not project.maintainers.all():
self.stdout.write(
f"Skipped {project.name} (no-maintainers)", self.style.WARNING
)
return
elif project.duration_until_outdated is None:
return

Notifier(project).notify()
self.stdout.write(f"Notified {project}", self.style.SUCCESS)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from datetime import timedelta

from django.conf import settings
from django.core.management.base import BaseCommand

from outdated.notifications.models import Notification


class Command(BaseCommand):
help = "Update notifications to match those in settings.py"

def handle(self, *args, **options):
notifications = []
for template, schedule in settings.NOTIFICATIONS:
notifications.append(
Notification.objects.get_or_create(
template=template, schedule=timedelta(days=schedule)
)[0]
)
[n.delete() for n in Notification.objects.all() if n not in notifications]

0 comments on commit 7eb2835

Please sign in to comment.