Skip to content

Commit 39516d7

Browse files
authored
Bug 2044749 - Expose code suggestions in feed.for_email.query inline comments
Add hasSuggestion and suggestionText fields to EmailInlineComment, populated from the inline comment content state. Also adds unit tests for the new fields.
1 parent 44d768b commit 39516d7

4 files changed

Lines changed: 85 additions & 3 deletions

File tree

moz-extensions/src/__phutil_library_map__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'EmailEndpointResponseData' => 'email/model/EmailEndpointResponseData.php',
3636
'EmailEvent' => 'email/model/EmailEvent.php',
3737
'EmailInlineComment' => 'email/model/EmailInlineComment.php',
38+
'EmailInlineCommentTestCase' => 'email/model/__tests__/EmailInlineCommentTestCase.php',
3839
'EmailMetadataEditedReviewer' => 'email/model/EmailMetadataEditedReviewer.php',
3940
'EmailRecipient' => 'email/model/EmailRecipient.php',
4041
'EmailReplyContext' => 'email/model/EmailReplyContext.php',
@@ -137,6 +138,7 @@
137138
'DifferentialBugzillaBugIDCommitMessageField' => 'DifferentialCommitMessageCustomField',
138139
'DifferentialBugzillaBugIDCustomFieldTestCase' => 'PhabricatorTestCase',
139140
'DifferentialUpliftRequestCustomFieldTestCase' => 'PhabricatorTestCase',
141+
'EmailInlineCommentTestCase' => 'PhabricatorTestCase',
140142
'DifferentialBugzillaBugIDField' => 'DifferentialStoredCustomField',
141143
'DifferentialBugzillaBugIDValidator' => 'Phobject',
142144
'DifferentialUpliftRequestCustomField' => 'DifferentialStoredCustomField',

moz-extensions/src/email/model/EmailInlineComment.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ class EmailInlineComment {
99
public string $contextKind;
1010
/** @var EmailReplyContext|EmailCodeContext */
1111
public $context;
12+
public bool $hasSuggestion;
13+
public string $suggestionText;
1214

13-
public function __construct(string $fileContext, string $link, EmailCommentMessage $message, string $contextKind, $context) {
15+
public function __construct(string $fileContext, string $link, EmailCommentMessage $message, string $contextKind, $context, bool $hasSuggestion = false, string $suggestionText = '') {
1416
$this->fileContext = $fileContext;
1517
$this->link = $link;
1618
$this->message = $message;
1719
$this->contextKind = $contextKind;
1820
$this->context = $context;
21+
$this->hasSuggestion = $hasSuggestion;
22+
$this->suggestionText = $suggestionText;
1923
}
20-
}
24+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
// This Source Code Form is subject to the terms of the Mozilla Public
3+
// License, v. 2.0. If a copy of the MPL was not distributed with this
4+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
6+
final class EmailInlineCommentTestCase extends PhabricatorTestCase {
7+
8+
private function newMessage(): EmailCommentMessage {
9+
return new EmailCommentMessage('text', '<p>text</p>');
10+
}
11+
12+
private function newCodeContext(): EmailCodeContext {
13+
return new EmailCodeContext([]);
14+
}
15+
16+
public function testDefaultsToNoSuggestion() {
17+
$comment = new EmailInlineComment(
18+
'/src/foo.php:10',
19+
'https://example.com/D1',
20+
$this->newMessage(),
21+
'code',
22+
$this->newCodeContext()
23+
);
24+
25+
$this->assertFalse($comment->hasSuggestion);
26+
$this->assertEqual('', $comment->suggestionText);
27+
}
28+
29+
public function testStoresSuggestion() {
30+
$comment = new EmailInlineComment(
31+
'/src/foo.php:10',
32+
'https://example.com/D1',
33+
$this->newMessage(),
34+
'code',
35+
$this->newCodeContext(),
36+
true,
37+
'return $x + 1;'
38+
);
39+
40+
$this->assertTrue($comment->hasSuggestion);
41+
$this->assertEqual('return $x + 1;', $comment->suggestionText);
42+
}
43+
44+
public function testNoSuggestionWithExplicitFalse() {
45+
$comment = new EmailInlineComment(
46+
'/src/foo.php:10',
47+
'https://example.com/D1',
48+
$this->newMessage(),
49+
'code',
50+
$this->newCodeContext(),
51+
false,
52+
''
53+
);
54+
55+
$this->assertFalse($comment->hasSuggestion);
56+
$this->assertEqual('', $comment->suggestionText);
57+
}
58+
59+
public function testFileContextAndLinkStored() {
60+
$comment = new EmailInlineComment(
61+
'/src/bar.php:42',
62+
'https://example.com/D2#inline-99',
63+
$this->newMessage(),
64+
'reply',
65+
$this->newCodeContext()
66+
);
67+
68+
$this->assertEqual('/src/bar.php:42', $comment->fileContext);
69+
$this->assertEqual('https://example.com/D2#inline-99', $comment->link);
70+
$this->assertEqual('reply', $comment->contextKind);
71+
}
72+
}

moz-extensions/src/email/resolve/ResolveComments.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,14 @@ private function resolveInlineComments(PublicEventPings $pings): array {
143143
$context = new EmailCodeContext($diffLines);
144144
}
145145

146+
$contentState = $comment->newInlineCommentObject()->getContentState();
147+
$hasSuggestion = $contentState->getContentHasSuggestion();
148+
$suggestionText = $contentState->getContentSuggestionText();
149+
146150
$commentLineNumber = $comment->getLineNumber();
147151
$rawMessage = $rawTransaction->getComment()->getContent();
148152
$message = self::renderCommentMarkup($rawMessage);
149-
$inlineComment = new EmailInlineComment("$filename:$commentLineNumber", $link, $message, $contextKind, $context);
153+
$inlineComment = new EmailInlineComment("$filename:$commentLineNumber", $link, $message, $contextKind, $context, $hasSuggestion, $suggestionText);
150154
foreach (self::findPingedUsers($rawMessage) as $user) {
151155
$pings->fromInlineComment($user, $inlineComment);
152156
}

0 commit comments

Comments
 (0)