[v3] Send request notifications to co-maintainers

Message ID 20210711182916.59048-1-bert@bertptrs.nl
State New
Headers show
Series [v3] Send request notifications to co-maintainers | expand

Commit Message

Bert Peters July 11, 2021, 6:29 p.m. UTC
This is in addition to the current recipients. Co-maintainers should
also be made aware when their package has pending requests.
---
This version addresses an issue in the previous patch that caused
notifications to fail if the package has no co-maintainers.

In addition, I've added a unit test that checks the new desired
behaviour.

 aurweb/scripts/notify.py |  6 ++++++
 test/t2500-notify.t      | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)

Patch

diff --git a/aurweb/scripts/notify.py b/aurweb/scripts/notify.py
index 7f8e7168..1fb4707b 100755
--- a/aurweb/scripts/notify.py
+++ b/aurweb/scripts/notify.py
@@ -435,9 +435,12 @@  class RequestOpenNotification(Notification):
         cur = conn.execute('SELECT DISTINCT Users.Email FROM PackageRequests ' +
                            'INNER JOIN PackageBases ' +
                            'ON PackageBases.ID = PackageRequests.PackageBaseID ' +
+                           'LEFT JOIN PackageComaintainers ' +
+                           'ON PackageComaintainers.PackageBaseID = PackageRequests.PackageBaseID ' +
                            'INNER JOIN Users ' +
                            'ON Users.ID = PackageRequests.UsersID ' +
                            'OR Users.ID = PackageBases.MaintainerUID ' +
+                           'OR Users.ID = PackageComaintainers.UsersID ' +
                            'WHERE PackageRequests.ID = ? AND ' +
                            'Users.Suspended = 0', [reqid])
         self._to = aurweb.config.get('options', 'aur_request_ml')
@@ -492,9 +495,12 @@  class RequestCloseNotification(Notification):
         cur = conn.execute('SELECT DISTINCT Users.Email FROM PackageRequests ' +
                            'INNER JOIN PackageBases ' +
                            'ON PackageBases.ID = PackageRequests.PackageBaseID ' +
+                           'LEFT JOIN PackageComaintainers ' +
+                           'ON PackageComaintainers.PackageBaseID = PackageRequests.PackageBaseID ' +
                            'INNER JOIN Users ' +
                            'ON Users.ID = PackageRequests.UsersID ' +
                            'OR Users.ID = PackageBases.MaintainerUID ' +
+                           'OR Users.ID = PackageComaintainers.UsersID ' +
                            'WHERE PackageRequests.ID = ? AND ' +
                            'Users.Suspended = 0', [reqid])
         self._to = aurweb.config.get('options', 'aur_request_ml')
diff --git a/test/t2500-notify.t b/test/t2500-notify.t
index 713b31e3..c0592c91 100755
--- a/test/t2500-notify.t
+++ b/test/t2500-notify.t
@@ -369,6 +369,23 @@  test_expect_success 'Test subject and body of request close notifications (auto-
 	test_cmp actual expected
 '
 
+test_expect_success 'Test Cc of request close notification with co-maintainer.' '
+	cat <<-EOD | sqlite3 aur.db &&
+	/* Use package base IDs which can be distinguished from user IDs. */
+	INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1001, 3, 1);
+	EOD
+	>sendmail.out &&
+	"$NOTIFY" request-close 0 3001 accepted &&
+	grep ^Cc: sendmail.out >actual &&
+	cat <<-EOD >expected &&
+	Cc: user@localhost, tu@localhost, dev@localhost
+	EOD
+	test_cmp actual expected &&
+	cat <<-EOD | sqlite3 aur.db
+	DELETE FROM PackageComaintainers;
+	EOD
+'
+
 test_expect_success 'Test subject and body of request close notifications with closure comment.' '
 	cat <<-EOD | sqlite3 aur.db &&
 	UPDATE PackageRequests SET ClosureComment = "This is a test closure comment." WHERE ID = 3001;