@@ -22,6 +22,8 @@ final class PhabricatorAuditCommentEditor {
22
22
private $ user ;
23
23
24
24
private $ attachInlineComments ;
25
+ private $ auditors = array ();
26
+ private $ ccs = array ();
25
27
26
28
public function __construct (PhabricatorRepositoryCommit $ commit ) {
27
29
$ this ->commit = $ commit ;
@@ -33,6 +35,16 @@ public function setUser(PhabricatorUser $user) {
33
35
return $ this ;
34
36
}
35
37
38
+ public function addAuditors (array $ auditor_phids ) {
39
+ $ this ->auditors = array_merge ($ this ->auditors , $ auditor_phids );
40
+ return $ this ;
41
+ }
42
+
43
+ public function addCCs (array $ cc_phids ) {
44
+ $ this ->ccs = array_merge ($ this ->ccs , $ cc_phids );
45
+ return $ this ;
46
+ }
47
+
36
48
public function setAttachInlineComments ($ attach_inline_comments ) {
37
49
$ this ->attachInlineComments = $ attach_inline_comments ;
38
50
return $ this ;
@@ -61,13 +73,39 @@ public function addComment(PhabricatorAuditComment $comment) {
61
73
->setTargetPHID ($ commit ->getPHID ())
62
74
->save ();
63
75
76
+ $ content_blocks = array ($ comment ->getContent ());
77
+
64
78
if ($ inline_comments ) {
65
79
foreach ($ inline_comments as $ inline ) {
66
80
$ inline ->setAuditCommentID ($ comment ->getID ());
67
81
$ inline ->save ();
82
+ $ content_blocks [] = $ inline ->getContent ();
83
+ }
84
+ }
85
+
86
+ $ ccs = $ this ->ccs ;
87
+ $ auditors = $ this ->auditors ;
88
+
89
+ $ metadata = $ comment ->getMetadata ();
90
+ $ metacc = array ();
91
+
92
+ // Find any "@mentions" in the content blocks.
93
+ $ mention_ccs = PhabricatorMarkupEngine::extractPHIDsFromMentions (
94
+ $ content_blocks );
95
+ if ($ mention_ccs ) {
96
+ $ metacc = idx (
97
+ $ metadata ,
98
+ PhabricatorAuditComment::METADATA_ADDED_CCS ,
99
+ array ());
100
+ foreach ($ mention_ccs as $ cc_phid ) {
101
+ $ metacc [] = $ cc_phid ;
68
102
}
69
103
}
70
104
105
+ if ($ metacc ) {
106
+ $ ccs = array_merge ($ ccs , $ metacc );
107
+ }
108
+
71
109
// When a user submits an audit comment, we update all the audit requests
72
110
// they have authority over to reflect the most recent status. The general
73
111
// idea here is that if audit has triggered for, e.g., several packages, but
@@ -114,7 +152,9 @@ public function addComment(PhabricatorAuditComment $comment) {
114
152
$ new_status = null ;
115
153
switch ($ action ) {
116
154
case PhabricatorAuditActionConstants::COMMENT :
117
- // Comments don't change audit statuses.
155
+ case PhabricatorAuditActionConstants::ADD_CCS :
156
+ case PhabricatorAuditActionConstants::ADD_AUDITORS :
157
+ // Commenting or adding cc's/auditors doesn't change status.
118
158
break ;
119
159
case PhabricatorAuditActionConstants::ACCEPT :
120
160
if (!$ user_is_author || $ request_is_for_user ) {
@@ -152,6 +192,8 @@ public function addComment(PhabricatorAuditComment $comment) {
152
192
$ new_status = null ;
153
193
switch ($ action ) {
154
194
case PhabricatorAuditActionConstants::COMMENT :
195
+ case PhabricatorAuditActionConstants::ADD_CCS :
196
+ case PhabricatorAuditActionConstants::ADD_AUDITORS :
155
197
$ new_status = PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED ;
156
198
break ;
157
199
case PhabricatorAuditActionConstants::ACCEPT :
@@ -181,12 +223,65 @@ public function addComment(PhabricatorAuditComment $comment) {
181
223
}
182
224
}
183
225
226
+ $ requests_by_auditor = mpull ($ requests , null , 'getAuditorPHID ' );
227
+ $ requests_phids = array_keys ($ requests_by_auditor );
228
+
229
+ $ ccs = array_diff ($ ccs , $ requests_phids );
230
+ $ auditors = array_diff ($ auditors , $ requests_phids );
231
+
232
+ if ($ action == PhabricatorAuditActionConstants::ADD_CCS ) {
233
+ if ($ ccs ) {
234
+ $ metadata [PhabricatorAuditComment::METADATA_ADDED_CCS ] = $ ccs ;
235
+ $ comment ->setMetaData ($ metadata );
236
+ } else {
237
+ $ comment ->setAction (PhabricatorAuditActionConstants::COMMENT );
238
+ }
239
+ }
240
+
241
+ if ($ action == PhabricatorAuditActionConstants::ADD_AUDITORS ) {
242
+ if ($ auditors ) {
243
+ $ metadata [PhabricatorAuditComment::METADATA_ADDED_AUDITORS ]
244
+ = $ auditors ;
245
+ $ comment ->setMetaData ($ metadata );
246
+ } else {
247
+ $ comment ->setAction (PhabricatorAuditActionConstants::COMMENT );
248
+ }
249
+ }
250
+
251
+ $ comment ->save ();
252
+
253
+ if ($ auditors ) {
254
+ foreach ($ auditors as $ auditor_phid ) {
255
+ $ audit_requested = PhabricatorAuditStatusConstants::AUDIT_REQUESTED ;
256
+ $ requests [] = id (new PhabricatorRepositoryAuditRequest ())
257
+ ->setCommitPHID ($ commit ->getPHID ())
258
+ ->setAuditorPHID ($ auditor_phid )
259
+ ->setAuditStatus ($ audit_requested )
260
+ ->setAuditReasons (
261
+ array ('Added by ' . $ user ->getUsername ()))
262
+ ->save ();
263
+ }
264
+ }
265
+
266
+ if ($ ccs ) {
267
+ foreach ($ ccs as $ cc_phid ) {
268
+ $ audit_cc = PhabricatorAuditStatusConstants::CC ;
269
+ $ requests [] = id (new PhabricatorRepositoryAuditRequest ())
270
+ ->setCommitPHID ($ commit ->getPHID ())
271
+ ->setAuditorPHID ($ cc_phid )
272
+ ->setAuditStatus ($ audit_cc )
273
+ ->setAuditReasons (
274
+ array ('Added by ' . $ user ->getUsername ()))
275
+ ->save ();
276
+ }
277
+ }
278
+
184
279
$ commit ->updateAuditStatus ($ requests );
185
280
$ commit ->save ();
186
281
187
282
$ this ->publishFeedStory ($ comment , array_keys ($ audit_phids ));
188
283
PhabricatorSearchCommitIndexer::indexCommit ($ commit );
189
- $ this ->sendMail ($ comment , $ other_comments , $ inline_comments );
284
+ $ this ->sendMail ($ comment , $ other_comments , $ inline_comments, $ requests );
190
285
}
191
286
192
287
@@ -256,7 +351,9 @@ private function publishFeedStory(
256
351
private function sendMail (
257
352
PhabricatorAuditComment $ comment ,
258
353
array $ other_comments ,
259
- array $ inline_comments ) {
354
+ array $ inline_comments ,
355
+ array $ requests ) {
356
+
260
357
assert_instances_of ($ other_comments , 'PhabricatorAuditComment ' );
261
358
assert_instances_of ($ inline_comments , 'PhabricatorInlineCommentInterface ' );
262
359
@@ -277,6 +374,8 @@ private function sendMail(
277
374
PhabricatorAuditActionConstants::ACCEPT => 'Accepted ' ,
278
375
PhabricatorAuditActionConstants::RESIGN => 'Resigned ' ,
279
376
PhabricatorAuditActionConstants::CLOSE => 'Closed ' ,
377
+ PhabricatorAuditActionConstants::ADD_CCS => 'Added CCs ' ,
378
+ PhabricatorAuditActionConstants::ADD_AUDITORS => 'Added Auditors ' ,
280
379
);
281
380
$ verb = idx ($ map , $ comment ->getAction (), 'Commented On ' );
282
381
@@ -297,6 +396,7 @@ private function sendMail(
297
396
$ inline_comments );
298
397
299
398
$ email_to = array ();
399
+ $ email_cc = array ();
300
400
301
401
$ author_phid = $ data ->getCommitDetail ('authorPHID ' );
302
402
if ($ author_phid ) {
@@ -308,6 +408,12 @@ private function sendMail(
308
408
$ email_cc [] = $ other_comment ->getActorPHID ();
309
409
}
310
410
411
+ foreach ($ requests as $ request ) {
412
+ if ($ request ->getAuditStatus () == PhabricatorAuditStatusConstants::CC ) {
413
+ $ email_cc [] = $ request ->getAuditorPHID ();
414
+ }
415
+ }
416
+
311
417
$ phids = array_merge ($ email_to , $ email_cc );
312
418
$ handles = id (new PhabricatorObjectHandleData ($ phids ))->loadHandles ();
313
419
0 commit comments