Page MenuHomeDevCentral

D627.id1551.diff
No OneTemporary

D627.id1551.diff

diff --git a/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php b/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php
--- a/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php
+++ b/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php
@@ -158,7 +158,7 @@
// symbols, we need to sort it to the right group.
$repository = $this->getRepository();
foreach ($this->configuration->repositoryMapping as $mapping) {
- if ($mapping->doesRepositoryBelong($repository)) {
+ if ($mapping->doesItemBelong($repository)) {
return $mapping->group;
}
}
diff --git a/app/Analyzers/GitHub/GitHubPayloadAnalyzerConfiguration.php b/app/Analyzers/GitHub/GitHubPayloadAnalyzerConfiguration.php
--- a/app/Analyzers/GitHub/GitHubPayloadAnalyzerConfiguration.php
+++ b/app/Analyzers/GitHub/GitHubPayloadAnalyzerConfiguration.php
@@ -36,7 +36,7 @@
/**
* An array of RepositoryGroupMapping objects to match repositories & groups
*
- * @var RepositoryGroupMapping[]
+ * @var \Nasqueron\Notifications\Analyzers\ItemGroupMapping[]
*/
public $repositoryMapping;
diff --git a/app/Analyzers/GitHub/RepositoryGroupMapping.php b/app/Analyzers/GitHub/RepositoryGroupMapping.php
deleted file mode 100644
--- a/app/Analyzers/GitHub/RepositoryGroupMapping.php
+++ /dev/null
@@ -1,53 +0,0 @@
-<?php
-
-namespace Nasqueron\Notifications\Analyzers\GitHub;
-
-class RepositoryGroupMapping {
- ///
- /// Properties
- ///
-
- /**
- * The group the mapped repositories belong to
- *
- * @var string
- */
- public $group;
-
- /**
- * An array of the repositories, each item a string with the name of the
- * repository. The wildcard '*' is allowed to specify several repositories.
- *
- * @var array
- */
- public $repositories;
-
- ///
- /// Helper methods
- ///
-
- /**
- * Determines if the specified repository matches a pattern
- *
- * @param string $pattern The pattern, with * allowed as wildcard character
- * @param string $repository The repository name to compare with the pattern
- * @return bool
- */
- public static function doesRepositoryMatch ($pattern, $repository) {
- return str_is($pattern, $repository);
- }
-
- /**
- * Determines if the specified repository belong to this mapping
- *
- * @return bool
- */
- public function doesRepositoryBelong ($actualRepository) {
- foreach ($this->repositories as $candidateRepository) {
- if (static::doesRepositoryMatch($candidateRepository, $actualRepository)) {
- return true;
- }
- }
- return false;
- }
-}
diff --git a/app/Analyzers/ItemGroupMapping.php b/app/Analyzers/ItemGroupMapping.php
new file mode 100644
--- /dev/null
+++ b/app/Analyzers/ItemGroupMapping.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace Nasqueron\Notifications\Analyzers;
+
+/**
+ * Map items (repositories, projects, items, etc.) names to groups
+ */
+class ItemGroupMapping {
+
+ ///
+ /// Properties
+ ///
+
+ /**
+ * The group the mapped items belong to
+ *
+ * @var string
+ */
+ public $group;
+
+ /**
+ * An array of the items to map, each item a string with the name of the
+ * repository, project or item used for mapping.
+ * The wildcard '*' is allowed to specify several items.
+ *
+ * @var array
+ */
+ public $items;
+
+ ///
+ /// Helper methods
+ ///
+
+ /**
+ * Determines if the specified item matches a pattern.
+ *
+ * @param string $pattern The pattern, with * allowed as wildcard character
+ * @param string $item The item name to compare with the pattern
+ * @return bool
+ */
+ public static function doesItemMatch ($pattern, $item) {
+ return str_is($pattern, $item);
+ }
+
+ /**
+ * Determines if the specified item belong to this mapping
+ *
+ * @return bool
+ */
+ public function doesItemBelong ($actualItem) {
+ foreach ($this->items as $candidateItem) {
+ if (static::doesItemMatch($candidateItem, $actualItem)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+}
diff --git a/app/Analyzers/Phabricator/PhabricatorGroupMapping.php b/app/Analyzers/Phabricator/PhabricatorGroupMapping.php
--- a/app/Analyzers/Phabricator/PhabricatorGroupMapping.php
+++ b/app/Analyzers/Phabricator/PhabricatorGroupMapping.php
@@ -2,29 +2,16 @@
namespace Nasqueron\Notifications\Analyzers\Phabricator;
+use Nasqueron\Notifications\Analyzers\ItemGroupMapping;
use Nasqueron\Notifications\Phabricator\PhabricatorStory;
-class PhabricatorGroupMapping {
+class PhabricatorGroupMapping extends ItemGroupMapping {
+
///
- /// Properties
+ /// Extra 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
@@ -32,35 +19,10 @@
public $words = [];
///
- /// Helper methods
+ /// Helper methods to process words
///
/**
- * 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
@@ -73,4 +35,5 @@
}
return false;
}
+
}
diff --git a/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php
--- a/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php
+++ b/app/Analyzers/Phabricator/PhabricatorPayloadAnalyzer.php
@@ -8,7 +8,7 @@
use Storage;
class PhabricatorPayloadAnalyzer {
-
+
///
/// Private members
///
@@ -115,7 +115,7 @@
// 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)) {
+ if ($mapping->doesItemBelong($project)) {
return $mapping->group;
}
}
diff --git a/tests/Analyzers/GitHub/GitHubPayloadAnalyzerConfigurationTest.php b/tests/Analyzers/GitHub/GitHubPayloadAnalyzerConfigurationTest.php
--- a/tests/Analyzers/GitHub/GitHubPayloadAnalyzerConfigurationTest.php
+++ b/tests/Analyzers/GitHub/GitHubPayloadAnalyzerConfigurationTest.php
@@ -5,6 +5,7 @@
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzerConfiguration;
+use Nasqueron\Notifications\Analyzers\ItemGroupMapping;
use Nasqueron\Notifications\Tests\TestCase;
class GitHubPayloadAnalyzerConfigurationTest extends TestCase {
@@ -38,10 +39,7 @@
$this->assertSame("nasqueron", $this->configuration->defaultGroup);
foreach ($this->configuration->repositoryMapping as $item) {
- $this->assertInstanceOf(
- 'Nasqueron\Notifications\Analyzers\GitHub\RepositoryGroupMapping',
- $item
- );
+ $this->assertInstanceOf(ItemGroupMapping::class, $item);
}
}
diff --git a/tests/Analyzers/GitHub/RepositoryGroupMappingTest.php b/tests/Analyzers/ItemGroupMappingTest.php
rename from tests/Analyzers/GitHub/RepositoryGroupMappingTest.php
rename to tests/Analyzers/ItemGroupMappingTest.php
--- a/tests/Analyzers/GitHub/RepositoryGroupMappingTest.php
+++ b/tests/Analyzers/ItemGroupMappingTest.php
@@ -4,42 +4,42 @@
use Illuminate\Foundation\Testing\WithoutMiddleware;
-use Nasqueron\Notifications\Analyzers\GitHub\RepositoryGroupMapping;
+use Nasqueron\Notifications\Analyzers\ItemGroupMapping;
use Nasqueron\Notifications\Tests\TestCase;
-class RepositoryGroupMappingTest extends TestCase {
+class ItemGroupMappingTest extends TestCase {
- public function testDoesRepositoryMatch () {
+ public function testDoesItemMatch () {
$this->assertTrue(
- RepositoryGroupMapping::doesRepositoryMatch(
+ ItemGroupMapping::doesItemMatch(
'quux*',
'quuxians'
)
);
$this->assertTrue(
- RepositoryGroupMapping::doesRepositoryMatch(
+ ItemGroupMapping::doesItemMatch(
'quux*',
'quux'
)
);
$this->assertFalse(
- RepositoryGroupMapping::doesRepositoryMatch(
+ ItemGroupMapping::doesItemMatch(
'foobar',
'quux'
)
);
$this->assertFalse(
- RepositoryGroupMapping::doesRepositoryMatch(
+ ItemGroupMapping::doesItemMatch(
'',
'quuxians'
)
);
$this->assertFalse(
- RepositoryGroupMapping::doesRepositoryMatch(
+ ItemGroupMapping::doesItemMatch(
'quux*',
''
)
diff --git a/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php b/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php
--- a/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php
+++ b/tests/Analyzers/Phabricator/PhabricatorGroupMappingTest.php
@@ -39,63 +39,26 @@
/// Tests
///
- public function testDoesProjectMatch () {
- $this->assertTrue(
- PhabricatorGroupMapping::doesProjectMatch(
- 'quux*',
- 'quuxians'
- )
- );
-
- $this->assertTrue(
- PhabricatorGroupMapping::doesProjectMatch(
- 'quux*',
- 'quux'
- )
- );
-
- $this->assertFalse(
- PhabricatorGroupMapping::doesProjectMatch(
- 'foobar',
- 'quux'
- )
- );
-
- $this->assertFalse(
- PhabricatorGroupMapping::doesProjectMatch(
- '',
- 'quuxians'
- )
- );
-
- $this->assertFalse(
- PhabricatorGroupMapping::doesProjectMatch(
- 'quux*',
- ''
- )
- );
- }
-
public function testDoesProjectBelong () {
$mapping = $this->mappings['projects'];
$this->assertFalse(
- $mapping->doesProjectBelong("")
+ $mapping->doesItemBelong("")
);
$this->assertFalse(
- $mapping->doesProjectBelong("Tasacora")
+ $mapping->doesItemBelong("Tasacora")
);
$this->assertTrue(
- $mapping->doesProjectBelong("Docker images")
+ $mapping->doesItemBelong("Docker images")
);
$this->assertFalse(
- $mapping->doesProjectBelong("Docker")
+ $mapping->doesItemBelong("Docker")
);
$this->assertFalse(
- $mapping->doesProjectBelong("Docker images quux")
+ $mapping->doesItemBelong("Docker images quux")
);
}
diff --git a/tests/data/GitHubPayloadAnalyzer/Nasqueron.json b/tests/data/GitHubPayloadAnalyzer/Nasqueron.json
--- a/tests/data/GitHubPayloadAnalyzer/Nasqueron.json
+++ b/tests/data/GitHubPayloadAnalyzer/Nasqueron.json
@@ -4,19 +4,19 @@
"repositoryMapping": [
{
"group": "docker",
- "repositories": [
+ "items": [
"docker-*"
]
},
{
"group": "tasacora",
- "repositories": [
+ "items": [
"tasacora-*"
]
},
{
"group": "ops",
- "repositories": [
+ "items": [
"decommission",
"discourse-config",
"ftp",
diff --git a/tests/data/PhabricatorPayloadAnalyzer/Nasqueron.json b/tests/data/PhabricatorPayloadAnalyzer/Nasqueron.json
--- a/tests/data/PhabricatorPayloadAnalyzer/Nasqueron.json
+++ b/tests/data/PhabricatorPayloadAnalyzer/Nasqueron.json
@@ -4,14 +4,14 @@
"groupsMapping": [
{
"group": "docker",
- "projects": [
+ "items": [
"Docker images",
"Nasqueron Docker deployment squad"
]
},
{
"group": "tasacora",
- "projects":[
+ "items":[
"Tasacora"
],
"words": [
@@ -21,7 +21,7 @@
},
{
"group": "ops",
- "projects": [
+ "items": [
"Continous integration and delivery",
"IPv6",
"Mail",

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 03:39 (56 m, 51 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2258512
Default Alt Text
D627.id1551.diff (13 KB)

Event Timeline