private function checkAuditReasons(PhabricatorRepositoryCommit $commit, PhabricatorOwnersPackage $package) { $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere('commitID = %d', $commit->getID()); $reasons = array(); if ($data->getCommitDetail('vsDiff')) { $reasons[] = pht('Changed After Revision Was Accepted'); } $commit_author_phid = $data->getCommitDetail('authorPHID'); if (!$commit_author_phid) { $reasons[] = pht('Commit Author Not Recognized'); } $revision_id = $data->getCommitDetail('differential.revisionID'); $revision_author_phid = null; $commit_reviewedby_phid = null; if ($revision_id) { $revision = id(new DifferentialRevisionQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withIDs(array($revision_id))->executeOne(); if ($revision) { $revision_author_phid = $revision->getAuthorPHID(); $commit_reviewedby_phid = $data->getCommitDetail('reviewerPHID'); if ($revision_author_phid !== $commit_author_phid) { $reasons[] = pht('Author Not Matching with Revision'); } } else { $reasons[] = pht('Revision Not Found'); } } else { $reasons[] = pht('No Revision Specified'); } $owners_phids = PhabricatorOwnersOwner::loadAffiliatedUserPHIDs(array($package->getID())); if (!($commit_author_phid && in_array($commit_author_phid, $owners_phids) || $commit_reviewedby_phid && in_array($commit_reviewedby_phid, $owners_phids))) { $reasons[] = pht('Owners Not Involved'); } return $reasons; }
public function willPublishStory($commit) { $requests = id(new DiffusionCommitQuery())->setViewer($this->getViewer())->withPHIDs(array($commit->getPHID()))->needAuditRequests(true)->executeOne()->getAudits(); // TODO: This is messy and should be generalized, but we don't have a good // query for it yet. Since we run in the daemons, just do the easiest thing // we can for the moment. Figure out who all of the "active" (need to // audit) and "passive" (no action necessary) users are. $auditor_phids = mpull($requests, 'getAuditorPHID'); $objects = id(new PhabricatorObjectQuery())->setViewer($this->getViewer())->withPHIDs($auditor_phids)->execute(); $active = array(); $passive = array(); foreach ($requests as $request) { $status = $request->getAuditStatus(); $object = idx($objects, $request->getAuditorPHID()); if (!$object) { continue; } $request_phids = array(); if ($object instanceof PhabricatorUser) { $request_phids = array($object->getPHID()); } else { if ($object instanceof PhabricatorOwnersPackage) { $request_phids = PhabricatorOwnersOwner::loadAffiliatedUserPHIDs(array($object->getID())); } else { if ($object instanceof PhabricatorProject) { $project = id(new PhabricatorProjectQuery())->setViewer($this->getViewer())->withIDs(array($object->getID()))->needMembers(true)->executeOne(); $request_phids = $project->getMemberPHIDs(); } else { // Dunno what this is. $request_phids = array(); } } } switch ($status) { case PhabricatorAuditStatusConstants::AUDIT_REQUIRED: case PhabricatorAuditStatusConstants::AUDIT_REQUESTED: case PhabricatorAuditStatusConstants::CONCERNED: $active += array_fuse($request_phids); break; default: $passive += array_fuse($request_phids); break; } } // Remove "Active" users from the "Passive" list. $passive = array_diff_key($passive, $active); $this->activePHIDs = $active; $this->passivePHIDs = $passive; $this->auditRequests = $requests; return $commit; }
private function checkAuditReasons(PhabricatorRepositoryCommit $commit, PhabricatorOwnersPackage $package, $author_phid, $revision) { $owner_phids = PhabricatorOwnersOwner::loadAffiliatedUserPHIDs(array($package->getID())); $owner_phids = array_fuse($owner_phids); $reasons = array(); if (!$author_phid) { $reasons[] = pht('Commit Author Not Recognized'); } else { if (isset($owner_phids[$author_phid])) { return $reasons; } } if (!$revision) { $reasons[] = pht('No Revision Specified'); return $reasons; } $accepted_statuses = array(DifferentialReviewerStatus::STATUS_ACCEPTED, DifferentialReviewerStatus::STATUS_ACCEPTED_OLDER); $accepted_statuses = array_fuse($accepted_statuses); $found_accept = false; foreach ($revision->getReviewerStatus() as $reviewer) { $reviewer_phid = $reviewer->getReviewerPHID(); // If this reviewer isn't a package owner, just ignore them. if (empty($owner_phids[$reviewer_phid])) { continue; } // If this reviewer accepted the revision and owns the package, we're // all clear and do not need to trigger an audit. if (isset($accepted_statuses[$reviewer->getStatus()])) { $found_accept = true; break; } } if (!$found_accept) { $reasons[] = pht('Owners Not Involved'); } return $reasons; }
private function checkAuditReasons(PhabricatorRepositoryCommit $commit, PhabricatorOwnersPackage $package) { $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere('commitID = %d', $commit->getID()); $reasons = array(); if ($data->getCommitDetail('vsDiff')) { $reasons[] = 'Changed After Revision Was Accepted'; } $commit_author_phid = $data->getCommitDetail('authorPHID'); if (!$commit_author_phid) { $reasons[] = 'Commit Author Not Recognized'; } $revision_id = $data->getCommitDetail('differential.revisionID'); $revision_author_phid = null; $commit_reviewedby_phid = null; if ($revision_id) { // TODO: (T603) This is probably safe to use an omnipotent user on, // but check things more closely. $revision = id(new DifferentialRevision())->load($revision_id); if ($revision) { $revision_author_phid = $revision->getAuthorPHID(); $commit_reviewedby_phid = $data->getCommitDetail('reviewerPHID'); if ($revision_author_phid !== $commit_author_phid) { $reasons[] = 'Author Not Matching with Revision'; } } else { $reasons[] = 'Revision Not Found'; } } else { $reasons[] = 'No Revision Specified'; } $owners_phids = PhabricatorOwnersOwner::loadAffiliatedUserPHIDs(array($package->getID())); if (!($commit_author_phid && in_array($commit_author_phid, $owners_phids) || $commit_reviewedby_phid && in_array($commit_reviewedby_phid, $owners_phids))) { $reasons[] = 'Owners Not Involved'; } return $reasons; }
public function getHeraldField($field) { switch ($field) { case self::FIELD_TITLE: return $this->revision->getTitle(); break; case self::FIELD_BODY: return $this->revision->getSummary() . "\n" . $this->revision->getTestPlan(); break; case self::FIELD_AUTHOR: return $this->revision->getAuthorPHID(); break; case self::FIELD_AUTHOR_PROJECTS: $author_phid = $this->revision->getAuthorPHID(); if (!$author_phid) { return array(); } $projects = id(new PhabricatorProjectQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withMemberPHIDs(array($author_phid))->execute(); return mpull($projects, 'getPHID'); case self::FIELD_DIFF_FILE: return $this->loadAffectedPaths(); case self::FIELD_REVIEWERS: if (isset($this->explicitReviewers)) { return array_keys($this->explicitReviewers); } else { return $this->revision->getReviewers(); } case self::FIELD_REPOSITORY: $repository = $this->loadRepository(); if (!$repository) { return null; } return $repository->getPHID(); case self::FIELD_REPOSITORY_PROJECTS: $repository = $this->loadRepository(); if (!$repository) { return array(); } return $repository->getProjectPHIDs(); case self::FIELD_DIFF_CONTENT: return $this->loadContentDictionary(); case self::FIELD_DIFF_ADDED_CONTENT: return $this->loadAddedContentDictionary(); case self::FIELD_DIFF_REMOVED_CONTENT: return $this->loadRemovedContentDictionary(); case self::FIELD_AFFECTED_PACKAGE: $packages = $this->loadAffectedPackages(); return mpull($packages, 'getPHID'); case self::FIELD_AFFECTED_PACKAGE_OWNER: $packages = $this->loadAffectedPackages(); return PhabricatorOwnersOwner::loadAffiliatedUserPHIDs(mpull($packages, 'getID')); } return parent::getHeraldField($field); }
public function getHeraldField($field) { switch ($field) { case HeraldFieldConfig::FIELD_TITLE: return $this->revision->getTitle(); break; case HeraldFieldConfig::FIELD_BODY: return $this->revision->getSummary() . "\n" . $this->revision->getTestPlan(); break; case HeraldFieldConfig::FIELD_AUTHOR: return $this->revision->getAuthorPHID(); break; case HeraldFieldConfig::FIELD_DIFF_FILE: return $this->loadAffectedPaths(); case HeraldFieldConfig::FIELD_CC: if (isset($this->explicitCCs)) { return array_keys($this->explicitCCs); } else { return $this->revision->getCCPHIDs(); } case HeraldFieldConfig::FIELD_REVIEWERS: if (isset($this->explicitReviewers)) { return array_keys($this->explicitReviewers); } else { return $this->revision->getReviewers(); } case HeraldFieldConfig::FIELD_REPOSITORY: $repository = $this->loadRepository(); if (!$repository) { return null; } return $repository->getPHID(); case HeraldFieldConfig::FIELD_DIFF_CONTENT: return $this->loadContentDictionary(); case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE: $packages = $this->loadAffectedPackages(); return mpull($packages, 'getPHID'); case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE_OWNER: $packages = $this->loadAffectedPackages(); return PhabricatorOwnersOwner::loadAffiliatedUserPHIDs(mpull($packages, 'getID')); default: throw new Exception("Invalid field '{$field}'."); } }
private function checkAuditReasons(PhabricatorRepositoryCommit $commit, PhabricatorOwnersPackage $package) { $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere('commitID = %d', $commit->getID()); $reasons = array(); if ($data->getCommitDetail('vsDiff')) { $reasons[] = "Changed After Revision Was Accepted"; } $commit_author_phid = $data->getCommitDetail('authorPHID'); if (!$commit_author_phid) { $reasons[] = "Commit Author Not Recognized"; } $revision_id = $data->getCommitDetail('differential.revisionID'); $revision_author_phid = null; $commit_reviewedby_phid = null; $commit_author_phid = null; if ($revision_id) { $revision = id(new DifferentialRevision())->load($revision_id); if ($revision) { $revision->loadRelationships(); $revision_author_phid = $revision->getAuthorPHID(); $revision_reviewedby_phid = $revision->loadReviewedBy(); $commit_reviewedby_phid = $data->getCommitDetail('reviewerPHID'); $commit_author_phid = $data->getCommitDetail('authorPHID'); if ($revision_author_phid !== $commit_author_phid) { $reasons[] = "Author Not Matching with Revision"; } if ($revision_reviewedby_phid !== $commit_reviewedby_phid) { $reasons[] = "ReviewedBy Not Matching with Revision"; } } else { $reasons[] = "Revision Not Found"; } } else { $reasons[] = "No Revision Specified"; } $owners_phids = PhabricatorOwnersOwner::loadAffiliatedUserPHIDs(array($package->getID())); if (!($commit_author_phid && in_array($commit_author_phid, $owners_phids) || $commit_reviewedby_phid && in_array($commit_reviewedby_phid, $owners_phids))) { $reasons[] = "Owners Not Involved"; } return $reasons; }