blob: c10083b3096ae6f6ea6e18cd4d9ae6ca6353e665 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# Copyright 2018 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
Copybara854996b2021-09-07 19:36:02 +00004
5"""Functions that prepare and send email notifications of issue changes."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
10
11import logging
12
13from features import features_constants
14from framework import cloud_tasks_helpers
15from framework import framework_constants
16from framework import urls
17from tracker import tracker_bizobj
18
19
20def PrepareAndSendIssueChangeNotification(
21 issue_id, hostport, commenter_id, send_email=True,
22 old_owner_id=framework_constants.NO_USER_SPECIFIED, comment_id=None):
23 """Create a task to notify users that an issue has changed.
24
25 Args:
26 issue_id: int ID of the issue that was changed.
27 hostport: string domain name and port number from the HTTP request.
28 commenter_id: int user ID of the user who made the comment.
29 send_email: True if email notifications should be sent.
30 old_owner_id: optional user ID of owner before the current change took
31 effect. They will also be notified.
32 comment_id: int Comment ID of the comment that was entered.
33
34 Returns nothing.
35 """
36 if old_owner_id is None:
37 old_owner_id = framework_constants.NO_USER_SPECIFIED
38 params = dict(
39 issue_id=issue_id, commenter_id=commenter_id, comment_id=comment_id,
40 hostport=hostport, old_owner_id=old_owner_id, send_email=int(send_email))
41 task = cloud_tasks_helpers.generate_simple_task(
42 urls.NOTIFY_ISSUE_CHANGE_TASK + '.do', params)
43 cloud_tasks_helpers.create_task(
44 task, queue=features_constants.QUEUE_NOTIFICATIONS)
45
46 task = cloud_tasks_helpers.generate_simple_task(
47 urls.PUBLISH_PUBSUB_ISSUE_CHANGE_TASK + '.do', params)
48 cloud_tasks_helpers.create_task(task, queue=features_constants.QUEUE_PUBSUB)
49
50
51def PrepareAndSendIssueBlockingNotification(
52 issue_id, hostport, delta_blocker_iids, commenter_id, send_email=True):
53 """Create a task to follow up on an issue blocked_on change."""
54 if not delta_blocker_iids:
55 return # No notification is needed
56
57 params = dict(
58 issue_id=issue_id, commenter_id=commenter_id, hostport=hostport,
59 send_email=int(send_email),
60 delta_blocker_iids=','.join(str(iid) for iid in delta_blocker_iids))
61
62 task = cloud_tasks_helpers.generate_simple_task(
63 urls.NOTIFY_BLOCKING_CHANGE_TASK + '.do', params)
64 cloud_tasks_helpers.create_task(
65 task, queue=features_constants.QUEUE_NOTIFICATIONS)
66
67
68def PrepareAndSendApprovalChangeNotification(
69 issue_id, approval_id, hostport, comment_id, send_email=True):
70 """Create a task to follow up on an approval change."""
71
72 params = dict(
73 issue_id=issue_id, approval_id=approval_id, hostport=hostport,
74 comment_id=comment_id, send_email=int(send_email))
75
76 task = cloud_tasks_helpers.generate_simple_task(
77 urls.NOTIFY_APPROVAL_CHANGE_TASK + '.do', params)
78 cloud_tasks_helpers.create_task(
79 task, queue=features_constants.QUEUE_NOTIFICATIONS)
80
81
82def SendIssueBulkChangeNotification(
83 issue_ids, hostport, old_owner_ids, comment_text, commenter_id,
84 amendments, send_email, users_by_id):
85 """Create a task to follow up on an issue blocked_on change."""
86 amendment_lines = []
87 for up in amendments:
88 line = ' %s: %s' % (
89 tracker_bizobj.GetAmendmentFieldName(up),
90 tracker_bizobj.AmendmentString(up, users_by_id))
91 if line not in amendment_lines:
92 amendment_lines.append(line)
93
94 params = dict(
95 issue_ids=','.join(str(iid) for iid in issue_ids),
96 commenter_id=commenter_id, hostport=hostport, send_email=int(send_email),
97 old_owner_ids=','.join(str(uid) for uid in old_owner_ids),
98 comment_text=comment_text, amendments='\n'.join(amendment_lines))
99
100 task = cloud_tasks_helpers.generate_simple_task(
101 urls.NOTIFY_BULK_CHANGE_TASK + '.do', params)
102 cloud_tasks_helpers.create_task(
103 task, queue=features_constants.QUEUE_NOTIFICATIONS)
104
105
106def PrepareAndSendDeletedFilterRulesNotification(
107 project_id, hostport, filter_rule_strs):
108 """Create a task to notify project owners of deleted filter rules."""
109
110 params = dict(
111 project_id=project_id, filter_rules=','.join(filter_rule_strs),
112 hostport=hostport)
113
114 task = cloud_tasks_helpers.generate_simple_task(
115 urls.NOTIFY_RULES_DELETED_TASK + '.do', params)
116 cloud_tasks_helpers.create_task(
117 task, queue=features_constants.QUEUE_NOTIFICATIONS)