Skip to content

Commit f659b87

Browse files
author
epriestley
committed
Fix Herald test adapter for commits
Summary: Fixes T11488. I broke this in D16360, I think by doing a little extra refactoring after testing it. This code is very old, before commits always needed to have repositories attached in order to do policy checks. Modernize it by mostly just using the repository which is present on the Commit object, and using the existing edge cache. Test Plan: Ran a commit through the Herald test adapter. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11488 Differential Revision: https://secure.phabricator.com/D16413
1 parent f46cf99 commit f659b87

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

src/applications/diffusion/herald/HeraldCommitAdapter.php

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ final class HeraldCommitAdapter
77
protected $diff;
88
protected $revision;
99

10-
protected $repository;
1110
protected $commit;
1211
protected $commitData;
1312
private $commitDiff;
@@ -42,6 +41,7 @@ protected function initializeNewAdapter() {
4241

4342
public function setObject($object) {
4443
$this->commit = $object;
44+
4545
return $this;
4646
}
4747

@@ -86,41 +86,26 @@ public function canTriggerOnObject($object) {
8686
}
8787

8888
public function getTriggerObjectPHIDs() {
89+
$project_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
90+
8991
return array_merge(
9092
array(
91-
$this->repository->getPHID(),
93+
$this->getRepository()->getPHID(),
9294
$this->getPHID(),
9395
),
94-
$this->repository->getProjectPHIDs());
96+
$this->loadEdgePHIDs($project_type));
9597
}
9698

9799
public function explainValidTriggerObjects() {
98100
return pht('This rule can trigger for **repositories** and **projects**.');
99101
}
100102

101-
public static function newLegacyAdapter(
102-
PhabricatorRepository $repository,
103-
PhabricatorRepositoryCommit $commit,
104-
PhabricatorRepositoryCommitData $commit_data) {
105-
106-
$object = new HeraldCommitAdapter();
107-
108-
$commit->attachRepository($repository);
109-
110-
$object->repository = $repository;
111-
$object->commit = $commit;
112-
$object->commitData = $commit_data;
113-
114-
return $object;
115-
}
116-
117103
public function setCommit(PhabricatorRepositoryCommit $commit) {
118104
$viewer = PhabricatorUser::getOmnipotentUser();
119105

120106
$repository = id(new PhabricatorRepositoryQuery())
121107
->setViewer($viewer)
122108
->withIDs(array($commit->getRepositoryID()))
123-
->needProjectPHIDs(true)
124109
->executeOne();
125110
if (!$repository) {
126111
throw new Exception(pht('Unable to load repository!'));
@@ -137,7 +122,6 @@ public function setCommit(PhabricatorRepositoryCommit $commit) {
137122
$this->commit->attachRepository($repository);
138123
$this->commit->attachCommitData($data);
139124

140-
$this->repository = $repository;
141125
$this->commitData = $data;
142126

143127
return $this;
@@ -150,7 +134,7 @@ public function getHeraldName() {
150134
public function loadAffectedPaths() {
151135
if ($this->affectedPaths === null) {
152136
$result = PhabricatorOwnerPathQuery::loadAffectedPaths(
153-
$this->repository,
137+
$this->getRepository(),
154138
$this->commit,
155139
PhabricatorUser::getOmnipotentUser());
156140
$this->affectedPaths = $result;
@@ -161,7 +145,7 @@ public function loadAffectedPaths() {
161145
public function loadAffectedPackages() {
162146
if ($this->affectedPackages === null) {
163147
$packages = PhabricatorOwnersPackage::loadAffectedPackages(
164-
$this->repository,
148+
$this->getRepository(),
165149
$this->loadAffectedPaths());
166150
$this->affectedPackages = $packages;
167151
}
@@ -314,7 +298,7 @@ private function callConduit($method, array $params) {
314298
$drequest = DiffusionRequest::newFromDictionary(
315299
array(
316300
'user' => $viewer,
317-
'repository' => $this->repository,
301+
'repository' => $this->getRepository(),
318302
'commit' => $this->commit->getCommitIdentifier(),
319303
));
320304

@@ -325,6 +309,10 @@ private function callConduit($method, array $params) {
325309
$params);
326310
}
327311

312+
private function getRepository() {
313+
return $this->getObject()->getRepository();
314+
}
315+
328316
/* -( HarbormasterBuildableAdapterInterface )------------------------------ */
329317

330318

0 commit comments

Comments
 (0)