mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-14 02:42:40 +01:00
Consolidate readers of "differential.revisionID" property
Summary: Depends on D20467. Ref T13277. Currently, the "MessageParserWorker" writes this property on commits, then Herald and Audit both read it. Make them share code so this property has one writer and one reader. This property isn't great, but at least now the badness is hidden. Currently, we can't just use edges because they may not have been written yet. I am likely to just do this, soon: - Just write the edges (in "MessageParserWorker"). - Hide the edges from mail. However, we'll sort-of lose the "revisionMatchData" explanation thing if I do that. Maybe this is fine? But when commits match because hashes match, it legitimately isn't obvious. For now, just reduce the amount of harm/badness here. Test Plan: - Ran `bin/repository reparse --publish ...`. - Ran a Herald "Audit" rule using the "Accepted Differential revision" field. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13277 Differential Revision: https://secure.phabricator.com/D20468
This commit is contained in:
parent
45f01dc716
commit
56f5c2443b
3 changed files with 47 additions and 31 deletions
|
@ -175,31 +175,34 @@ final class HeraldCommitAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadDifferentialRevision() {
|
public function loadDifferentialRevision() {
|
||||||
$viewer = $this->getViewer();
|
|
||||||
|
|
||||||
if ($this->affectedRevision === null) {
|
if ($this->affectedRevision === null) {
|
||||||
$this->affectedRevision = false;
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
$commit = $this->getObject();
|
// NOTE: The viewer here is omnipotent, which means that Herald discloses
|
||||||
$data = $commit->getCommitData();
|
// some information users do not normally have access to when rules load
|
||||||
|
// the revision related to a commit. See D20468.
|
||||||
|
|
||||||
$revision_id = $data->getCommitDetail('differential.revisionID');
|
// A user who wants to learn about "Dxyz" can write a Herald rule which
|
||||||
if ($revision_id) {
|
// uses all the "Related revision..." fields, then push a commit which
|
||||||
// NOTE: The Herald rule owner might not actually have access to
|
// contains "Differential Revision: Dxyz" in the message to make Herald
|
||||||
// the revision, and can control which revision a commit is
|
// evaluate the commit with "Dxyz" as the related revision.
|
||||||
// associated with by putting text in the commit message. However,
|
|
||||||
// the rules they can write against revisions don't actually expose
|
|
||||||
// anything interesting, so it seems reasonable to load unconditionally
|
|
||||||
// here.
|
|
||||||
|
|
||||||
$revision = id(new DifferentialRevisionQuery())
|
// At time of writing, this commit will link to the revision and the
|
||||||
->withIDs(array($revision_id))
|
// transcript for the commit will disclose some information about the
|
||||||
->setViewer($viewer)
|
// revision (like reviewers, subscribers, and build status) which the
|
||||||
->needReviewers(true)
|
// commit author could not otherwise see.
|
||||||
->executeOne();
|
|
||||||
if ($revision) {
|
// For now, we just accept this. The disclosures are relatively
|
||||||
$this->affectedRevision = $revision;
|
// uninteresting and you have to jump through a lot of hoops (and leave
|
||||||
}
|
// a lot of evidence) to get this information.
|
||||||
|
|
||||||
|
$revision = DiffusionCommitRevisionQuery::loadRevisionForCommit(
|
||||||
|
$viewer,
|
||||||
|
$this->getObject());
|
||||||
|
if ($revision) {
|
||||||
|
$this->affectedRevision = $revision;
|
||||||
|
} else {
|
||||||
|
$this->affectedRevision = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,4 +46,23 @@ final class DiffusionCommitRevisionQuery
|
||||||
return $map;
|
return $map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function loadRevisionForCommit(
|
||||||
|
PhabricatorUser $viewer,
|
||||||
|
PhabricatorRepositoryCommit $commit) {
|
||||||
|
|
||||||
|
$data = $commit->getCommitData();
|
||||||
|
|
||||||
|
$revision_id = $data->getCommitDetail('differential.revisionID');
|
||||||
|
if (!$revision_id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return id(new DifferentialRevisionQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withIDs(array($revision_id))
|
||||||
|
->needReviewers(true)
|
||||||
|
->executeOne();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,16 +135,10 @@ final class PhabricatorRepositoryCommitPublishWorker
|
||||||
$data = $commit->getCommitData();
|
$data = $commit->getCommitData();
|
||||||
|
|
||||||
$author_phid = $data->getCommitDetail('authorPHID');
|
$author_phid = $data->getCommitDetail('authorPHID');
|
||||||
$revision_id = $data->getCommitDetail('differential.revisionID');
|
|
||||||
if ($revision_id) {
|
$revision = DiffusionCommitRevisionQuery::loadRevisionForCommit(
|
||||||
$revision = id(new DifferentialRevisionQuery())
|
$viewer,
|
||||||
->setViewer($viewer)
|
$commit);
|
||||||
->withIDs(array($revision_id))
|
|
||||||
->needReviewers(true)
|
|
||||||
->executeOne();
|
|
||||||
} else {
|
|
||||||
$revision = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$requests = $commit->getAudits();
|
$requests = $commit->getAudits();
|
||||||
$requests = mpull($requests, null, 'getAuditorPHID');
|
$requests = mpull($requests, null, 'getAuditorPHID');
|
||||||
|
|
Loading…
Reference in a new issue