From 64072461dfcc74857087b23c9ba7d9812b6afe40 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Tue, 10 Nov 2015 20:18:13 +0100 Subject: Add support for package update notifications Introduce a new notification option to receive notifications when a new commit is pushed to a package repository. Implements FS#30109. Signed-off-by: Lukas Fleischer --- scripts/notify.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'scripts') diff --git a/scripts/notify.py b/scripts/notify.py index 6b106009..56534ae7 100755 --- a/scripts/notify.py +++ b/scripts/notify.py @@ -105,6 +105,16 @@ def get_comment_recipients(cur, pkgbase_id, uid): return [row[0] for row in cur.fetchall()] +def get_update_recipients(cur, pkgbase_id, uid): + cur.execute('SELECT DISTINCT Users.Email FROM Users ' + + 'INNER JOIN PackageNotifications ' + + 'ON PackageNotifications.UserID = Users.ID WHERE ' + + 'Users.UpdateNotify = 1 AND ' + + 'PackageNotifications.UserID != %s AND ' + + 'PackageNotifications.PackageBaseID = %s', [uid, pkgbase_id]) + return [row[0] for row in cur.fetchall()] + + def get_request_recipients(cur, pkgbase_id, uid): cur.execute('SELECT DISTINCT Users.Email FROM Users ' + 'INNER JOIN PackageBases ' + @@ -189,6 +199,28 @@ def comment(cur, uid, pkgbase_id, comment_id): send_notification(to, subject, body, refs, headers) +def update(cur, uid, pkgbase_id): + user = username_from_id(cur, uid) + pkgbase = pkgbase_from_id(cur, pkgbase_id) + to = get_update_recipients(cur, pkgbase_id, uid) + + user_uri = aur_location + '/account/' + user + '/' + pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/' + + subject = 'AUR Package Update: %s' % (pkgbase) + body = '%s [1] pushed a new commit to %s [2].' % (user, pkgbase) + body += '\n\n' + body += 'If you no longer wish to receive notifications about this ' \ + 'package, please go to the package page [2] and select "%s".' % \ + ('Disable notifications') + refs = '[1] ' + user_uri + '\n' + refs += '[2] ' + pkgbase_uri + thread_id = '' + headers = headers_reply(thread_id) + + send_notification(to, subject, body, refs, headers) + + def flag(cur, uid, pkgbase_id): user = username_from_id(cur, uid) pkgbase = pkgbase_from_id(cur, pkgbase_id) @@ -327,6 +359,7 @@ if __name__ == '__main__': 'send-resetkey': send_resetkey, 'welcome': welcome, 'comment': comment, + 'update': update, 'flag': flag, 'comaintainer-add': comaintainer_add, 'comaintainer-remove': comaintainer_remove, -- cgit v1.2.3-24-g4f1b