private function triggerOwnerAudits(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     if (!$repository->shouldPublish()) {
         return;
     }
     $affected_paths = PhabricatorOwnerPathQuery::loadAffectedPaths($repository, $commit, PhabricatorUser::getOmnipotentUser());
     $affected_packages = PhabricatorOwnersPackage::loadAffectedPackages($repository, $affected_paths);
     if (!$affected_packages) {
         return;
     }
     $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere('commitID = %d', $commit->getID());
     $commit->attachCommitData($data);
     $author_phid = $data->getCommitDetail('authorPHID');
     $revision_id = $data->getCommitDetail('differential.revisionID');
     if ($revision_id) {
         $revision = id(new DifferentialRevisionQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withIDs(array($revision_id))->needReviewerStatus(true)->executeOne();
     } else {
         $revision = null;
     }
     $requests = id(new PhabricatorRepositoryAuditRequest())->loadAllWhere('commitPHID = %s', $commit->getPHID());
     $requests = mpull($requests, null, 'getAuditorPHID');
     foreach ($affected_packages as $package) {
         $request = idx($requests, $package->getPHID());
         if ($request) {
             // Don't update request if it exists already.
             continue;
         }
         if ($package->isArchived()) {
             // Don't trigger audits if the package is archived.
             continue;
         }
         if ($package->getAuditingEnabled()) {
             $reasons = $this->checkAuditReasons($commit, $package, $author_phid, $revision);
             if ($reasons) {
                 $audit_status = PhabricatorAuditStatusConstants::AUDIT_REQUIRED;
             } else {
                 $audit_status = PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED;
             }
         } else {
             $reasons = array();
             $audit_status = PhabricatorAuditStatusConstants::NONE;
         }
         $relationship = new PhabricatorRepositoryAuditRequest();
         $relationship->setAuditorPHID($package->getPHID());
         $relationship->setCommitPHID($commit->getPHID());
         $relationship->setAuditReasons($reasons);
         $relationship->setAuditStatus($audit_status);
         $relationship->save();
         $requests[$package->getPHID()] = $relationship;
     }
     $commit->updateAuditStatus($requests);
     $commit->save();
 }
 protected function parseCommit(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     $affected_paths = PhabricatorOwnerPathQuery::loadAffectedPaths($repository, $commit);
     $affected_packages = PhabricatorOwnersPackage::loadAffectedPackages($repository, $affected_paths);
     if ($affected_packages) {
         $requests = id(new PhabricatorRepositoryAuditRequest())->loadAllWhere('commitPHID = %s', $commit->getPHID());
         $requests = mpull($requests, null, 'getAuditorPHID');
         foreach ($affected_packages as $package) {
             $request = idx($requests, $package->getPHID());
             if ($request) {
                 // Don't update request if it exists already.
                 continue;
             }
             if ($package->getAuditingEnabled()) {
                 $reasons = $this->checkAuditReasons($commit, $package);
                 if ($reasons) {
                     $audit_status = PhabricatorAuditStatusConstants::AUDIT_REQUIRED;
                 } else {
                     $audit_status = PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED;
                 }
             } else {
                 $reasons = array();
                 $audit_status = PhabricatorAuditStatusConstants::NONE;
             }
             $relationship = new PhabricatorRepositoryAuditRequest();
             $relationship->setAuditorPHID($package->getPHID());
             $relationship->setCommitPHID($commit->getPHID());
             $relationship->setAuditReasons($reasons);
             $relationship->setAuditStatus($audit_status);
             $relationship->save();
             $requests[$package->getPHID()] = $relationship;
         }
         $commit->updateAuditStatus($requests);
         $commit->save();
     }
     if ($this->shouldQueueFollowupTasks()) {
         $herald_task = new PhabricatorWorkerTask();
         $herald_task->setTaskClass('PhabricatorRepositoryCommitHeraldWorker');
         $herald_task->setData(array('commitID' => $commit->getID()));
         $herald_task->save();
     }
 }
 private function triggerOwnerAudits(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     if (!$repository->shouldPublish()) {
         return;
     }
     $affected_paths = PhabricatorOwnerPathQuery::loadAffectedPaths($repository, $commit, PhabricatorUser::getOmnipotentUser());
     $affected_packages = PhabricatorOwnersPackage::loadAffectedPackages($repository, $affected_paths);
     if ($affected_packages) {
         $requests = id(new PhabricatorRepositoryAuditRequest())->loadAllWhere('commitPHID = %s', $commit->getPHID());
         $requests = mpull($requests, null, 'getAuditorPHID');
         foreach ($affected_packages as $package) {
             $request = idx($requests, $package->getPHID());
             if ($request) {
                 // Don't update request if it exists already.
                 continue;
             }
             if ($package->getAuditingEnabled()) {
                 $reasons = $this->checkAuditReasons($commit, $package);
                 if ($reasons) {
                     $audit_status = PhabricatorAuditStatusConstants::AUDIT_REQUIRED;
                 } else {
                     $audit_status = PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED;
                 }
             } else {
                 $reasons = array();
                 $audit_status = PhabricatorAuditStatusConstants::NONE;
             }
             $relationship = new PhabricatorRepositoryAuditRequest();
             $relationship->setAuditorPHID($package->getPHID());
             $relationship->setCommitPHID($commit->getPHID());
             $relationship->setAuditReasons($reasons);
             $relationship->setAuditStatus($audit_status);
             $relationship->save();
             $requests[$package->getPHID()] = $relationship;
         }
         $commit->updateAuditStatus($requests);
         $commit->save();
     }
 }
 /**
  * Find audit requests in the "Auditors" field if it is present and trigger
  * explicit audit requests.
  */
 private function createAuditsFromCommitMessage(PhabricatorRepositoryCommit $commit, PhabricatorRepositoryCommitData $data)
 {
     $message = $data->getCommitMessage();
     $matches = null;
     if (!preg_match('/^Auditors:\\s*(.*)$/im', $message, $matches)) {
         return array();
     }
     $phids = id(new PhabricatorObjectListQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->setAllowPartialResults(true)->setAllowedTypes(array(PhabricatorPeopleUserPHIDType::TYPECONST, PhabricatorProjectProjectPHIDType::TYPECONST))->setObjectList($matches[1])->execute();
     if (!$phids) {
         return array();
     }
     $requests = id(new PhabricatorRepositoryAuditRequest())->loadAllWhere('commitPHID = %s', $commit->getPHID());
     $requests = mpull($requests, null, 'getAuditorPHID');
     foreach ($phids as $phid) {
         if (isset($requests[$phid])) {
             continue;
         }
         $request = new PhabricatorRepositoryAuditRequest();
         $request->setCommitPHID($commit->getPHID());
         $request->setAuditorPHID($phid);
         $request->setAuditStatus(PhabricatorAuditStatusConstants::AUDIT_REQUESTED);
         $request->setAuditReasons(array('Requested by Author'));
         $request->save();
         $requests[$phid] = $request;
     }
     $commit->updateAuditStatus($requests);
     $commit->save();
     return $phids;
 }
 /**
  * Find audit requests in the "Auditors" field if it is present and trigger
  * explicit audit requests.
  */
 private function createAuditsFromCommitMessage(PhabricatorRepositoryCommit $commit, PhabricatorRepositoryCommitData $data)
 {
     $message = $data->getCommitMessage();
     $matches = null;
     if (!preg_match('/^Auditors:\\s*(.*)$/im', $message, $matches)) {
         return array();
     }
     $phids = DifferentialFieldSpecification::parseCommitMessageObjectList($matches[1], $include_mailables = false, $allow_partial = true);
     if (!$phids) {
         return array();
     }
     $requests = id(new PhabricatorRepositoryAuditRequest())->loadAllWhere('commitPHID = %s', $commit->getPHID());
     $requests = mpull($requests, null, 'getAuditorPHID');
     foreach ($phids as $phid) {
         if (isset($requests[$phid])) {
             continue;
         }
         $request = new PhabricatorRepositoryAuditRequest();
         $request->setCommitPHID($commit->getPHID());
         $request->setAuditorPHID($phid);
         $request->setAuditStatus(PhabricatorAuditStatusConstants::AUDIT_REQUESTED);
         $request->setAuditReasons(array('Requested by Author'));
         $request->save();
         $requests[$phid] = $request;
     }
     $commit->updateAuditStatus($requests);
     $commit->save();
     return $phids;
 }