Page MenuHomeDevCentral

No OneTemporary

diff --git a/app/Analyzers/PhabricatorPayloadAnalyzer.php b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php
similarity index 98%
rename from app/Analyzers/PhabricatorPayloadAnalyzer.php
rename to app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php
index 677d10a..00f0775 100644
--- a/app/Analyzers/PhabricatorPayloadAnalyzer.php
+++ b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php
@@ -1,122 +1,122 @@
<?php
-namespace Nasqueron\Notifications\Analyzers;
+namespace Nasqueron\Notifications\Analyzers\Phabricator;
use Nasqueron\Notifications\Phabricator\PhabricatorStory;
use Config;
use Storage;
class PhabricatorPayloadAnalyzer {
///
/// Private members
///
/**
* The project name, used to load specific configuration and offer defaults
* @var string
*/
private $project;
/**
* The story
* @var PhabricatorStory
*/
private $story;
/**
* The configuration for the payload analyzer
* @var PhabricatorPayloadAnalyzerConfiguration;
*/
private $configuration;
///
/// Constructor
///
/**
* Creates a new GitHubPayloadAnalyzer instance.
*
* @param string $project
* @param string $event
* @param stdClass $payload
*/
public function __construct($project, PhabricatorStory $story) {
$this->project = $project;
$this->story = $story;
$this->loadConfiguration($project);
}
///
/// Configuration
///
const CONFIG_DEFAULT_FILE = 'default.json';
public function getConfigurationFileName () {
$dir = Config::get('services.phabricator.analyzer.configDir');
$filename = $dir . '/' . $this->project . '.json';
if (!Storage::has($filename)) {
return $dir . '/' . static::CONFIG_DEFAULT_FILE;
}
return $filename;
}
public function loadConfiguration () {
$fileName = $this->getConfigurationFileName();
$mapper = new \JsonMapper();
$this->configuration = $mapper->map(
json_decode(Storage::get($fileName)),
new PhabricatorPayloadAnalyzerConfiguration()
);
}
///
/// Qualification of the story
///
public function isAdministrativeEvent () {
return false;
}
/**
* Gets the group for a specific story
*
* @return string the group, central part of the routing key
*/
public function getGroup () {
// Some events are organization-level only and can't be mapped
// to projects.
if ($this->isAdministrativeEvent()) {
return $this->configuration->administrativeGroup;
}
// 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->story->getProjects() as $project) {
if ($mapping->doesProjectBelong($project)) {
return $mapping->group;
}
}
}
// Words
foreach ($this->configuration->groupsMapping as $mapping) {
if ($mapping->doesStoryBelong($this->story)) {
return $mapping->group;
}
}
// By default, fallback group is the project name or a specified value.
if (empty($this->configuration->defaultGroup)) {
return strtolower($this->project);
}
return $this->configuration->defaultGroup;
}
}
diff --git a/app/Analyzers/PhabricatorPayloadAnalyzerConfiguration.php b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzerConfiguration.php
similarity index 83%
rename from app/Analyzers/PhabricatorPayloadAnalyzerConfiguration.php
rename to app/Analyzers/Phabricator/PhabricatorPayloadAnalyzerConfiguration.php
index 8f08ab2..7598d45 100644
--- a/app/Analyzers/PhabricatorPayloadAnalyzerConfiguration.php
+++ b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzerConfiguration.php
@@ -1,26 +1,26 @@
<?php
-namespace Nasqueron\Notifications\Analyzers;
+namespace Nasqueron\Notifications\Analyzers\Phabricator;
class PhabricatorPayloadAnalyzerConfiguration {
/**
* The group for organization only events
*
* @var string
*/
public $administrativeGroup;
/**
* The default group to fallback for any event not mapped in another group
*
* @var string
*/
public $defaultGroup;
/**
* An array of RepositoryGroupMapping objects to match repositories & groups
*
- * @var PhabricatorGroupMapping[]
+ * @var ProjectGroupMapping[]
*/
public $groupsMapping;
}
diff --git a/app/Analyzers/PhabricatorGroupMapping.php b/app/Analyzers/Phabricator/ProjectGroupMapping.php
similarity index 95%
rename from app/Analyzers/PhabricatorGroupMapping.php
rename to app/Analyzers/Phabricator/ProjectGroupMapping.php
index 01e5e41..9646935 100644
--- a/app/Analyzers/PhabricatorGroupMapping.php
+++ b/app/Analyzers/Phabricator/ProjectGroupMapping.php
@@ -1,76 +1,76 @@
<?php
-namespace Nasqueron\Notifications\Analyzers;
+namespace Nasqueron\Notifications\Analyzers\Phabricator;
use Nasqueron\Notifications\Phabricator\PhabricatorStory;
-class PhabricatorGroupMapping {
+class ProjectGroupMapping {
///
/// Properties
///
/**
* The group the mapped projects belong to
*
* @var string
*/
public $group;
/**
* An array of the projects, each item a string with the name of the
* project. The wildcard '*' is allowed to specify several projects.
*
* @var array
*/
public $projects;
/**
* An array of words, each item a string with a word to find in the story.
*
* @var array
*/
public $words = [];
///
/// Helper methods
///
/**
* Determines if the specified project matches a pattern
*
* @param string $pattern The pattern, with * allowed as wildcard character
* @param string $project The project name to compare with the pattern
* @return bool
*/
public static function doesProjectMatch ($pattern, $project) {
return str_is($pattern, $project);
}
/**
* Determines if the specified project belong to this mapping
*
* @return bool
*/
public function doesProjectBelong ($actualProject) {
foreach ($this->projects as $candidateProject) {
if (static::doesProjectMatch($candidateProject, $actualProject)) {
return true;
}
}
return false;
}
/**
* Determines if the specified story belong to this mapping
*
* @return bool
*/
public function doesStoryBelong (PhabricatorStory $story) {
foreach ($this->words as $word) {
if (strpos($story->text, $word) !== false) {
return true;
}
}
return false;
}
}
diff --git a/app/Notifications/PhabricatorNotification.php b/app/Notifications/PhabricatorNotification.php
index 946046f..2f8ea4a 100644
--- a/app/Notifications/PhabricatorNotification.php
+++ b/app/Notifications/PhabricatorNotification.php
@@ -1,73 +1,73 @@
<?php
namespace Nasqueron\Notifications\Notifications;
-use Nasqueron\Notifications\Analyzers\PhabricatorPayloadAnalyzer;
+use Nasqueron\Notifications\Analyzers\Phabricator\PhabricatorPayloadAnalyzer;
use Nasqueron\Notifications\Notification;
use Nasqueron\Notifications\Phabricator\PhabricatorStory;
class PhabricatorNotification extends Notification {
/**
* @var PhabricatorPayloadAnalyzer
*/
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
*/
public function __construct ($project, PhabricatorStory $story) {
// Private property used by the analyzer
$this->story = $story;
// Straightforward properties
$this->service = "Phabricator";
$this->project = $project;
$this->rawContent = json_encode($story);
$this->text = $story->text;
// Analyzes and fills
$this->type = $story->getObjectType();
$this->group = $this->getGroup();
$this->link = $this->getLink();
}
/**
* Gets analyzer
*/
private function getAnalyzer () {
if ($this->analyzer === null) {
$this->analyzer = new PhabricatorPayloadAnalyzer(
$this->project,
$this->story
);
}
return $this->analyzer;
}
/**
* Gets the target notificatrion group
*
* @return string the target group for the notification
*/
public function getGroup () {
return $this->getAnalyzer()->getGroup();
}
/**
* Gets the notification URL. Intended to be a widget or icon link.
*
* @return string
*/
public function getLink () {
return "";
}
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Nov 25, 07:51 (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259786
Default Alt Text
(9 KB)

Event Timeline