1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-29 00:40:57 +01:00

Store metadata with Differential and Maniphest comments, and store added

reviewers as metadata

Summary:
The "Add reviewer" implementation is super lazy right now since I didn't want to
do a schema change. Man up and add a column. I also plan to store "via"
information here (e.g., via email or via mobile).

NOTE: This schema change may take a while since the comment table is pretty big
in Facebook's install.

This needs a little CSS work but I think it's reasonable for now.

Test Plan:
Made comments on revisions and tasks. Added reviewers to a revision, got linked
names instead of a blob of text.

Reviewed By: aran
Reviewers: tomo, jungejason, tuomaspelkonen, aran
Commenters: tomo
CC: aran, tomo, epriestley
Differential Revision: 394
This commit is contained in:
epriestley 2011-06-01 11:19:55 -07:00
parent 22c1b38655
commit 2e8990e9e0
7 changed files with 71 additions and 8 deletions

View file

@ -0,0 +1,11 @@
ALTER TABLE phabricator_differential.differential_comment
ADD metadata LONGBLOB NOT NULL;
UPDATE phabricator_differential.differential_comment
SET metadata = '{}' WHERE metadata = '';
ALTER TABLE phabricator_maniphest.maniphest_transaction
ADD metadata LONGBLOB NOT NULL;
UPDATE phabricator_maniphest.maniphest_transaction
SET metadata = '{}' WHERE metadata = '';

View file

@ -78,6 +78,19 @@ class DifferentialRevisionViewController extends DifferentialController {
$user->getPHID(),
),
mpull($comments, 'getAuthorPHID'));
foreach ($comments as $comment) {
$metadata = $comment->getMetadata();
$added_reviewers = idx(
$metadata,
DifferentialComment::METADATA_ADDED_REVIEWERS);
if ($added_reviewers) {
foreach ($added_reviewers as $phid) {
$object_phids[] = $phid;
}
}
}
foreach ($revision->getAttached() as $type => $phids) {
foreach ($phids as $phid => $info) {
$object_phids[] = $phid;

View file

@ -84,6 +84,8 @@ class DifferentialCommentEditor {
$reviewer_phids = array_combine($reviewer_phids, $reviewer_phids);
}
$metadata = array();
switch ($action) {
case DifferentialAction::ACTION_COMMENT:
break;
@ -242,13 +244,8 @@ class DifferentialCommentEditor {
$add = $added_reviewers,
$actor_phid);
$handles = id(new PhabricatorObjectHandleData($added_reviewers))
->loadHandles();
$usernames = mpull($handles, 'getName');
$this->message =
'Added reviewers: '.implode(', ', $usernames)."\n\n".
$this->message;
$key = DifferentialComment::METADATA_ADDED_REVIEWERS;
$metadata[$key] = $added_reviewers;
} else {
$action = DifferentialAction::ACTION_COMMENT;
@ -282,6 +279,7 @@ class DifferentialCommentEditor {
->setRevisionID($revision->getID())
->setAction($action)
->setContent((string)$this->message)
->setMetadata($metadata)
->save();
$changesets = array();

View file

@ -18,10 +18,21 @@
class DifferentialComment extends DifferentialDAO {
const METADATA_ADDED_REVIEWERS = 'added-reviewers';
protected $authorPHID;
protected $revisionID;
protected $action;
protected $content;
protected $cache;
protected $metadata = array();
public function getConfiguration() {
return array(
self::CONFIG_SERIALIZATION => array(
'metadata' => self::SERIALIZATION_JSON,
),
) + parent::getConfiguration();
}
}

View file

@ -109,6 +109,7 @@ final class DifferentialRevisionCommentView extends AphrontView {
$verb = phutil_escape_html($verb);
$content = $comment->getContent();
$head_content = null;
if (strlen(rtrim($content))) {
$title = "{$author_link} {$verb} this revision:";
$cache = $comment->getCache();
@ -127,10 +128,11 @@ final class DifferentialRevisionCommentView extends AphrontView {
'</div>';
} else {
$title = null;
$content =
$head_content =
'<div class="differential-comment-nocontent">'.
"<p>{$author_link} {$verb} this revision.</p>".
'</div>';
$content = null;
}
if ($this->inlines) {
@ -213,6 +215,29 @@ final class DifferentialRevisionCommentView extends AphrontView {
$background = "background-image: url('{$uri}');";
}
$metadata_blocks = array();
$metadata = $comment->getMetadata();
$added_reviewers = idx(
$metadata,
DifferentialComment::METADATA_ADDED_REVIEWERS);
if ($added_reviewers) {
$reviewers = array();
foreach ($added_reviewers as $phid) {
$reviewers[] = $this->handles[$phid]->renderLink();
}
$reviewers = 'Added reviewers: '.implode(', ', $reviewers);
$metadata_blocks[] = $reviewers;
}
if ($metadata_blocks) {
$metadata_blocks =
'<div class="differential-comment-metadata">'.
implode("\n", $metadata_blocks).
'</div>';
} else {
$metadata_blocks = null;
}
return phutil_render_tag(
'div',
array(
@ -226,6 +251,8 @@ final class DifferentialRevisionCommentView extends AphrontView {
'</div>'.
'<div class="differential-comment-body" style="'.$background.'">'.
'<div class="differential-comment-content">'.
$head_content.
$metadata_blocks.
'<div class="differential-comment-core">'.
$content.
'</div>'.

View file

@ -7,6 +7,7 @@
phutil_require_module('phabricator', 'applications/differential/constants/action');
phutil_require_module('phabricator', 'applications/differential/storage/comment');
phutil_require_module('phabricator', 'infrastructure/celerity/api');
phutil_require_module('phabricator', 'infrastructure/javelin/api');
phutil_require_module('phabricator', 'view/base');

View file

@ -25,12 +25,14 @@ class ManiphestTransaction extends ManiphestDAO {
protected $newValue;
protected $comments;
protected $cache;
protected $metadata = array();
public function getConfiguration() {
return array(
self::CONFIG_SERIALIZATION => array(
'oldValue' => self::SERIALIZATION_JSON,
'newValue' => self::SERIALIZATION_JSON,
'metadata' => self::SERIALIZATION_JSON,
),
) + parent::getConfiguration();
}