Page MenuHomeDevCentral

D124.diff
No OneTemporary

D124.diff

diff --git a/app/Analyzers/PhabricatorPayloadAnalyzer.php b/app/Analyzers/PhabricatorPayloadAnalyzer.php
--- a/app/Analyzers/PhabricatorPayloadAnalyzer.php
+++ b/app/Analyzers/PhabricatorPayloadAnalyzer.php
@@ -24,12 +24,6 @@
private $story;
/**
- * The projects associated to this story
- * @var string[]
- */
- private $projects;
-
- /**
* The configuration for the payload analyzer
* @var PhabricatorPayloadAnalyzerConfiguration;
*/
@@ -46,10 +40,9 @@
* @param string $event
* @param stdClass $payload
*/
- public function __construct($project, PhabricatorStory $story, $projects) {
+ public function __construct($project, PhabricatorStory $story) {
$this->project = $project;
$this->story = $story;
- $this->projects = $projects;
$this->loadConfiguration($project);
}
@@ -105,7 +98,7 @@
// If the payload is about some repository matching a table of
// symbols, we need to sort it to the right group.
foreach ($this->configuration->groupsMapping as $mapping) {
- foreach ($this->projects as $project) {
+ foreach ($this->story->getProjects() as $project) {
if ($mapping->doesProjectBelong($project)) {
return $mapping->group;
}
diff --git a/app/Events/PhabricatorPayloadEvent.php b/app/Events/PhabricatorPayloadEvent.php
--- a/app/Events/PhabricatorPayloadEvent.php
+++ b/app/Events/PhabricatorPayloadEvent.php
@@ -33,12 +33,6 @@
public $story;
/**
- * The list of the projects attached to this story
- * @var string[]
- */
- public $projects;
-
- /**
* Gets story from the request
*
* @param string $instance The Phabricator instance URL
@@ -63,8 +57,6 @@
$this->instance = $instance;
$this->payload = $payload;
- $story = $this->getStory();
- $this->story = $story;
- $this->projects = $story->getProjects(); // Cost: up to 3 API calls
+ $this->story = $this->getStory();
}
}
diff --git a/app/Jobs/FirePhabricatorNotification.php b/app/Jobs/FirePhabricatorNotification.php
--- a/app/Jobs/FirePhabricatorNotification.php
+++ b/app/Jobs/FirePhabricatorNotification.php
@@ -49,8 +49,7 @@
protected function createNotification() {
return new PhabricatorNotification(
$this->event->door, // Project
- $this->event->story, // Story
- $this->event->projects // Phabricator projects
+ $this->event->story // Story
);
}
}
diff --git a/app/Notifications/PhabricatorNotification.php b/app/Notifications/PhabricatorNotification.php
--- a/app/Notifications/PhabricatorNotification.php
+++ b/app/Notifications/PhabricatorNotification.php
@@ -15,7 +15,6 @@
private $story;
- private $projects;
/**
* Initializes a new PhabricatorNotification instance
@@ -24,10 +23,9 @@
* @param PhabricatorStory $story The story to convert into a notification
* @param string[] $projects the list of the projects for this story
*/
- public function __construct ($project, PhabricatorStory $story, $projects) {
- // Private properties used by the analyzer
+ public function __construct ($project, PhabricatorStory $story) {
+ // Private property used by the analyzer
$this->story = $story;
- $this->projects = $projects;
// Straightforward properties
$this->service = "Phabricator";
@@ -48,8 +46,7 @@
if ($this->analyzer === null) {
$this->analyzer = new PhabricatorPayloadAnalyzer(
$this->project,
- $this->story,
- $this->projects
+ $this->story
);
}
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
@@ -55,6 +55,16 @@
*/
public $epoch;
+ /**
+ * The projects attached to this story.
+ *
+ * When there is no project, [].
+ * When not yet queried, null.
+ *
+ * @var string[]|null
+ */
+ private $projects = null;
+
///
/// Constructors
///
@@ -181,20 +191,30 @@
* @return string[] The list of project PHIDs
*/
public function getProjects () {
+ if ($this->projects === null) {
+ $this->attachProjects();
+ }
+ return $this->projects;
+ }
+
+ /**
+ * Queries the list of the projects associated to the story
+ * and attached it to the projects property.
+ */
+ public function attachProjects () {
+ $this->projects = [];
+
$PHIDs = $this->getProjectsPHIDs();
if (count($PHIDs) == 0) {
// No project is attached to the story's object
- return [];
+ return;
}
- $projects = [];
-
$map = ProjectsMap::load($this->instance);
foreach ($PHIDs as $PHID) {
- $projects[] = $map->getProjectName($PHID);
+ $this->projects[] = $map->getProjectName($PHID);
}
- return $projects;
}
///

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 18, 00:49 (21 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2250006
Default Alt Text
D124.diff (5 KB)

Event Timeline