mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-03 19:31:02 +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:
parent
74e39bfe41
commit
8ddfdb26e9
5 changed files with 132 additions and 9 deletions
|
@ -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',
|
||||
|
|
|
@ -26,5 +26,6 @@ final class PhabricatorFeedStoryTypeConstants
|
|||
const STORY_MANIPHEST = 'PhabricatorFeedStoryManiphest';
|
||||
const STORY_PROJECT = 'PhabricatorFeedStoryProject';
|
||||
const STORY_AUDIT = 'PhabricatorFeedStoryAudit';
|
||||
const STORY_COMMIT = 'PhabricatorFeedStoryCommit';
|
||||
|
||||
}
|
||||
|
|
77
src/applications/feed/story/PhabricatorFeedStoryCommit.php
Normal file
77
src/applications/feed/story/PhabricatorFeedStoryCommit.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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')
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue