Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/audit/editor/comment/PhabricatorAuditCommentEditor.php b/src/applications/audit/editor/comment/PhabricatorAuditCommentEditor.php
index 29ffd6b926..27db026dbe 100644
--- a/src/applications/audit/editor/comment/PhabricatorAuditCommentEditor.php
+++ b/src/applications/audit/editor/comment/PhabricatorAuditCommentEditor.php
@@ -1,141 +1,144 @@
<?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 PhabricatorAuditCommentEditor {
private $commit;
private $user;
public function __construct(PhabricatorRepositoryCommit $commit) {
$this->commit = $commit;
return $this;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function addComment(PhabricatorAuditComment $comment) {
$commit = $this->commit;
$user = $this->user;
$comment
->setActorPHID($user->getPHID())
->setTargetPHID($commit->getPHID())
->save();
// When a user submits an audit comment, we update all the audit requests
// they have authority over to reflect the most recent status. The general
// idea here is that if audit has triggered for, e.g., several packages, but
// a user owns all of them, they can clear the audit requirement in one go
// without auditing the commit for each trigger.
$audit_phids = self::loadAuditPHIDsForUser($this->user);
$audit_phids = array_fill_keys($audit_phids, true);
$relationships = id(new PhabricatorOwnersPackageCommitRelationship())
->loadAllWhere(
'commitPHID = %s',
$commit->getPHID());
$action = $comment->getAction();
$status_map = PhabricatorAuditActionConstants::getStatusNameMap();
$status = idx($status_map, $action, null);
// Status may be empty for updates which don't affect status, like
// "comment".
if ($status) {
foreach ($relationships as $relationship) {
if (empty($audit_phids[$relationship->getPackagePHID()])) {
continue;
}
$relationship->setAuditStatus($status);
$relationship->save();
}
}
$this->publishFeedStory($comment, array_keys($audit_phids));
+ PhabricatorSearchCommitIndexer::indexCommit($commit);
- // TODO: Search index.
// TODO: Email.
}
/**
* Load the PHIDs for all objects the user has the authority to act as an
* audit for. This includes themselves, and any packages they are an owner
* of.
*/
public static function loadAuditPHIDsForUser(PhabricatorUser $user) {
$phids = array();
// The user can audit on their own behalf.
$phids[$user->getPHID()] = true;
// The user can audit on behalf of all packages they own.
$owned_packages = id(new PhabricatorOwnersOwner())->loadAllWhere(
'userPHID = %s',
$user->getPHID());
if ($owned_packages) {
$packages = id(new PhabricatorOwnersPackage())->loadAllWhere(
'id IN (%Ld)',
mpull($owned_packages, 'getPackageID'));
foreach (mpull($packages, 'getPHID') as $phid) {
$phids[$phid] = true;
}
}
// The user can audit on behalf of all projects they are a member of.
$query = new PhabricatorProjectQuery();
$query->setMembers(array($user->getPHID()));
$projects = $query->execute();
foreach ($projects as $project) {
$phids[$project->getPHID()] = true;
}
return array_keys($phids);
}
- private function publishFeedStory($comment, array $more_phids) {
+ private function publishFeedStory(
+ PhabricatorAuditComment $comment,
+ array $more_phids) {
+
$commit = $this->commit;
$user = $this->user;
$related_phids = array_merge(
array(
$user->getPHID(),
$commit->getPHID(),
),
$more_phids);
id(new PhabricatorFeedStoryPublisher())
->setRelatedPHIDs($related_phids)
->setStoryAuthorPHID($user->getPHID())
->setStoryTime(time())
->setStoryType(PhabricatorFeedStoryTypeConstants::STORY_AUDIT)
->setStoryData(
array(
'commitPHID' => $commit->getPHID(),
'action' => $comment->getAction(),
'content' => $comment->getContent(),
))
->publish();
}
}
diff --git a/src/applications/audit/editor/comment/__init__.php b/src/applications/audit/editor/comment/__init__.php
index f362087b9f..e85ccf3cd2 100644
--- a/src/applications/audit/editor/comment/__init__.php
+++ b/src/applications/audit/editor/comment/__init__.php
@@ -1,20 +1,21 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/audit/constants/action');
phutil_require_module('phabricator', 'applications/feed/constants/story');
phutil_require_module('phabricator', 'applications/feed/publisher');
phutil_require_module('phabricator', 'applications/owners/storage/owner');
phutil_require_module('phabricator', 'applications/owners/storage/package');
phutil_require_module('phabricator', 'applications/owners/storage/packagecommitrelationship');
phutil_require_module('phabricator', 'applications/project/query/project');
+phutil_require_module('phabricator', 'applications/search/index/indexer/repository');
phutil_require_module('phutil', 'utils');
phutil_require_source('PhabricatorAuditCommentEditor.php');
diff --git a/src/applications/repository/worker/herald/PhabricatorRepositoryCommitHeraldWorker.php b/src/applications/repository/worker/herald/PhabricatorRepositoryCommitHeraldWorker.php
index 938a6a0641..1d2e23a71b 100644
--- a/src/applications/repository/worker/herald/PhabricatorRepositoryCommitHeraldWorker.php
+++ b/src/applications/repository/worker/herald/PhabricatorRepositoryCommitHeraldWorker.php
@@ -1,180 +1,183 @@
<?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.
*/
class PhabricatorRepositoryCommitHeraldWorker
extends PhabricatorRepositoryCommitParserWorker {
public function parseCommit(
PhabricatorRepository $repository,
PhabricatorRepositoryCommit $commit) {
$data = id(new PhabricatorRepositoryCommitData())->loadOneWhere(
'commitID = %d',
$commit->getID());
$rules = HeraldRule::loadAllByContentTypeWithFullData(
HeraldContentTypeConfig::CONTENT_TYPE_COMMIT,
$commit->getPHID());
$adapter = new HeraldCommitAdapter(
$repository,
$commit,
$data);
$engine = new HeraldEngine();
$effects = $engine->applyRules($rules, $adapter);
$engine->applyEffects($effects, $adapter, $rules);
$audit_phids = $adapter->getAuditMap();
if ($audit_phids) {
$this->createAudits($commit, $audit_phids, $rules);
}
$email_phids = $adapter->getEmailPHIDs();
if (!$email_phids) {
return;
}
if ($repository->getDetail('herald-disabled')) {
// This just means "disable email"; audits are (mostly) idempotent.
return;
}
$xscript = $engine->getTranscript();
$commit_name = $adapter->getHeraldName();
$revision = $adapter->loadDifferentialRevision();
$name = null;
if ($revision) {
$name = ' '.$revision->getTitle();
}
$author_phid = $data->getCommitDetail('authorPHID');
$reviewer_phid = $data->getCommitDetail('reviewerPHID');
$phids = array_filter(array($author_phid, $reviewer_phid));
$handles = array();
if ($phids) {
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
}
if ($author_phid) {
$author_name = $handles[$author_phid]->getName();
} else {
$author_name = $data->getAuthorName();
}
if ($reviewer_phid) {
$reviewer_name = $handles[$reviewer_phid]->getName();
} else {
$reviewer_name = null;
}
$who = implode(', ', array_filter(array($author_name, $reviewer_name)));
$description = $data->getCommitMessage();
$details = PhabricatorEnv::getProductionURI('/'.$commit_name);
$differential = $revision
? PhabricatorEnv::getProductionURI('/D'.$revision->getID())
: 'No revision.';
$files = $adapter->loadAffectedPaths();
sort($files);
$files = implode("\n ", $files);
$xscript_id = $xscript->getID();
$manage_uri = PhabricatorEnv::getProductionURI('/herald/view/commits/');
$why_uri = PhabricatorEnv::getProductionURI(
'/herald/transcript/'.$xscript_id.'/');
$body = <<<EOBODY
DESCRIPTION
{$description}
DETAILS
{$details}
DIFFERENTIAL REVISION
{$differential}
AFFECTED FILES
{$files}
MANAGE HERALD COMMIT RULES
{$manage_uri}
WHY DID I GET THIS EMAIL?
{$why_uri}
EOBODY;
$subject = "[Herald/Commit] {$commit_name} ({$who}){$name}";
$mailer = new PhabricatorMetaMTAMail();
$mailer->setRelatedPHID($commit->getPHID());
$mailer->addTos($email_phids);
$mailer->setSubject($subject);
$mailer->setBody($body);
$mailer->setIsBulk(true);
$mailer->addHeader('X-Herald-Rules', $xscript->getXHeraldRulesHeader());
if ($author_phid) {
$mailer->setFrom($author_phid);
}
$mailer->saveAndSend();
}
- private function createAudits($commit, $map, $rules) {
+ private function createAudits(
+ PhabricatorRepositoryCommit $commit,
+ array $map,
+ array $rules) {
$table = new PhabricatorOwnersPackageCommitRelationship();
$rships = $table->loadAllWhere(
'commitPHID = %s AND packagePHID IN (%Ls)',
$commit->getPHID(),
array_keys($map));
$rships = mpull($rships, null, 'getPackagePHID');
$rules = mpull($rules, null, 'getID');
foreach ($map as $phid => $rule_ids) {
$rship = idx($rships, $phid);
if ($rship) {
continue;
}
$reasons = array();
foreach ($rule_ids as $id) {
$rule_name = '?';
if ($rules[$id]) {
$rule_name = $rules[$id]->getName();
}
$reasons[] = 'Herald Rule #'.$id.' "'.$rule_name.'" Triggered Audit';
}
$rship = new PhabricatorOwnersPackageCommitRelationship();
$rship->setCommitPHID($commit->getPHID());
$rship->setPackagePHID($phid);
$rship->setAuditStatus(PhabricatorAuditStatusConstants::AUDIT_REQUIRED);
$rship->setAuditReasons($reasons);
$rship->save();
}
}
}
diff --git a/src/applications/search/index/indexer/repository/PhabricatorSearchCommitIndexer.php b/src/applications/search/index/indexer/repository/PhabricatorSearchCommitIndexer.php
index 6a5cdb42b4..a3ad51fa49 100644
--- a/src/applications/search/index/indexer/repository/PhabricatorSearchCommitIndexer.php
+++ b/src/applications/search/index/indexer/repository/PhabricatorSearchCommitIndexer.php
@@ -1,72 +1,83 @@
<?php
/*
- * Copyright 2011 Facebook, Inc.
+ * 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.
*/
/**
* @group search
*/
class PhabricatorSearchCommitIndexer
extends PhabricatorSearchDocumentIndexer {
public static function indexCommit(PhabricatorRepositoryCommit $commit) {
$commit_data = id(new PhabricatorRepositoryCommitData())->loadOneWhere(
'commitID = %d',
$commit->getID());
$date_created = $commit->getEpoch();
$commit_message = $commit_data->getCommitMessage();
$author_phid = $commit_data->getCommitDetail('authorPHID');
$repository = id(new PhabricatorRepository())->loadOneWhere(
'id = %d',
$commit->getRepositoryID());
if (!$repository) {
return;
}
$title = 'r'.$repository->getCallsign().$commit->getCommitIdentifier().
" ".$commit_data->getSummary();
$doc = new PhabricatorSearchAbstractDocument();
$doc->setPHID($commit->getPHID());
$doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_CMIT);
$doc->setDocumentCreated($date_created);
$doc->setDocumentModified($date_created);
$doc->setDocumentTitle($title);
$doc->addField(
PhabricatorSearchField::FIELD_BODY,
$commit_message);
if ($author_phid) {
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR,
$author_phid,
PhabricatorPHIDConstants::PHID_TYPE_USER,
$date_created);
}
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_REPOSITORY,
$repository->getPHID(),
PhabricatorPHIDConstants::PHID_TYPE_REPO,
$date_created);
+ $comments = id(new PhabricatorAuditComment())->loadAllWhere(
+ 'targetPHID = %s',
+ $commit->getPHID());
+ foreach ($comments as $comment) {
+ if (strlen($comment->getContent())) {
+ $doc->addField(
+ PhabricatorSearchField::FIELD_COMMENT,
+ $comment->getContent());
+ }
+ }
+
self::reindexAbstractDocument($doc);
}
}
diff --git a/src/applications/search/index/indexer/repository/__init__.php b/src/applications/search/index/indexer/repository/__init__.php
index 9d0b8d2e14..b87c763192 100644
--- a/src/applications/search/index/indexer/repository/__init__.php
+++ b/src/applications/search/index/indexer/repository/__init__.php
@@ -1,20 +1,21 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
+phutil_require_module('phabricator', 'applications/audit/storage/auditcomment');
phutil_require_module('phabricator', 'applications/phid/constants');
phutil_require_module('phabricator', 'applications/repository/storage/commitdata');
phutil_require_module('phabricator', 'applications/repository/storage/repository');
phutil_require_module('phabricator', 'applications/search/constants/field');
phutil_require_module('phabricator', 'applications/search/constants/relationship');
phutil_require_module('phabricator', 'applications/search/index/abstractdocument');
phutil_require_module('phabricator', 'applications/search/index/indexer/base');
phutil_require_module('phutil', 'utils');
phutil_require_source('PhabricatorSearchCommitIndexer.php');

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jun 10, 6:26 AM (19 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
140268
Default Alt Text
(15 KB)

Event Timeline