From 8ddfdb26e9995ba4ebcd52460255b6a21c9c43c4 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 20 Jun 2012 06:03:44 -0700 Subject: [PATCH] Publish feed stories about commits Summary: When stuff gets committed, publish feed stories about it. Test Plan: {F13061} Reviewers: jungejason, vrana, voldern Reviewed By: jungejason CC: aran Maniphest Tasks: T1322 Differential Revision: https://secure.phabricator.com/D2805 --- src/__phutil_library_map__.php | 2 + .../PhabricatorFeedStoryTypeConstants.php | 1 + .../feed/story/PhabricatorFeedStoryCommit.php | 77 +++++++++++++++++++ .../PhabricatorRepositoryEditController.php | 12 +-- ...habricatorRepositoryCommitHeraldWorker.php | 49 +++++++++++- 5 files changed, 132 insertions(+), 9 deletions(-) create mode 100644 src/applications/feed/story/PhabricatorFeedStoryCommit.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 73a6fb42b2..27c4c2ac0e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -632,6 +632,7 @@ phutil_register_library_map(array( 'PhabricatorFeedQuery' => 'applications/feed/PhabricatorFeedQuery.php', 'PhabricatorFeedStory' => 'applications/feed/story/PhabricatorFeedStory.php', 'PhabricatorFeedStoryAudit' => 'applications/feed/story/PhabricatorFeedStoryAudit.php', + 'PhabricatorFeedStoryCommit' => 'applications/feed/story/PhabricatorFeedStoryCommit.php', 'PhabricatorFeedStoryData' => 'applications/feed/storage/PhabricatorFeedStoryData.php', 'PhabricatorFeedStoryDifferential' => 'applications/feed/story/PhabricatorFeedStoryDifferential.php', 'PhabricatorFeedStoryManiphest' => 'applications/feed/story/PhabricatorFeedStoryManiphest.php', @@ -1625,6 +1626,7 @@ phutil_register_library_map(array( 'PhabricatorFeedDAO' => 'PhabricatorLiskDAO', 'PhabricatorFeedPublicStreamController' => 'PhabricatorFeedController', 'PhabricatorFeedStoryAudit' => 'PhabricatorFeedStory', + 'PhabricatorFeedStoryCommit' => 'PhabricatorFeedStory', 'PhabricatorFeedStoryData' => 'PhabricatorFeedDAO', 'PhabricatorFeedStoryDifferential' => 'PhabricatorFeedStory', 'PhabricatorFeedStoryManiphest' => 'PhabricatorFeedStory', diff --git a/src/applications/feed/constants/PhabricatorFeedStoryTypeConstants.php b/src/applications/feed/constants/PhabricatorFeedStoryTypeConstants.php index 903d87a390..0384d3ab3e 100644 --- a/src/applications/feed/constants/PhabricatorFeedStoryTypeConstants.php +++ b/src/applications/feed/constants/PhabricatorFeedStoryTypeConstants.php @@ -26,5 +26,6 @@ final class PhabricatorFeedStoryTypeConstants const STORY_MANIPHEST = 'PhabricatorFeedStoryManiphest'; const STORY_PROJECT = 'PhabricatorFeedStoryProject'; const STORY_AUDIT = 'PhabricatorFeedStoryAudit'; + const STORY_COMMIT = 'PhabricatorFeedStoryCommit'; } diff --git a/src/applications/feed/story/PhabricatorFeedStoryCommit.php b/src/applications/feed/story/PhabricatorFeedStoryCommit.php new file mode 100644 index 0000000000..a2144979a5 --- /dev/null +++ b/src/applications/feed/story/PhabricatorFeedStoryCommit.php @@ -0,0 +1,77 @@ +getStoryData(); + + return array_filter( + array( + $data->getValue('commitPHID'), + $data->getValue('authorPHID'), + $data->getValue('committerPHID'), + )); + } + + public function renderView() { + $data = $this->getStoryData(); + + $author = null; + if ($data->getValue('authorPHID')) { + $author = $this->linkTo($data->getValue('authorPHID')); + } else { + $author = phutil_escape_html($data->getValue('authorName')); + } + + $committer = null; + if ($data->getValue('committerPHID')) { + $committer = $this->linkTo($data->getValue('committerPHID')); + } else if ($data->getValue('committerName')) { + $committer = phutil_escape_html($data->getValue('committerName')); + } + + $commit = $this->linkTo($data->getValue('commitPHID')); + + if (!$committer) { + $committer = $author; + $author = null; + } + + if ($author) { + $title = "{$committer} committed {$commit} (authored by {$author})"; + } else { + $title = "{$committer} committed {$commit}"; + } + + $view = new PhabricatorFeedStoryView(); + + $view->setTitle($title); + $view->setEpoch($data->getEpoch()); + + if ($data->getValue('authorPHID')) { + $view->setImage($this->getHandle($data->getAuthorPHID())->getImageURI()); + } + + $content = $this->renderSummary($data->getValue('summary')); + $view->appendChild($content); + + return $view; + } + +} diff --git a/src/applications/repository/controller/PhabricatorRepositoryEditController.php b/src/applications/repository/controller/PhabricatorRepositoryEditController.php index 3905d04784..9b3c14328a 100644 --- a/src/applications/repository/controller/PhabricatorRepositoryEditController.php +++ b/src/applications/repository/controller/PhabricatorRepositoryEditController.php @@ -653,16 +653,18 @@ final class PhabricatorRepositoryEditController ->appendChild( id(new AphrontFormSelectControl()) ->setName('herald-disabled') - ->setLabel('Herald Enabled') + ->setLabel('Herald/Feed Enabled') ->setValue($repository->getDetail('herald-disabled', 0)) ->setOptions( array( - 0 => 'Enabled - Send Email', - 1 => 'Disabled - Do Not Send Email', + 0 => 'Enabled - Send Email and Publish Stories', + 1 => 'Disabled - Do Not Send Email or Publish Stories', )) ->setCaption( - 'You can temporarily disable Herald commit notifications when '. - 'reparsing a repository or importing a new repository.')); + 'You can disable Herald commit notifications and feed stories '. + 'for this repository. This can be useful when initially importing '. + 'a repository. Feed stories are never published about commits '. + 'that are more than 24 hours old.')); $parsers = id(new PhutilSymbolLoader()) ->setAncestorClass('PhabricatorRepositoryCommitMessageDetailParser') diff --git a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php index d6f58b5a63..23be0ead94 100644 --- a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php +++ b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php @@ -52,13 +52,15 @@ final class PhabricatorRepositoryCommitHeraldWorker $this->createAuditsFromCommitMessage($commit, $data); - $email_phids = $adapter->getEmailPHIDs(); - if (!$email_phids) { + if ($repository->getDetail('herald-disabled')) { + // This just means "disable email"; audits are (mostly) idempotent. return; } - if ($repository->getDetail('herald-disabled')) { - // This just means "disable email"; audits are (mostly) idempotent. + $this->publishFeedStory($repository, $commit, $data); + + $email_phids = $adapter->getEmailPHIDs(); + if (!$email_phids) { return; } @@ -273,4 +275,43 @@ EOBODY; $commit->save(); } + private function publishFeedStory( + PhabricatorRepository $repository, + PhabricatorRepositoryCommit $commit, + PhabricatorRepositoryCommitData $data) { + + if (time() > $commit->getEpoch() + (24 * 60 * 60)) { + // Don't publish stories that are more than 24 hours old, to avoid + // ridiculous levels of feed spam if a repository is imported without + // disabling feed publishing. + return; + } + + $author_phid = $commit->getAuthorPHID(); + $committer_phid = $data->getCommitDetail('committerPHID'); + + $publisher = new PhabricatorFeedStoryPublisher(); + $publisher->setStoryType(PhabricatorFeedStoryTypeConstants::STORY_COMMIT); + $publisher->setStoryData( + array( + 'commitPHID' => $commit->getPHID(), + 'summary' => $data->getSummary(), + 'authorName' => $data->getAuthorName(), + 'authorPHID' => $author_phid, + 'committerName' => $data->getCommitDetail('committer'), + 'committerPHID' => $committer_phid, + )); + $publisher->setStoryTime($commit->getEpoch()); + $publisher->setRelatedPHIDs( + array_filter( + array( + $author_phid, + $committer_phid, + ))); + if ($author_phid) { + $publisher->setStoryAuthorPHID($author_phid); + } + $publisher->publish(); + } + }