Page MenuHomeDevCentral

D633.id1578.diff
No OneTemporary

D633.id1578.diff

diff --git a/app/Console/Commands/ConfigShow.php b/app/Console/Commands/ConfigShow.php
--- a/app/Console/Commands/ConfigShow.php
+++ b/app/Console/Commands/ConfigShow.php
@@ -66,7 +66,7 @@
protected function getServiveStatus ($service) {
if ($service->gate === 'Phabricator') {
// Ensure the projects map is cached
- $map = \ProjectsMap::fetch($service->instance);
+ $map = \ProjectsMap::fetch($service->door);
if (!$map->isCached()) {
return "Projects map not cached.";
}
diff --git a/app/Console/Commands/PhabricatorProjectsMap.php b/app/Console/Commands/PhabricatorProjectsMap.php
--- a/app/Console/Commands/PhabricatorProjectsMap.php
+++ b/app/Console/Commands/PhabricatorProjectsMap.php
@@ -39,7 +39,7 @@
public function handle() {
foreach (Services::getForGate('Phabricator') as $service) {
$this->info("Querying projects map for " . $service->instance);
- $map = ProjectsMap::fetch($service->instance);
+ $map = ProjectsMap::fetch($service->door);
$map->saveToCache();
$this->table(
['PHID', 'Project name'],
diff --git a/app/Events/PhabricatorPayloadEvent.php b/app/Events/PhabricatorPayloadEvent.php
--- a/app/Events/PhabricatorPayloadEvent.php
+++ b/app/Events/PhabricatorPayloadEvent.php
@@ -16,12 +16,6 @@
public $door;
/**
- * The Phabricator instance
- * @var string
- */
- protected $instance;
-
- /**
* The raw payload
*/
public $payload;
@@ -35,12 +29,11 @@
/**
* Gets story from the request
*
- * @param string $instance The Phabricator instance URL
* @return PhabricatorStory
*/
protected function getStory () {
return PhabricatorStory::loadFromArray(
- $this->instance,
+ $this->door,
$this->payload
);
}
@@ -49,12 +42,10 @@
* Creates a new event instance.
*
* @param string $door
- * @param string $instance The Phabricator instance URL
* @param stdClass $payload
*/
- public function __construct($door, $instance, $payload) {
+ public function __construct($door, $payload) {
$this->door = $door;
- $this->instance = $instance;
$this->payload = $payload;
$this->story = $this->getStory();
diff --git a/app/Http/Controllers/Gate/GateController.php b/app/Http/Controllers/Gate/GateController.php
--- a/app/Http/Controllers/Gate/GateController.php
+++ b/app/Http/Controllers/Gate/GateController.php
@@ -90,6 +90,13 @@
}
/**
+ * Checks if a registered service exists for this service and door
+ */
+ protected function doesServiceExist () {
+ return $this->getService() !== null;
+ }
+
+ /**
* Gets secret for this service and door.
*
* @return string the secret, or if unknown, an empty string
diff --git a/app/Http/Controllers/Gate/PhabricatorGateController.php b/app/Http/Controllers/Gate/PhabricatorGateController.php
--- a/app/Http/Controllers/Gate/PhabricatorGateController.php
+++ b/app/Http/Controllers/Gate/PhabricatorGateController.php
@@ -2,10 +2,11 @@
namespace Nasqueron\Notifications\Http\Controllers\Gate;
+use Nasqueron\Notifications\Events\PhabricatorPayloadEvent;
+
use Event;
use Request;
-
-use Nasqueron\Notifications\Events\PhabricatorPayloadEvent;
+use Services;
class PhabricatorGateController extends GateController {
@@ -40,9 +41,8 @@
*/
public function onPost ($door) {
$this->door = $door;
- $this->instance = $this->getInstance();
- if ($this->instance === "") {
+ if (!$this->doesServiceExist()) {
abort(404, 'Unknown Phabricator instance.');
}
@@ -61,20 +61,6 @@
$this->payload = Request::all();
}
- /**
- * Gets the instance matching this door
- *
- * @return string The Phabricator root URL without trailing slash
- */
- protected function getInstance () {
- $service = $this->getService();
- if ($service === null) {
- return "";
- }
-
- return $service->instance;
- }
-
///
/// Payload processing
///
@@ -84,7 +70,6 @@
Event::fire(new PhabricatorPayloadEvent(
$this->door,
- $this->instance,
$this->payload
));
}
diff --git a/app/Phabricator/PhabricatorStory.php b/app/Phabricator/PhabricatorStory.php
--- a/app/Phabricator/PhabricatorStory.php
+++ b/app/Phabricator/PhabricatorStory.php
@@ -9,11 +9,11 @@
///
/**
- * The Phabricator main URL
+ * The Phabricator instance name
*
* @var string
*/
- public $instance;
+ public $instanceName;
/**
* The unique identifier Phabricator assigns to each story
@@ -72,10 +72,10 @@
/**
* Initializes a new instance of the Phabricator story class
*
- * @param string $instance The Phabricator main URL, without trailing slash
+ * @param string $instanceName The Phabricator instance name
*/
- public function __construct ($instance) {
- $this->instance = $instance;
+ public function __construct ($instanceName) {
+ $this->instanceName = $instanceName;
}
/**
@@ -87,8 +87,8 @@
* @param string $payload The data submitted by Phabricator
* @return PhabricatorStory
*/
- public static function loadFromArray ($phabricatorURL, $payload) {
- $instance = new self($phabricatorURL);
+ public static function loadFromArray ($instanceName, $payload) {
+ $instance = new self($instanceName);
foreach ($payload as $key => $value) {
$property = self::mapPhabricatorFeedKey($key);
@@ -167,7 +167,7 @@
public function getRepositoryPHID ($method) {
$objectPHID = $this->data['objectPHID'];
- $api = PhabricatorAPI::forInstance($this->instance);
+ $api = PhabricatorAPI::forProject($this->instanceName);
$reply = $api->call(
$method,
[ 'phids[0]' => $objectPHID ]
@@ -192,7 +192,7 @@
return [];
}
- $api = PhabricatorAPI::forInstance($this->instance);
+ $api = PhabricatorAPI::forProject($this->instanceName);
$reply = $api->call(
$method,
[ 'phids[0]' => $objectPHID ]
@@ -217,7 +217,7 @@
return [];
}
- $api = PhabricatorAPI::forInstance($this->instance);
+ $api = PhabricatorAPI::forProject($this->instanceName);
$reply = $api->call(
$method,
[
diff --git a/app/Phabricator/ProjectsMap.php b/app/Phabricator/ProjectsMap.php
--- a/app/Phabricator/ProjectsMap.php
+++ b/app/Phabricator/ProjectsMap.php
@@ -26,11 +26,11 @@
private $map = [];
/**
- * The Phabricator instance for this projects map
+ * The Phabricator instance name for this projects map
*
* @var string
*/
- private $instance;
+ private $instanceName;
/**
*
@@ -52,10 +52,10 @@
/**
* Initializes a new instance of ProjectsMap.
*
- * @param string $instance The Phabricator root URL without trailing slash
+ * @param string $instanceName The Phabricator instance name
*/
- public function __construct ($instance) {
- $this->instance = $instance;
+ public function __construct ($instanceName) {
+ $this->instanceName = $instanceName;
}
///
@@ -121,11 +121,11 @@
/**
* Gets a new ProjectsMap instance from cache or API when not cached.
*
- * @param string $phabricatorURL The Phabricator URL (e.g. http://secure.phabricator.com)
+ * @param string $phabricatorInstanceName The Phabricator instance name
* @return ProjectsMap
*/
- public static function load ($phabricatorURL) {
- $instance = new self($phabricatorURL);
+ public static function load ($phabricatorInstanceName) {
+ $instance = new self($phabricatorInstanceName);
if ($instance->isCached()) {
$instance->loadFromCache();
@@ -139,12 +139,12 @@
/**
* Gets a new ProjectsMap instance and queries Phabricator API to fill it.
*
- * @param string $phabricatorURL The Phabricator URL (e.g. http://secure.phabricator.com)
+ * @param string $phabricatorInstanceName The Phabricator instance name
* @param Nasqueron\Notifications\Contracts\APIClient $apiClient The Phabricator API client
* @return ProjectsMap
*/
- public static function fetch ($phabricatorURL, APIClient $apiClient = null) {
- $instance = new self($phabricatorURL);
+ public static function fetch ($phabricatorInstanceName, APIClient $apiClient = null) {
+ $instance = new self($phabricatorInstanceName);
$instance->setAPIClient($apiClient);
$instance->fetchFromAPI();
return $instance;
@@ -160,7 +160,7 @@
public function getAPIClient () {
if ($this->apiClient === null) {
$factory = App::make('phabricator-api');
- $this->apiClient = $factory->get($this->instance);
+ $this->apiClient = $factory->getForProject($this->instanceName);
}
return $this->apiClient;
}
@@ -174,7 +174,7 @@
/**
* Fetches the projects' map from the Phabricator API.
- *
+ *
* @throws \Exception when API reply is empty or invalid.
*/
private function fetchFromAPI () {
@@ -184,11 +184,11 @@
);
if (!$reply) {
- throw new \Exception("Empty reply calling project.query at $this->instance API.");
+ throw new \Exception("Empty reply calling project.query at $this->instanceName Conduit API.");
}
if (!property_exists($reply, 'data')) {
- throw new \Exception("Invalid reply calling project.query at $this->instance API.");
+ throw new \Exception("Invalid reply calling project.query at $this->instanceName Conduit API.");
}
foreach ($reply->data as $phid => $projectInfo) {
@@ -208,7 +208,7 @@
* @return string The cache key for the current projects map
*/
private function getCacheKey () {
- return class_basename(get_class($this)) . '-' . md5($this->instance);
+ return class_basename(get_class($this)) . '-' . md5($this->instanceName);
}
/**
diff --git a/app/Phabricator/ProjectsMapFactory.php b/app/Phabricator/ProjectsMapFactory.php
--- a/app/Phabricator/ProjectsMapFactory.php
+++ b/app/Phabricator/ProjectsMapFactory.php
@@ -7,21 +7,21 @@
/**
* Loads projects map from cache or fetches it from API if not cached.
*
- * @param string $instance The Phabricator instance
+ * @param string $instanceName The Phabricator instance name
* @return Nasqueron\Notifications\Phabricator\ProjectsMap
*/
- public function load ($instance) {
- return ProjectsMap::load($instance);
+ public function load ($instanceName) {
+ return ProjectsMap::load($instanceName);
}
/**
* Fetches projects map from API.
*
- * @param string $instance The Phabricator instance
+ * @param string $instanceName The Phabricator instance name
* @return Nasqueron\Notifications\Phabricator\ProjectsMap
*/
- public function fetch ($instance) {
- return ProjectsMap::fetch($instance);
+ public function fetch ($instanceName) {
+ return ProjectsMap::fetch($instanceName);
}
}
diff --git a/tests/Analyzers/Phabricator/WithConfiguration.php b/tests/Analyzers/Phabricator/WithConfiguration.php
--- a/tests/Analyzers/Phabricator/WithConfiguration.php
+++ b/tests/Analyzers/Phabricator/WithConfiguration.php
@@ -22,7 +22,7 @@
private function getStory() {
return $this
->getMockBuilder("Nasqueron\Notifications\Phabricator\PhabricatorStory")
- ->setConstructorArgs(["https://phab.acme"])
+ ->setConstructorArgs(["Acme"])
->getMock();
}
diff --git a/tests/Phabricator/ProjectsMapFactoryTest.php b/tests/Phabricator/ProjectsMapFactoryTest.php
--- a/tests/Phabricator/ProjectsMapFactoryTest.php
+++ b/tests/Phabricator/ProjectsMapFactoryTest.php
@@ -21,14 +21,14 @@
public function testLoadProjectsMap () {
$this->assertInstanceOf(
'\Nasqueron\Notifications\Phabricator\ProjectsMap',
- $this->factory->load("https://phabricator.acme.tld")
+ $this->factory->load("Acme")
);
}
public function testFetchProjectsMap () {
$this->assertInstanceOf(
'\Nasqueron\Notifications\Phabricator\ProjectsMap',
- $this->factory->fetch("https://phabricator.acme.tld")
+ $this->factory->fetch("Acme")
);
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -95,7 +95,7 @@
$mock = $this->mockPhabricatorAPI();
$reply = $this->mockPhabricatorAPIProjectsQueryReply();
- $mock->shouldReceive('get->call')->andReturn($reply);
+ $mock->shouldReceive('getForProject->call')->andReturn($reply);
}
///

File Metadata

Mime Type
text/plain
Expires
Fri, Jan 31, 12:09 (10 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2387858
Default Alt Text
D633.id1578.diff (13 KB)

Event Timeline