Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F11725825
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
48 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/app/Analyzers/Jenkins/JenkinsPayloadAnalyzer.php b/app/Analyzers/BasePayloadAnalyzer.php
similarity index 55%
copy from app/Analyzers/Jenkins/JenkinsPayloadAnalyzer.php
copy to app/Analyzers/BasePayloadAnalyzer.php
index 4734b26..10f0558 100644
--- a/app/Analyzers/Jenkins/JenkinsPayloadAnalyzer.php
+++ b/app/Analyzers/BasePayloadAnalyzer.php
@@ -1,173 +1,169 @@
<?php
-namespace Nasqueron\Notifications\Analyzers\Jenkins;
+namespace Nasqueron\Notifications\Analyzers;
use Config;
use Storage;
+use BadMethodCallException;
use InvalidArgumentException;
-class JenkinsPayloadAnalyzer {
+abstract class BasePayloadAnalyzer {
///
/// Private members
///
/**
* The project name, used to load specific configuration and offer defaults
* @var string
*/
- private $project;
+ protected $project;
/**
* The request content, as a structured data
* @var stdClass
*/
- private $payload;
+ protected $payload;
/**
* The configuration for the payload analyzer
- * @var Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzerConfiguration;
+ * @var Nasqueron\Notifications\Analyzers\BasePayloadAnalyzerConfiguration;
*/
- private $configuration;
+ protected $configuration;
///
/// Constructor
///
/**
* Creates a new JenkinsPayloadAnalyzer instance.
*
* @param string $project
* @param stdClass $payload
*/
public function __construct($project, $payload) {
if (!is_object($payload)) {
throw new InvalidArgumentException("Payload must be an object.");
}
$this->project = $project;
$this->payload = $payload;
$this->loadConfiguration($project);
}
///
/// Configuration
///
/**
* The default name of the configuration file
*/
const CONFIG_DEFAULT_FILE = 'default.json';
/**
* Gets the full path to the configuration file.
*
* @return string
*/
public function getConfigurationFileName () {
- $dir = Config::get('services.jenkins.analyzer.configDir');
+ $dir = Config::get('services.' . strtolower(static::SERVICE_NAME) . '.analyzer.configDir');
+
$filename = $dir . '/' . $this->project . '.json';
if (!Storage::has($filename)) {
return $dir . '/' . static::CONFIG_DEFAULT_FILE;
}
return $filename;
}
+ /**
+ * Gets full qualified class name for configuration.
+ *
+ * @return string
+ */
+ private function getCandidateConfigurationClassName() {
+ $namespace = 'Nasqueron\Notifications\Analyzers\\' . static::SERVICE_NAME;
+ return $namespace . "\\" . static::SERVICE_NAME . 'PayloadAnalyzerConfiguration';
+ }
+
+ /**
+ * Gets full qualified class name for configuration if existing,
+ * or PayloadAnalyzerConfiguration class if not.
+ *
+ * @return string The configuration class to use
+ */
+ private function getConfigurationClassName () {
+ $class = $this->getCandidateConfigurationClassName();
+
+ if (class_exists($class)) {
+ return $class;
+ }
+
+ return PayloadAnalyzerConfiguration::class;
+ }
+
+ /**
+ * Loads configuration for the analyzer
+ */
public function loadConfiguration () {
$fileName = $this->getConfigurationFileName();
+ $class = $this->getConfigurationClassName();
+
$mapper = new \JsonMapper();
$this->configuration = $mapper->map(
json_decode(Storage::get($fileName)),
- new JenkinsPayloadAnalyzerConfiguration($this->project)
+ new $class($this->project)
);
}
///
/// Properties
///
/**
- * Gets the name of the repository.
+ * Gets the name of the item.
*
* @var string
*/
- public function getJobName () {
- return $this->payload->name;
+ public function getItemName () {
+ throw new BadMethodCallException("The getItemName method must be implemented in the analyzer class if used.");
+ }
+
+ /**
+ * Determines if the event isn't related to a specific item,
+ * but to the general service.
+ *
+ * @return bool
+ */
+ public function isAdministrativeEvent () {
+ return false;
}
/**
* Gets the group for a specific payload.
*
* @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.
- $item = $this->getJobName();
- foreach ($this->configuration->groupsMapping as $mapping) {
+ $item = $this->getItemName();
+ foreach ($this->configuration->map as $mapping) {
if ($mapping->doesItemBelong($item)) {
return $mapping->group;
}
}
return $this->configuration->getDefaultGroup();
}
- ///
- /// Notify only on failure helper methods
- ///
-
- /**
- * Tries to get build status.
- *
- * @param out string $status
- * @return bool indicates if the build status is defined in the payload
- */
- private function tryGetBuildStatus (&$status) {
- if (!isset($this->payload->build->status)) {
- return false;
- }
-
- $status = $this->payload->build->status;
- return true;
- }
-
- /**
- * @return bool
- */
- public function shouldNotifyOnlyOnFailure () {
- return in_array(
- $this->getJobName(),
- $this->configuration->notifyOnlyOnFailure
- );
- }
-
- /**
- * Determines if the build status is a failure.
- *
- * @return bool
- */
- public function isFailure () {
- if (!$this->tryGetBuildStatus($status)) {
- return false;
- }
-
- return $status === "FAILURE"
- || $status === "ABORTED"
- || $status === "UNSTABLE";
- }
-
- /**
- * Indicates if we should handle this payload to trigger a notification.
- *
- * @return bool if false, this payload is to be ignored for notifications
- */
- public function shouldNotify () {
- return $this->isFailure() || !$this->shouldNotifyOnlyOnFailure();
- }
-
}
diff --git a/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php b/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php
index d74527a..865f323 100644
--- a/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php
+++ b/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php
@@ -1,191 +1,112 @@
<?php
namespace Nasqueron\Notifications\Analyzers\GitHub;
+use Nasqueron\Notifications\Analyzers\BasePayloadAnalyzer;
use Nasqueron\Notifications\Analyzers\GitHub\Events\Event;
use Nasqueron\Notifications\Analyzers\GitHub\Events\UnknownEvent;
-use Config;
-use Storage;
+class GitHubPayloadAnalyzer extends BasePayloadAnalyzer {
-class GitHubPayloadAnalyzer {
+ /**
+ * The name of the service, used to get specific classes and config
+ */
+ const SERVICE_NAME = "GitHub";
///
/// Private members
///
- /**
- * The project name, used to load specific configuration and offer defaults
- * @var string
- */
- private $project;
-
/**
* The GitHub event triggering this request
* @var string
*/
private $event;
- /**
- * The request content, as a structured data
- * @var stdClass
- */
- private $payload;
-
- /**
- * The configuration for the payload analyzer
- * @var Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzerConfiguration;
- */
- private $configuration;
-
/**
* The payload analyzer event
*
* @var Nasqueron\Notifications\Analyzers\GitHub\Events\Event;
*/
private $analyzerEvent;
///
/// Constructor
///
/**
* Creates a new GitHubPayloadAnalyzer instance.
*
* @param string $project
* @param string $event
* @param stdClass $payload
*/
public function __construct($project, $event, $payload) {
- if (!is_object($payload)) {
- throw new \InvalidArgumentException("Payload must be an object.");
- }
+ parent::__construct($project, $payload);
- $this->project = $project;
$this->event = $event;
- $this->payload = $payload;
-
- $this->loadConfiguration($project);
try {
$this->analyzerEvent = Event::forPayload($event, $payload);
} catch (\InvalidArgumentException $ex) {
$this->analyzerEvent = new UnknownEvent($event);
}
}
- ///
- /// Configuration
- ///
-
- /**
- * The default name of the configuration file
- */
- const CONFIG_DEFAULT_FILE = 'default.json';
-
- /**
- * Gets the full path to the configuration file.
- *
- * @return string
- */
- public function getConfigurationFileName () {
- $dir = Config::get('services.github.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 GitHubPayloadAnalyzerConfiguration($this->project)
- );
- }
-
///
/// Properties
///
/**
- * Gets the name of the repository.
+ * Gets the name of the item, ie here of the name of the repository.
*
* @var string
*/
- public function getRepository () {
+ public function getItemName () {
if ($this->isAdministrativeEvent()) {
return '';
}
return $this->payload->repository->name;
}
///
/// Qualification of the payload
///
/**
* @return bool
*/
public function isAdministrativeEvent () {
$administrativeEvents = [
'membership', // Member added to team
'ping', // Special ping pong event, fired on new hook
'repository', // Repository created
];
return in_array($this->event, $administrativeEvents);
}
- /**
- * Gets the group for a specific payload.
- *
- * @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 an
- // existing repository.
- 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.
- $repository = $this->getRepository();
- foreach ($this->configuration->repositoryMapping as $mapping) {
- if ($mapping->doesItemBelong($repository)) {
- return $mapping->group;
- }
- }
-
- return $this->configuration->getDefaultGroup();
- }
-
///
/// Description of the payload
///
/**
* Gets a short textual description of the event.
*
* @return string
*/
public function getDescription () {
return $this->analyzerEvent->getDescription();
}
/**
* Gets a link to view the event on GitHub.
*
* @return string The most relevant URL
*/
public function getLink () {
return $this->analyzerEvent->getLink();
}
}
diff --git a/app/Analyzers/Jenkins/JenkinsPayloadAnalyzer.php b/app/Analyzers/Jenkins/JenkinsPayloadAnalyzer.php
index 4734b26..699340b 100644
--- a/app/Analyzers/Jenkins/JenkinsPayloadAnalyzer.php
+++ b/app/Analyzers/Jenkins/JenkinsPayloadAnalyzer.php
@@ -1,173 +1,85 @@
<?php
namespace Nasqueron\Notifications\Analyzers\Jenkins;
+use Nasqueron\Notifications\Analyzers\BasePayloadAnalyzer;
+
use Config;
use Storage;
use InvalidArgumentException;
-class JenkinsPayloadAnalyzer {
-
- ///
- /// Private members
- ///
-
- /**
- * The project name, used to load specific configuration and offer defaults
- * @var string
- */
- private $project;
-
- /**
- * The request content, as a structured data
- * @var stdClass
- */
- private $payload;
-
- /**
- * The configuration for the payload analyzer
- * @var Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzerConfiguration;
- */
- private $configuration;
-
- ///
- /// Constructor
- ///
-
- /**
- * Creates a new JenkinsPayloadAnalyzer instance.
- *
- * @param string $project
- * @param stdClass $payload
- */
- public function __construct($project, $payload) {
- if (!is_object($payload)) {
- throw new InvalidArgumentException("Payload must be an object.");
- }
-
- $this->project = $project;
- $this->payload = $payload;
-
- $this->loadConfiguration($project);
- }
-
- ///
- /// Configuration
- ///
-
- /**
- * The default name of the configuration file
- */
- const CONFIG_DEFAULT_FILE = 'default.json';
+class JenkinsPayloadAnalyzer extends BasePayloadAnalyzer {
/**
- * Gets the full path to the configuration file.
- *
- * @return string
+ * The name of the service, used to get specific classes and config
*/
- public function getConfigurationFileName () {
- $dir = Config::get('services.jenkins.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 JenkinsPayloadAnalyzerConfiguration($this->project)
- );
- }
+ const SERVICE_NAME = "Jenkins";
///
- /// Properties
+ /// Payload custom properties
///
/**
- * Gets the name of the repository.
+ * Gets the name of the item, ie here of the job.
*
* @var string
*/
- public function getJobName () {
+ public function getItemName () {
return $this->payload->name;
}
- /**
- * Gets the group for a specific payload.
- *
- * @return string The group, central part of the routing key
- */
- public function getGroup () {
- // If the payload is about some repository matching a table of
- // symbols, we need to sort it to the right group.
- $item = $this->getJobName();
- foreach ($this->configuration->groupsMapping as $mapping) {
- if ($mapping->doesItemBelong($item)) {
- return $mapping->group;
- }
- }
-
- return $this->configuration->getDefaultGroup();
- }
-
///
/// Notify only on failure helper methods
///
/**
* Tries to get build status.
*
* @param out string $status
* @return bool indicates if the build status is defined in the payload
*/
private function tryGetBuildStatus (&$status) {
if (!isset($this->payload->build->status)) {
return false;
}
$status = $this->payload->build->status;
return true;
}
/**
* @return bool
*/
public function shouldNotifyOnlyOnFailure () {
return in_array(
- $this->getJobName(),
+ $this->getItemName(),
$this->configuration->notifyOnlyOnFailure
);
}
/**
* Determines if the build status is a failure.
*
* @return bool
*/
public function isFailure () {
if (!$this->tryGetBuildStatus($status)) {
return false;
}
return $status === "FAILURE"
|| $status === "ABORTED"
|| $status === "UNSTABLE";
}
/**
* Indicates if we should handle this payload to trigger a notification.
*
* @return bool if false, this payload is to be ignored for notifications
*/
public function shouldNotify () {
return $this->isFailure() || !$this->shouldNotifyOnlyOnFailure();
}
}
diff --git a/app/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfiguration.php b/app/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfiguration.php
index b2844cc..1b70039 100644
--- a/app/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfiguration.php
+++ b/app/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfiguration.php
@@ -1,72 +1,18 @@
<?php
namespace Nasqueron\Notifications\Analyzers\Jenkins;
-class JenkinsPayloadAnalyzerConfiguration {
+use Nasqueron\Notifications\Analyzers\PayloadAnalyzerConfiguration;
- ///
- /// Private members
- ///
-
- /**
- * The project this configuration is for
- *
- * @var string
- */
- private $project;
+class JenkinsPayloadAnalyzerConfiguration extends PayloadAnalyzerConfiguration {
///
/// Public properties
///
- /**
- * The default group to fallback for any event not mapped in another group
- *
- * @var string
- */
- public $defaultGroup;
-
- /**
- * An array of RepositoryGroupMapping objects to match jobs & groups
- *
- * @var \Nasqueron\Notifications\Analyzers\ItemGroupMapping[]
- */
- public $groupsMapping;
-
/**
* @var array
*/
public $notifyOnlyOnFailure;
- ///
- /// Constructor
- ///
-
- /**
- * Initializes a new instance of the GitHubPayloadAnalyzerConfiguration class
- *
- * @param string $project The project name this configuration is related to
- */
- public function __construct ($project) {
- $this->project = $project;
- }
-
- ///
- /// Helper methods
- ///
-
- /**
- * Gets the default group
- *
- * @return string the default group, as set in the configuration,
- * or if omitted, the project name as fallback.
- */
- public function getDefaultGroup () {
- if (empty($this->defaultGroup)) {
- return strtolower($this->project);
- }
-
- return $this->defaultGroup;
- }
-
}
diff --git a/app/Analyzers/GitHub/GitHubPayloadAnalyzerConfiguration.php b/app/Analyzers/PayloadAnalyzerConfiguration.php
similarity index 84%
rename from app/Analyzers/GitHub/GitHubPayloadAnalyzerConfiguration.php
rename to app/Analyzers/PayloadAnalyzerConfiguration.php
index fa36bf2..c2c8b15 100644
--- a/app/Analyzers/GitHub/GitHubPayloadAnalyzerConfiguration.php
+++ b/app/Analyzers/PayloadAnalyzerConfiguration.php
@@ -1,73 +1,74 @@
<?php
-namespace Nasqueron\Notifications\Analyzers\GitHub;
+namespace Nasqueron\Notifications\Analyzers;
-class GitHubPayloadAnalyzerConfiguration {
+class PayloadAnalyzerConfiguration {
///
/// Private members
///
/**
* The project this configuration is for
*
* @var string
*/
- private $project;
+ protected $project;
///
/// Public properties
///
/**
* 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 \Nasqueron\Notifications\Analyzers\ItemGroupMapping[]
*/
- public $repositoryMapping;
+ public $map;
///
/// Constructor
///
/**
- * Initializes a new instance of the GitHubPayloadAnalyzerConfiguration class
+ * Initializes a new instance of the BasePayloadAnalyzerConfiguration class
*
* @param string $project The project name this configuration is related to
*/
public function __construct ($project) {
$this->project = $project;
}
///
/// Helper methods
///
/**
* Gets the default group
*
* @return string the default group, as set in the configuration,
* or if omitted, the project name as fallback.
*/
public function getDefaultGroup () {
if (empty($this->defaultGroup)) {
return strtolower($this->project);
}
return $this->defaultGroup;
}
+
}
diff --git a/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php
index f949040..b00fd62 100644
--- a/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php
+++ b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php
@@ -1,138 +1,77 @@
<?php
namespace Nasqueron\Notifications\Analyzers\Phabricator;
+use Nasqueron\Notifications\Analyzers\BasePayloadAnalyzer;
+
use Nasqueron\Notifications\Phabricator\PhabricatorStory;
-use Config;
-use Storage;
+class PhabricatorPayloadAnalyzer extends BasePayloadAnalyzer {
-class PhabricatorPayloadAnalyzer {
+ /**
+ * The name of the service, used to get specific classes and config
+ */
+ const SERVICE_NAME = "Phabricator";
///
/// 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 PhabricatorPayloadAnalyzer instance.
*
* @param string $project
* @param PhabricatorStory $story
*/
public function __construct($project, PhabricatorStory $story) {
$this->project = $project;
$this->story = $story;
$this->loadConfiguration($project);
}
- ///
- /// Configuration
- ///
-
- /**
- * The default name of the configuration file
- */
- const CONFIG_DEFAULT_FILE = 'default.json';
-
- /**
- * Gets the full path to the configuration file.
- *
- * @return string
- */
- 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;
- }
-
- /**
- * Gets the full path to the configuration file.
- *
- * @return string
- */
- public function loadConfiguration () {
- $fileName = $this->getConfigurationFileName();
-
- $mapper = new \JsonMapper();
- $this->configuration = $mapper->map(
- json_decode(Storage::get($fileName)),
- new PhabricatorPayloadAnalyzerConfiguration()
- );
- }
-
///
/// Qualification of the story
///
- /**
- * @return bool
- */
- 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->configuration->map as $mapping) {
foreach ($this->story->getProjects() as $project) {
if ($mapping->doesItemBelong($project)) {
return $mapping->group;
}
}
}
// Words
- foreach ($this->configuration->groupsMapping as $mapping) {
+ foreach ($this->configuration->map 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;
}
-}
+}
\ No newline at end of file
diff --git a/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzerConfiguration.php b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzerConfiguration.php
index 7584ad7..0b4a802 100644
--- a/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzerConfiguration.php
+++ b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzerConfiguration.php
@@ -1,26 +1,16 @@
<?php
namespace Nasqueron\Notifications\Analyzers\Phabricator;
-class PhabricatorPayloadAnalyzerConfiguration {
- /**
- * The group for organization only events
- *
- * @var string
- */
- public $administrativeGroup;
+use Nasqueron\Notifications\Analyzers\PayloadAnalyzerConfiguration;
- /**
- * The default group to fallback for any event not mapped in another group
- *
- * @var string
- */
- public $defaultGroup;
+class PhabricatorPayloadAnalyzerConfiguration extends PayloadAnalyzerConfiguration {
/**
* An array of RepositoryGroupMapping objects to match repositories & groups
*
* @var PhabricatorGroupMapping[]
*/
- public $groupsMapping;
+ public $map;
+
}
diff --git a/storage/app/GitHubPayloadAnalyzer/default.json b/storage/app/GitHubPayloadAnalyzer/default.json
index 8a31c71..b5378d2 100644
--- a/storage/app/GitHubPayloadAnalyzer/default.json
+++ b/storage/app/GitHubPayloadAnalyzer/default.json
@@ -1,5 +1,5 @@
{
"administrativeGroup": "orgz",
"defaultGroup": "",
- "repositoryMapping": []
+ "map": []
}
diff --git a/storage/app/JenkinsPayloadAnalyzer/default.json b/storage/app/JenkinsPayloadAnalyzer/default.json
index 3ec0e5a..3b948cf 100644
--- a/storage/app/JenkinsPayloadAnalyzer/default.json
+++ b/storage/app/JenkinsPayloadAnalyzer/default.json
@@ -1,5 +1,5 @@
{
"defaultGroup": "ci",
- "groupsMapping": [],
+ "map": [],
"notifyOnlyOnFailure": []
}
diff --git a/storage/app/PhabricatorPayloadAnalyzer/default.json b/storage/app/PhabricatorPayloadAnalyzer/default.json
index 71e3122..b5378d2 100644
--- a/storage/app/PhabricatorPayloadAnalyzer/default.json
+++ b/storage/app/PhabricatorPayloadAnalyzer/default.json
@@ -1,5 +1,5 @@
{
"administrativeGroup": "orgz",
"defaultGroup": "",
- "groupsMapping": []
+ "map": []
}
diff --git a/tests/Analyzers/GitHub/GitHubPayloadAnalyzerTest.php b/tests/Analyzers/GitHub/GitHubPayloadAnalyzerTest.php
index 08bb7e1..5af44be 100644
--- a/tests/Analyzers/GitHub/GitHubPayloadAnalyzerTest.php
+++ b/tests/Analyzers/GitHub/GitHubPayloadAnalyzerTest.php
@@ -1,140 +1,140 @@
<?php
namespace Nasqueron\Notifications\Tests\Analyzers;
use Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzer;
use Nasqueron\Notifications\Tests\TestCase;
class GitHubPayloadAnalyzerTest extends TestCase {
/**
* @var Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzer
*/
private $unknownEventAnalyzer;
/**
* @var Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzer
*/
private $pingAnalyzer;
/**
* @var Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzer
*/
private $pushAnalyzer;
/**
* @var Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzer
*/
private $pushToMappedRepositoryAnalyzer;
/**
* Prepares the tests
*/
public function setUp () {
parent::setUp();
$this->unknownEventAnalyzer = new GitHubPayloadAnalyzer(
"Acme", // Expected without known config file
"quux",
new \stdClass
);
$this->pingAnalyzer = new GitHubPayloadAnalyzer(
"Nasqueron", // Expected with known config file
"ping",
new \stdClass
);
$filename = __DIR__ . "/../../data/payloads/GitHubEvents/push.json";
$payloadRawContent = file_get_contents($filename);
$payload = json_decode($payloadRawContent);
$this->pushAnalyzer = new GitHubPayloadAnalyzer(
"Nasqueron", // Expected with known config
"push",
$payload
);
$dockerPayload = json_decode($payloadRawContent);
$dockerPayload->repository->name = "docker-someapp";
$this->pushToMappedRepositoryAnalyzer = new GitHubPayloadAnalyzer(
"Nasqueron", // Expected with known config
"push",
$dockerPayload
);
}
///
/// Test constructor
///
/**
* @expectedException InvalidArgumentException
*/
public function testConstructorThrowsAnExceptionWhenPayloadIsInvalid () {
new GitHubPayloadAnalyzer(
"Acme",
"push",
"This is not an object deserialized from JSON but a string."
);
}
///
/// Test getConfigurationFileName
///
public function testGetConfigurationFileNameWhenConfigExists () {
$this->assertSame(
"GitHubPayloadAnalyzer/Nasqueron.json",
$this->pingAnalyzer->getConfigurationFileName()
);
}
public function testGetConfigurationFileNameWhenConfigDoesNotExist () {
$this->assertSame(
"GitHubPayloadAnalyzer/default.json",
$this->unknownEventAnalyzer->getConfigurationFileName()
);
}
///
- /// Test getRepository
+ /// Test getItemName
///
- public function testGetRepositoryWhenEventIsAdministrative () {
- $this->assertEmpty($this->pingAnalyzer->getRepository());
+ public function testGetItemNameWhenEventIsAdministrative () {
+ $this->assertEmpty($this->pingAnalyzer->getItemName());
}
- public function testGetRepositoryWhenEventIsRepositoryRelative () {
- $this->assertSame("public-repo", $this->pushAnalyzer->getRepository());
+ public function testGetItemNameWhenEventIsRepositoryRelative () {
+ $this->assertSame("public-repo", $this->pushAnalyzer->getItemName());
}
///
/// Test getGroup
///
public function testGetGroupWhenEventIsAdministrative () {
$this->assertSame("orgz", $this->pingAnalyzer->getGroup());
}
public function testGetGroupOnPushToMappedRepository () {
$this->assertSame("docker", $this->pushToMappedRepositoryAnalyzer->getGroup());
}
public function testGetGroupOnPushToNotMappedRepository () {
$this->assertSame("nasqueron", $this->pushAnalyzer->getGroup());
}
///
/// Test if our fallback is correct when the GitHub event type is unknown
///
public function testDescriptionContainsTypeWhenEventTypeIsUnknown () {
$this->assertContains(
"quux",
$this->unknownEventAnalyzer->getDescription()
);
}
}
diff --git a/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfigurationTest.php b/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfigurationTest.php
index 9a47df4..fb9577c 100644
--- a/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfigurationTest.php
+++ b/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerConfigurationTest.php
@@ -1,62 +1,62 @@
<?php
namespace Nasqueron\Notifications\Tests\Analyzers;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzerConfiguration;
use Nasqueron\Notifications\Analyzers\ItemGroupMapping;
use Nasqueron\Notifications\Tests\TestCase;
class JenkinsPayloadAnalyzerConfigurationTest extends TestCase {
/**
* Configuration
*
* @var Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzerConfiguration
*/
protected $configuration;
/**
* Prepares the test
*/
public function setUp () {
$filename = __DIR__ . '/../../data/JenkinsPayloadAnalyzer/Nasqueron.json';
$mapper = new \JsonMapper();
$this->configuration = $mapper->map(
json_decode(file_get_contents($filename)),
new JenkinsPayloadAnalyzerConfiguration('Nasqueron')
);
parent::setUp();
}
/**
* Determines the JSON object is well parsed
*/
public function testProperties () {
$this->assertSame("ci", $this->configuration->defaultGroup);
- foreach ($this->configuration->groupsMapping as $item) {
+ foreach ($this->configuration->map as $item) {
$this->assertInstanceOf(ItemGroupMapping::class, $item);
}
}
///
/// Tests for getDefaultGroup
///
public function testGetDefaultGroup () {
$this->configuration->defaultGroup = "quux";
$this->assertSame("quux", $this->configuration->getDefaultGroup());
}
public function testGetDefaultGroupWhenNotInConfig () {
$this->configuration->defaultGroup = "";
$this->assertSame("nasqueron", $this->configuration->getDefaultGroup());
$this->configuration->defaultGroup = null;
$this->assertSame("nasqueron", $this->configuration->getDefaultGroup());
}
}
diff --git a/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerTest.php b/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerTest.php
index 663ec40..f3edd9d 100644
--- a/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerTest.php
+++ b/tests/Analyzers/Jenkins/JenkinsPayloadAnalyzerTest.php
@@ -1,78 +1,78 @@
<?php
namespace Nasqueron\Notifications\Tests\Analyzers;
use Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzer;
use Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzerConfiguration;
use Nasqueron\Notifications\Tests\TestCase;
class JenkinsPayloadAnalyzerTest extends TestCase {
/**
* Jenkins analyzer to a successful build
*
* @var Nasqueron\Notifications\Analyzers\Jenkins\JenkinsPayloadAnalyzer
*/
protected $analyzer;
/**
* @var stdClass
*/
protected $payload;
/**
* Prepares the test
*/
public function setUp () {
parent::setUp();
$filename = __DIR__ . '/../../data/payloads/JenkinsToIgnorePayload.json';
$this->payload = json_decode(file_get_contents($filename));
$this->analyzer = new JenkinsPayloadAnalyzer("Nasqueron", $this->payload);
}
- public function testGetJobName () {
- $this->assertSame("test-prod-env", $this->analyzer->getJobName());
+ public function testGetItemName () {
+ $this->assertSame("test-prod-env", $this->analyzer->getItemName());
}
public function testGetGroup () {
$this->assertSame("ops", $this->analyzer->getGroup());
}
public function testGetGroupWhenWeNeedDefaultFallback () {
$this->payload->name = "quux";
$this->assertSame("ci", $this->analyzer->getGroup());
}
public function testShouldNotifyWhenStatusIsUndefined () {
unset($this->payload->build->status);
$this->assertFalse($this->analyzer->shouldNotify());
}
/**
* @dataProvider payloadStatusProvider
*/
public function testShouldNotifyByStatus ($status, $shouldNotify) {
$this->payload->build->status = $status;
$this->assertSame($shouldNotify, $this->analyzer->shouldNotify());
}
/**
* Provides data for testShouldNotifyByStatus
*
* @return array
*/
public function payloadStatusProvider () {
return [
// Build status to notify
["FAILURE", true],
["ABORTED", true],
["UNSTABLE", true],
// Build status to ignore
["SUCCESS", false],
["NOT_BUILT", false],
];
}
}
diff --git a/tests/Analyzers/GitHub/GitHubPayloadAnalyzerConfigurationTest.php b/tests/Analyzers/PayloadAnalyzerConfigurationTest.php
similarity index 76%
rename from tests/Analyzers/GitHub/GitHubPayloadAnalyzerConfigurationTest.php
rename to tests/Analyzers/PayloadAnalyzerConfigurationTest.php
index 056e534..8df2323 100644
--- a/tests/Analyzers/GitHub/GitHubPayloadAnalyzerConfigurationTest.php
+++ b/tests/Analyzers/PayloadAnalyzerConfigurationTest.php
@@ -1,63 +1,63 @@
<?php
namespace Nasqueron\Notifications\Tests\Analyzers;
use Illuminate\Foundation\Testing\WithoutMiddleware;
-use Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzerConfiguration;
+use Nasqueron\Notifications\Analyzers\PayloadAnalyzerConfiguration;
use Nasqueron\Notifications\Analyzers\ItemGroupMapping;
use Nasqueron\Notifications\Tests\TestCase;
-class GitHubPayloadAnalyzerConfigurationTest extends TestCase {
+class PayloadAnalyzerConfigurationTest extends TestCase {
/**
* Configuration
*
- * @var Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzerConfiguration
+ * @var Nasqueron\Notifications\Analyzers\PayloadAnalyzerConfiguration
*/
protected $configuration;
/**
* Prepares the test
*/
public function setUp () {
- $filename = __DIR__ . '/../../data/GitHubPayloadAnalyzer/Nasqueron.json';
+ $filename = __DIR__ . '/../data/GitHubPayloadAnalyzer/Nasqueron.json';
$mapper = new \JsonMapper();
$this->configuration = $mapper->map(
json_decode(file_get_contents($filename)),
- new GitHubPayloadAnalyzerConfiguration('Nasqueron')
+ new PayloadAnalyzerConfiguration('Nasqueron')
);
parent::setUp();
}
/**
* Determines the JSON object is well parsed
*/
public function testProperties () {
$this->assertSame("orgz", $this->configuration->administrativeGroup);
$this->assertSame("nasqueron", $this->configuration->defaultGroup);
- foreach ($this->configuration->repositoryMapping as $item) {
+ foreach ($this->configuration->map as $item) {
$this->assertInstanceOf(ItemGroupMapping::class, $item);
}
}
///
/// Tests for getDefaultGroup
///
public function testGetDefaultGroup () {
$this->configuration->defaultGroup = "quux";
$this->assertSame("quux", $this->configuration->getDefaultGroup());
}
public function testGetDefaultGroupWhenNotInConfig () {
$this->configuration->defaultGroup = "";
$this->assertSame("nasqueron", $this->configuration->getDefaultGroup());
$this->configuration->defaultGroup = null;
$this->assertSame("nasqueron", $this->configuration->getDefaultGroup());
}
}
diff --git a/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php b/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php
index b6376ef..ec01e40 100644
--- a/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php
+++ b/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php
@@ -1,90 +1,90 @@
<?php
namespace Nasqueron\Notifications\Tests\Analyzers\Phabricator;
use Nasqueron\Notifications\Analyzers\Phabricator\PhabricatorGroupMapping;
use Nasqueron\Notifications\Tests\TestCase;
class PhabricatorGroupMappingTest extends TestCase {
use WithConfiguration;
/**
* @var PhabricatorGroupMapping|]
*/
private $mappings;
/**
* @var PhabricatorStory
*/
private $story;
public function setUp () {
parent::setUp();
$config = $this->getPhabricatorPayloadAnalyzerConfiguration();
$keys = [
'projects',
'words',
'strongWords',
];
- $this->mappings = array_combine($keys, $config->groupsMapping);
+ $this->mappings = array_combine($keys, $config->map);
$this->story = $this->getStory();
}
///
/// Tests
///
public function testDoesProjectBelong () {
$mapping = $this->mappings['projects'];
$this->assertFalse(
$mapping->doesItemBelong("")
);
$this->assertFalse(
$mapping->doesItemBelong("Tasacora")
);
$this->assertTrue(
$mapping->doesItemBelong("Docker images")
);
$this->assertFalse(
$mapping->doesItemBelong("Docker")
);
$this->assertFalse(
$mapping->doesItemBelong("Docker images quux")
);
}
public function testDoesStoryBelong () {
$mapping = $this->mappings['words'];
$this->assertFalse(
$mapping->doesStoryBelong($this->story)
);
$this->story->text = "Review the cartography elements.";
$this->assertTrue(
$mapping->doesStoryBelong($this->story)
);
}
/**
* Test to fix T773
*/
public function testDoesStoryBelongWhenWordIsInAnotherCase () {
$mapping = $this->mappings['words'];
$this->story->text = "Review the Cartography elements.";
$this->assertTrue(
$mapping->doesStoryBelong($this->story)
);
}
}
diff --git a/tests/Analyzers/Phabricator/PhabricatorPayloadAnalyzerTest.php b/tests/Analyzers/Phabricator/PhabricatorPayloadAnalyzerTest.php
index 549d1fb..0e11951 100644
--- a/tests/Analyzers/Phabricator/PhabricatorPayloadAnalyzerTest.php
+++ b/tests/Analyzers/Phabricator/PhabricatorPayloadAnalyzerTest.php
@@ -1,89 +1,96 @@
<?php
namespace Nasqueron\Notifications\Tests\Analyzers\Phabricator;
use Nasqueron\Notifications\Analyzers\Phabricator\PhabricatorPayloadAnalyzer;
use Nasqueron\Notifications\Tests\TestCase;
class PhabricatorPayloadAnalyzerTest extends TestCase {
use WithConfiguration;
/**
* @var PhabricatorPayloadAnalyzer
*/
private $analyzer;
/**
* @var PhabricatorStory
*/
private $story;
public function setUp () {
parent::setUp();
$this->story = $this->getStory();
$this->analyzer = new PhabricatorPayloadAnalyzer(
"Nasqueron",
$this->story
);
}
public function testGetConfigurationFileName () {
$this->assertSame(
"PhabricatorPayloadAnalyzer/Nasqueron.json",
$this->analyzer->getConfigurationFileName()
);
}
public function testGetGroupWhereEventIsAdministrative () {
$this->markTestIncomplete(
"Not yet implemented feature. See T664."
);
$this->assertSame(
"orgz",
$this->analyzer->getGroup()
);
}
public function testGetGroupWhereStoryDoesntMatchAnything () {
$this->attachProjectsToStoryMock($this->story, []);
$this->assertSame(
"nasqueron",
$this->analyzer->getGroup()
);
}
public function testGetGroupWhereStoryMatchesProject () {
$this->attachProjectsToStoryMock($this->story, ['Docker images']);
$this->assertSame(
"docker",
$this->analyzer->getGroup()
);
}
public function testGetGroupWhereStoryMatchesWords () {
$this->attachProjectsToStoryMock($this->story, []);
$this->story->text = "Review the cartography elements.";
$this->assertSame(
"tasacora",
$this->analyzer->getGroup()
);
}
public function testGetGroupWhereWordsAreStrong () {
$this->markTestIncomplete(
"Not yet implemented feature. See T748."
);
$this->attachProjectsToStoryMock($this->story, ['Docker images']);
$this->story->text = "Review the cartography elements on Dwellers.";
$this->assertSame(
"ops",
$this->analyzer->getGroup()
);
}
+ /**
+ * @expectedException \BadMethodCallException
+ */
+ public function testGetItemThrowsBadMethodCallException () {
+ $this->analyzer->getItemName();
+ }
+
}
diff --git a/tests/data/GitHubPayloadAnalyzer/Nasqueron.json b/tests/data/GitHubPayloadAnalyzer/Nasqueron.json
index 21bab6e..9e1b5a3 100644
--- a/tests/data/GitHubPayloadAnalyzer/Nasqueron.json
+++ b/tests/data/GitHubPayloadAnalyzer/Nasqueron.json
@@ -1,30 +1,30 @@
{
"administrativeGroup": "orgz",
"defaultGroup": "nasqueron",
- "repositoryMapping": [
+ "map": [
{
"group": "docker",
"items": [
"docker-*"
]
},
{
"group": "tasacora",
"items": [
"tasacora-*"
]
},
{
"group": "ops",
"items": [
"decommission",
"discourse-config",
"ftp",
"notifications",
"operations",
"servers-*",
"zemke-rhyne"
]
}
]
}
diff --git a/tests/data/GitHubPayloadAnalyzer/default.json b/tests/data/GitHubPayloadAnalyzer/default.json
index 8a31c71..b5378d2 100644
--- a/tests/data/GitHubPayloadAnalyzer/default.json
+++ b/tests/data/GitHubPayloadAnalyzer/default.json
@@ -1,5 +1,5 @@
{
"administrativeGroup": "orgz",
"defaultGroup": "",
- "repositoryMapping": []
+ "map": []
}
diff --git a/tests/data/JenkinsPayloadAnalyzer/Nasqueron.json b/tests/data/JenkinsPayloadAnalyzer/Nasqueron.json
index 02867e3..bc13c1a 100644
--- a/tests/data/JenkinsPayloadAnalyzer/Nasqueron.json
+++ b/tests/data/JenkinsPayloadAnalyzer/Nasqueron.json
@@ -1,27 +1,27 @@
{
"defaultGroup": "ci",
- "groupsMapping": [
+ "map": [
{
"group": "wikidata",
"items": [
"deploy-irc-daeghrefn-wikidata"
]
},
{
"group": "ops",
"items": [
"deploy-website-*",
"test-prod-env"
]
},
{
"group": "devtools",
"items": [
"test-notifications-*"
]
}
],
"notifyOnlyOnFailure": [
"test-prod-env"
]
}
diff --git a/tests/data/JenkinsPayloadAnalyzer/default.json b/tests/data/JenkinsPayloadAnalyzer/default.json
index 3ec0e5a..3b948cf 100644
--- a/tests/data/JenkinsPayloadAnalyzer/default.json
+++ b/tests/data/JenkinsPayloadAnalyzer/default.json
@@ -1,5 +1,5 @@
{
"defaultGroup": "ci",
- "groupsMapping": [],
+ "map": [],
"notifyOnlyOnFailure": []
}
diff --git a/tests/data/PhabricatorPayloadAnalyzer/Nasqueron.json b/tests/data/PhabricatorPayloadAnalyzer/Nasqueron.json
index bbb4b37..3abc484 100644
--- a/tests/data/PhabricatorPayloadAnalyzer/Nasqueron.json
+++ b/tests/data/PhabricatorPayloadAnalyzer/Nasqueron.json
@@ -1,42 +1,42 @@
{
"administrativeGroup": "orgz",
"defaultGroup": "nasqueron",
- "groupsMapping": [
+ "map": [
{
"group": "docker",
"items": [
"Docker images",
"Nasqueron Docker deployment squad"
]
},
{
"group": "tasacora",
"items":[
"Tasacora"
],
"words": [
"Tasacora",
"cartography"
]
},
{
"group": "ops",
"items": [
"Continous integration and delivery",
"IPv6",
"Mail",
"Message queues",
"Murasil",
"Nasqueron security operations squad",
"Servers",
"Ops-sprint-*"
],
"words": [
"Ysul",
"Dwellers",
"pkg audit"
],
"wordsAreStrong": true
}
]
}
diff --git a/tests/data/PhabricatorPayloadAnalyzer/default.json b/tests/data/PhabricatorPayloadAnalyzer/default.json
index 71e3122..b5378d2 100644
--- a/tests/data/PhabricatorPayloadAnalyzer/default.json
+++ b/tests/data/PhabricatorPayloadAnalyzer/default.json
@@ -1,5 +1,5 @@
{
"administrativeGroup": "orgz",
"defaultGroup": "",
- "groupsMapping": []
+ "map": []
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Sep 18, 22:01 (3 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2991823
Default Alt Text
(48 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment