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 Aug 9, 2023
1 parent 857d396 commit fdf0fbb
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 fdf0fbb

Please sign in to comment.