mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-31 18:01:00 +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:
parent
22c1b38655
commit
2e8990e9e0
7 changed files with 71 additions and 8 deletions
11
resources/sql/patches/042.commentmetadata.sql
Normal file
11
resources/sql/patches/042.commentmetadata.sql
Normal 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 = '';
|
|
@ -78,6 +78,19 @@ class DifferentialRevisionViewController extends DifferentialController {
|
||||||
$user->getPHID(),
|
$user->getPHID(),
|
||||||
),
|
),
|
||||||
mpull($comments, 'getAuthorPHID'));
|
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 ($revision->getAttached() as $type => $phids) {
|
||||||
foreach ($phids as $phid => $info) {
|
foreach ($phids as $phid => $info) {
|
||||||
$object_phids[] = $phid;
|
$object_phids[] = $phid;
|
||||||
|
|
|
@ -84,6 +84,8 @@ class DifferentialCommentEditor {
|
||||||
$reviewer_phids = array_combine($reviewer_phids, $reviewer_phids);
|
$reviewer_phids = array_combine($reviewer_phids, $reviewer_phids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$metadata = array();
|
||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case DifferentialAction::ACTION_COMMENT:
|
case DifferentialAction::ACTION_COMMENT:
|
||||||
break;
|
break;
|
||||||
|
@ -242,13 +244,8 @@ class DifferentialCommentEditor {
|
||||||
$add = $added_reviewers,
|
$add = $added_reviewers,
|
||||||
$actor_phid);
|
$actor_phid);
|
||||||
|
|
||||||
$handles = id(new PhabricatorObjectHandleData($added_reviewers))
|
$key = DifferentialComment::METADATA_ADDED_REVIEWERS;
|
||||||
->loadHandles();
|
$metadata[$key] = $added_reviewers;
|
||||||
$usernames = mpull($handles, 'getName');
|
|
||||||
|
|
||||||
$this->message =
|
|
||||||
'Added reviewers: '.implode(', ', $usernames)."\n\n".
|
|
||||||
$this->message;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$action = DifferentialAction::ACTION_COMMENT;
|
$action = DifferentialAction::ACTION_COMMENT;
|
||||||
|
@ -282,6 +279,7 @@ class DifferentialCommentEditor {
|
||||||
->setRevisionID($revision->getID())
|
->setRevisionID($revision->getID())
|
||||||
->setAction($action)
|
->setAction($action)
|
||||||
->setContent((string)$this->message)
|
->setContent((string)$this->message)
|
||||||
|
->setMetadata($metadata)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
$changesets = array();
|
$changesets = array();
|
||||||
|
|
|
@ -18,10 +18,21 @@
|
||||||
|
|
||||||
class DifferentialComment extends DifferentialDAO {
|
class DifferentialComment extends DifferentialDAO {
|
||||||
|
|
||||||
|
const METADATA_ADDED_REVIEWERS = 'added-reviewers';
|
||||||
|
|
||||||
protected $authorPHID;
|
protected $authorPHID;
|
||||||
protected $revisionID;
|
protected $revisionID;
|
||||||
protected $action;
|
protected $action;
|
||||||
protected $content;
|
protected $content;
|
||||||
protected $cache;
|
protected $cache;
|
||||||
|
protected $metadata = array();
|
||||||
|
|
||||||
|
public function getConfiguration() {
|
||||||
|
return array(
|
||||||
|
self::CONFIG_SERIALIZATION => array(
|
||||||
|
'metadata' => self::SERIALIZATION_JSON,
|
||||||
|
),
|
||||||
|
) + parent::getConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,7 @@ final class DifferentialRevisionCommentView extends AphrontView {
|
||||||
$verb = phutil_escape_html($verb);
|
$verb = phutil_escape_html($verb);
|
||||||
|
|
||||||
$content = $comment->getContent();
|
$content = $comment->getContent();
|
||||||
|
$head_content = null;
|
||||||
if (strlen(rtrim($content))) {
|
if (strlen(rtrim($content))) {
|
||||||
$title = "{$author_link} {$verb} this revision:";
|
$title = "{$author_link} {$verb} this revision:";
|
||||||
$cache = $comment->getCache();
|
$cache = $comment->getCache();
|
||||||
|
@ -127,10 +128,11 @@ final class DifferentialRevisionCommentView extends AphrontView {
|
||||||
'</div>';
|
'</div>';
|
||||||
} else {
|
} else {
|
||||||
$title = null;
|
$title = null;
|
||||||
$content =
|
$head_content =
|
||||||
'<div class="differential-comment-nocontent">'.
|
'<div class="differential-comment-nocontent">'.
|
||||||
"<p>{$author_link} {$verb} this revision.</p>".
|
"<p>{$author_link} {$verb} this revision.</p>".
|
||||||
'</div>';
|
'</div>';
|
||||||
|
$content = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->inlines) {
|
if ($this->inlines) {
|
||||||
|
@ -213,6 +215,29 @@ final class DifferentialRevisionCommentView extends AphrontView {
|
||||||
$background = "background-image: url('{$uri}');";
|
$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(
|
return phutil_render_tag(
|
||||||
'div',
|
'div',
|
||||||
array(
|
array(
|
||||||
|
@ -226,6 +251,8 @@ final class DifferentialRevisionCommentView extends AphrontView {
|
||||||
'</div>'.
|
'</div>'.
|
||||||
'<div class="differential-comment-body" style="'.$background.'">'.
|
'<div class="differential-comment-body" style="'.$background.'">'.
|
||||||
'<div class="differential-comment-content">'.
|
'<div class="differential-comment-content">'.
|
||||||
|
$head_content.
|
||||||
|
$metadata_blocks.
|
||||||
'<div class="differential-comment-core">'.
|
'<div class="differential-comment-core">'.
|
||||||
$content.
|
$content.
|
||||||
'</div>'.
|
'</div>'.
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
|
|
||||||
phutil_require_module('phabricator', 'applications/differential/constants/action');
|
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/celerity/api');
|
||||||
phutil_require_module('phabricator', 'infrastructure/javelin/api');
|
phutil_require_module('phabricator', 'infrastructure/javelin/api');
|
||||||
phutil_require_module('phabricator', 'view/base');
|
phutil_require_module('phabricator', 'view/base');
|
||||||
|
|
|
@ -25,12 +25,14 @@ class ManiphestTransaction extends ManiphestDAO {
|
||||||
protected $newValue;
|
protected $newValue;
|
||||||
protected $comments;
|
protected $comments;
|
||||||
protected $cache;
|
protected $cache;
|
||||||
|
protected $metadata = array();
|
||||||
|
|
||||||
public function getConfiguration() {
|
public function getConfiguration() {
|
||||||
return array(
|
return array(
|
||||||
self::CONFIG_SERIALIZATION => array(
|
self::CONFIG_SERIALIZATION => array(
|
||||||
'oldValue' => self::SERIALIZATION_JSON,
|
'oldValue' => self::SERIALIZATION_JSON,
|
||||||
'newValue' => self::SERIALIZATION_JSON,
|
'newValue' => self::SERIALIZATION_JSON,
|
||||||
|
'metadata' => self::SERIALIZATION_JSON,
|
||||||
),
|
),
|
||||||
) + parent::getConfiguration();
|
) + parent::getConfiguration();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue