Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F7659359
D635.id1583.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D635.id1583.diff
View Options
diff --git a/app/Console/Commands/NotificationsPayload.php b/app/Console/Commands/NotificationsPayload.php
--- a/app/Console/Commands/NotificationsPayload.php
+++ b/app/Console/Commands/NotificationsPayload.php
@@ -2,6 +2,8 @@
namespace Nasqueron\Notifications\Console\Commands;
+use Nasqueron\Notifications\Phabricator\PhabricatorStory;
+
use Illuminate\Console\Command;
use InvalidArgumentException;
@@ -123,9 +125,24 @@
$keys = $this->getNotificationConstructorParameters();
$values = $this->argument('args');
- $values['payload'] = json_decode($this->payload);
+ $values['payload'] = $this->payload;
$this->constructor = self::argumentsArrayCombine($keys, $values);
+ $this->constructor['payload'] = $this->formatPayload();
+ }
+
+ /**
+ * Formats payload to pass to constructor
+ *
+ * @return PhabricatorStory|stdClass A deserialization of the payload
+ */
+ private function formatPayload() {
+ if ($this->service === "Phabricator") {
+ $project = $this->constructor['project'];
+ return PhabricatorStory::loadFromJson($project, $this->payload);
+ }
+
+ return json_decode($this->payload);
}
/**
diff --git a/app/Notifications/PhabricatorNotification.php b/app/Notifications/PhabricatorNotification.php
--- a/app/Notifications/PhabricatorNotification.php
+++ b/app/Notifications/PhabricatorNotification.php
@@ -13,28 +13,21 @@
*/
private $analyzer = null;
- private $story;
-
-
/**
* Initializes a new PhabricatorNotification instance
*
* @param string $project The project for this notification
- * @param PhabricatorStory $story The story to convert into a notification
- * @param string[] $projects the list of the projects for this story
+ * @param PhabricatorStory $payload The story to convert into a notification
*/
- public function __construct ($project, PhabricatorStory $story) {
- // Private property used by the analyzer
- $this->story = $story;
-
+ public function __construct ($project, PhabricatorStory $payload) {
// Straightforward properties
$this->service = "Phabricator";
$this->project = $project;
- $this->rawContent = json_encode($story);
- $this->text = $story->text;
+ $this->rawContent = $payload;
+ $this->text = $payload->text;
// Analyzes and fills
- $this->type = $story->getObjectType();
+ $this->type = $payload->getObjectType();
$this->group = $this->getGroup();
$this->link = $this->getLink();
}
@@ -48,7 +41,7 @@
if ($this->analyzer === null) {
$this->analyzer = new PhabricatorPayloadAnalyzer(
$this->project,
- $this->story
+ $this->rawContent
);
}
return $this->analyzer;
diff --git a/app/Phabricator/PhabricatorStory.php b/app/Phabricator/PhabricatorStory.php
--- a/app/Phabricator/PhabricatorStory.php
+++ b/app/Phabricator/PhabricatorStory.php
@@ -2,6 +2,8 @@
namespace Nasqueron\Notifications\Phabricator;
+use InvalidArgumentException;
+
class PhabricatorStory {
///
@@ -98,6 +100,25 @@
return $instance;
}
+ /**
+ * Initializes a new instance of PhabricatorStory from a JSON payload.
+ *
+ * This is intended to parse files saved by LastPayloadSaver::savePayload.
+ *
+ * @param string $instanceName The Phabricator instance name
+ * @param string $payload The data submitted by Phabricator's JSON representation
+ * @return PhabricatorStory
+ */
+ public static function loadFromJson ($instanceName, $payload) {
+ $array = json_decode($payload, true);
+
+ if (!is_array($array)) {
+ throw new InvalidArgumentException("Payload should be deserializable as an array.");
+ }
+
+ return self::loadFromArray($instanceName, $array);
+ }
+
///
/// Helper methods
///
diff --git a/tests/Http/PayloadFullTest.php b/tests/Http/PayloadFullTest.php
--- a/tests/Http/PayloadFullTest.php
+++ b/tests/Http/PayloadFullTest.php
@@ -92,11 +92,8 @@
$this->assertResponseOk();
}
- /**
- * Tests a Phabricator gate payload.
- */
- public function testPhabricatorPayload () {
- $data = [
+ private function getDataForPhabricatorPayloadTests () {
+ return [
'storyID' => 3849,
'storyType' => 'PhabricatorApplicationTransactionFeedStory',
'storyData[objectPHID]' => 'PHID-TASK-l34fw5wievp6n6rnvpuk',
@@ -105,6 +102,13 @@
'storyText' => 'quux moved T123: Lorem ipsum dolor to Backlog on the Foo workboard.',
'epoch' => 1450654419,
];
+ }
+
+ /**
+ * Tests a Phabricator gate payload.
+ */
+ public function testPhabricatorPayload () {
+ $data = $this->getDataForPhabricatorPayloadTests();
$this->post('/gate/Phabricator/Acme', $data)->seeJson([
'gate' => 'Phabricator',
@@ -112,6 +116,13 @@
'action' => 'AMQPAction'
]);
$this->assertResponseOk();
+ }
+
+ /**
+ * Tests a Phabricator gate payload, when the door doesn't exist.
+ */
+ public function testPhabricatorPayloadOnNotExistingDoor () {
+ $data = $this->getDataForPhabricatorPayloadTests();
$this->post('/gate/Phabricator/NotExistingDoor', $data);
$this->assertResponseStatus(404);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, May 1, 13:47 (13 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2621608
Default Alt Text
D635.id1583.diff (5 KB)
Attached To
Mode
D635: Simplify PhabricatorNotification and allow to use notifications:payload
Attached
Detach File
Event Timeline
Log In to Comment