1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

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
This commit is contained in:
epriestley 2012-06-20 06:03:44 -07:00
parent 74e39bfe41
commit 8ddfdb26e9
5 changed files with 132 additions and 9 deletions

View file

@ -632,6 +632,7 @@ phutil_register_library_map(array(
'PhabricatorFeedQuery' => 'applications/feed/PhabricatorFeedQuery.php', 'PhabricatorFeedQuery' => 'applications/feed/PhabricatorFeedQuery.php',
'PhabricatorFeedStory' => 'applications/feed/story/PhabricatorFeedStory.php', 'PhabricatorFeedStory' => 'applications/feed/story/PhabricatorFeedStory.php',
'PhabricatorFeedStoryAudit' => 'applications/feed/story/PhabricatorFeedStoryAudit.php', 'PhabricatorFeedStoryAudit' => 'applications/feed/story/PhabricatorFeedStoryAudit.php',
'PhabricatorFeedStoryCommit' => 'applications/feed/story/PhabricatorFeedStoryCommit.php',
'PhabricatorFeedStoryData' => 'applications/feed/storage/PhabricatorFeedStoryData.php', 'PhabricatorFeedStoryData' => 'applications/feed/storage/PhabricatorFeedStoryData.php',
'PhabricatorFeedStoryDifferential' => 'applications/feed/story/PhabricatorFeedStoryDifferential.php', 'PhabricatorFeedStoryDifferential' => 'applications/feed/story/PhabricatorFeedStoryDifferential.php',
'PhabricatorFeedStoryManiphest' => 'applications/feed/story/PhabricatorFeedStoryManiphest.php', 'PhabricatorFeedStoryManiphest' => 'applications/feed/story/PhabricatorFeedStoryManiphest.php',
@ -1625,6 +1626,7 @@ phutil_register_library_map(array(
'PhabricatorFeedDAO' => 'PhabricatorLiskDAO', 'PhabricatorFeedDAO' => 'PhabricatorLiskDAO',
'PhabricatorFeedPublicStreamController' => 'PhabricatorFeedController', 'PhabricatorFeedPublicStreamController' => 'PhabricatorFeedController',
'PhabricatorFeedStoryAudit' => 'PhabricatorFeedStory', 'PhabricatorFeedStoryAudit' => 'PhabricatorFeedStory',
'PhabricatorFeedStoryCommit' => 'PhabricatorFeedStory',
'PhabricatorFeedStoryData' => 'PhabricatorFeedDAO', 'PhabricatorFeedStoryData' => 'PhabricatorFeedDAO',
'PhabricatorFeedStoryDifferential' => 'PhabricatorFeedStory', 'PhabricatorFeedStoryDifferential' => 'PhabricatorFeedStory',
'PhabricatorFeedStoryManiphest' => 'PhabricatorFeedStory', 'PhabricatorFeedStoryManiphest' => 'PhabricatorFeedStory',

View file

@ -26,5 +26,6 @@ final class PhabricatorFeedStoryTypeConstants
const STORY_MANIPHEST = 'PhabricatorFeedStoryManiphest'; const STORY_MANIPHEST = 'PhabricatorFeedStoryManiphest';
const STORY_PROJECT = 'PhabricatorFeedStoryProject'; const STORY_PROJECT = 'PhabricatorFeedStoryProject';
const STORY_AUDIT = 'PhabricatorFeedStoryAudit'; const STORY_AUDIT = 'PhabricatorFeedStoryAudit';
const STORY_COMMIT = 'PhabricatorFeedStoryCommit';
} }

View file

@ -0,0 +1,77 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorFeedStoryCommit extends PhabricatorFeedStory {
public function getRequiredHandlePHIDs() {
$data = $this->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;
}
}

View file

@ -653,16 +653,18 @@ final class PhabricatorRepositoryEditController
->appendChild( ->appendChild(
id(new AphrontFormSelectControl()) id(new AphrontFormSelectControl())
->setName('herald-disabled') ->setName('herald-disabled')
->setLabel('Herald Enabled') ->setLabel('Herald/Feed Enabled')
->setValue($repository->getDetail('herald-disabled', 0)) ->setValue($repository->getDetail('herald-disabled', 0))
->setOptions( ->setOptions(
array( array(
0 => 'Enabled - Send Email', 0 => 'Enabled - Send Email and Publish Stories',
1 => 'Disabled - Do Not Send Email', 1 => 'Disabled - Do Not Send Email or Publish Stories',
)) ))
->setCaption( ->setCaption(
'You can temporarily disable Herald commit notifications when '. 'You can disable Herald commit notifications and feed stories '.
'reparsing a repository or importing a new repository.')); '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()) $parsers = id(new PhutilSymbolLoader())
->setAncestorClass('PhabricatorRepositoryCommitMessageDetailParser') ->setAncestorClass('PhabricatorRepositoryCommitMessageDetailParser')

View file

@ -52,13 +52,15 @@ final class PhabricatorRepositoryCommitHeraldWorker
$this->createAuditsFromCommitMessage($commit, $data); $this->createAuditsFromCommitMessage($commit, $data);
$email_phids = $adapter->getEmailPHIDs(); if ($repository->getDetail('herald-disabled')) {
if (!$email_phids) { // This just means "disable email"; audits are (mostly) idempotent.
return; return;
} }
if ($repository->getDetail('herald-disabled')) { $this->publishFeedStory($repository, $commit, $data);
// This just means "disable email"; audits are (mostly) idempotent.
$email_phids = $adapter->getEmailPHIDs();
if (!$email_phids) {
return; return;
} }
@ -273,4 +275,43 @@ EOBODY;
$commit->save(); $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();
}
} }