Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F11724214
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/app/Analyzers/GitHub/Events/RepositoryEvent.php b/app/Analyzers/GitHub/Events/RepositoryEvent.php
index cc5f264..8c85b33 100644
--- a/app/Analyzers/GitHub/Events/RepositoryEvent.php
+++ b/app/Analyzers/GitHub/Events/RepositoryEvent.php
@@ -1,42 +1,65 @@
<?php
namespace Nasqueron\Notifications\Analyzers\GitHub\Events;
/**
* RepositoryEvent payload analyzer
*
* @link https://developer.github.com/v3/activity/events/types/#repositoryevent
*/
class RepositoryEvent extends Event {
+ /**
+ * Determines if the action is valid.
+ *
+ * @param string $type The action to check
+ * @return bool true if the action is valid; otherwise, false
+ */
+ protected static function isValidAction ($action) {
+ $actions = ['created', 'deleted', 'publicized', 'privatized'];
+ return in_array($action, $actions);
+ }
+
/**
* Gets description for the payload
*
* @return string
*/
public function getDescription () {
- $message = trans('GitHub.EventsDescriptions.RepositoryEvent', [
- 'repository' => $this->payload->repository->full_name,
- ]);
+ $action = $this->payload->action;
+
+ if (!static::isValidAction($action)) {
+ return trans(
+ 'GitHub.EventsDescriptions.RepositoryEventUnknown',
+ ['action' => $action]
+ );
+ }
+
+ $key = 'GitHub.EventsDescriptions.RepositoryEventPerAction.';
+ $key .= $action;
+
+ $repository = $this->payload->repository->full_name;
+
+ $message = trans($key, ['repository' => $repository]);
if ($this->payload->repository->fork) {
$message .= trans('GitHub.EventsDescriptions.RepositoryEventFork');
}
if ($description = $this->payload->repository->description) {
$message .= trans('GitHub.Separator');
$message .= $description;
}
return $message;
}
/**
* Gets link for the payload
*
* @return string
*/
public function getLink () {
return $this->payload->repository->html_url;
}
}
diff --git a/resources/lang/en/GitHub.php b/resources/lang/en/GitHub.php
index 9f79dbf..3d99c4b 100644
--- a/resources/lang/en/GitHub.php
+++ b/resources/lang/en/GitHub.php
@@ -1,57 +1,63 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| GitHub notifications messages
|--------------------------------------------------------------------------
|
| The following language lines are used to localize notifications for events
| fired by GitHub
|
*/
'Separator' => ' — ',
'Commits' => [
'Message' => ':committer committed :title',
'Authored' => ' (authored by :author)', // appended to Message
],
'RepoAndBranch' => ':repo (branch :branch)',
'EventsDescriptions' => [
'CommitCommentEvent' => ':author added a comment to :commit: :excerpt',
'CreateEvent' => 'New :type on :repository: :ref',
'CreateEventUnknown' => 'Unknown create reference: :type :ref',
'DeleteEvent' => 'Removed :type on :repository: :ref',
'DeleteEventUnknown' => 'Unknown delete reference: :type :ref',
'ForkEvent' => ':repo_base has been forked to :repo_fork',
'PingEvent' => '« :zen » — GitHub Webhooks ping zen aphorism.',
'PushEvent' => [
'0' => ':user forcely updated :repoAndBranch',
'n' => ':user pushed :count commits to :repoAndBranch', // n > 1
],
- 'RepositoryEvent' => 'New repository :repository',
+ 'RepositoryEventPerAction' => [
+ 'created' => 'New repository :repository',
+ 'deleted' => "Repository :repository deleted (danger zone)",
+ 'publicized' => "Repository :repository is now public",
+ 'privatized' => "Repository :repository is now private",
+ ],
'RepositoryEventFork' => ' (fork)',
+ 'RepositoryEventUnknown' => 'Unknown repository action: :action',
'StatusEvent' => 'Status of :commit: :status',
'WatchEvent' => ':user starred :repository',
],
'StatusEventState' => [
'pending' => 'pending',
'success' => 'success',
'failure' => 'failure',
'error' => 'error',
],
];
diff --git a/tests/Analyzers/GitHub/Events/RepositoryEventTest.php b/tests/Analyzers/GitHub/Events/RepositoryEventTest.php
index e748d62..5df7771 100644
--- a/tests/Analyzers/GitHub/Events/RepositoryEventTest.php
+++ b/tests/Analyzers/GitHub/Events/RepositoryEventTest.php
@@ -1,48 +1,72 @@
<?php
namespace Nasqueron\Notifications\Tests\Analyzers\GitHub\Events;
use Nasqueron\Notifications\Analyzers\GitHub\Events\RepositoryEvent;
use Nasqueron\Notifications\Tests\TestCase;
class RepositoryEventTest extends TestCase {
/**
* @var stdClass
*/
private $payload;
public function setUp () {
$filename = __DIR__ . "/../../../data/payloads/GitHubEvents/repository.json";
$this->payload = json_decode(file_get_contents($filename));
parent::setUp();
}
public function testWhenRepositoryIsForked () {
$payload = clone $this->payload;
$payload->repository->fork = true;
$event = new RepositoryEvent($payload);
$this->assertContains("fork", $event->getDescription());
}
public function testWhenRepositoryContainsDescription () {
$payload = clone $this->payload;
$payload->repository->description = "Lorem ipsum dolor";
$event = new RepositoryEvent($payload);
$this->assertContains("Lorem ipsum dolor", $event->getDescription());
}
public function testWhenRepositoryIsForkedAndContainsDescription () {
$payload = clone $this->payload;
$payload->repository->fork = true;
$payload->repository->description = "Lorem ipsum dolor";
$event = new RepositoryEvent($payload);
$this->assertContains("fork", $event->getDescription());
$this->assertContains("Lorem ipsum dolor", $event->getDescription());
}
+ /**
+ * @dataProvider payloadDescriptionProvider
+ */
+ public function testWhenRepositoryPerAction ($action, $description) {
+ $this->payload->action = $action;
+ $event = new RepositoryEvent($this->payload);
+ $this->assertSame($description, $event->getDescription());
+ }
+
+ /**
+ * Provides actions and descritions for testWhenRepositoryPerAction
+ *
+ * See https://developer.github.com/v3/activity/events/types/#repositoryevent
+ */
+ public function payloadDescriptionProvider () {
+ return [
+ ['created', "New repository baxterandthehackers/new-repository"],
+ ['deleted', "Repository baxterandthehackers/new-repository deleted (danger zone)"],
+ ['publicized', "Repository baxterandthehackers/new-repository is now public"],
+ ['privatized', "Repository baxterandthehackers/new-repository is now private"],
+ ['quuxed', "Unknown repository action: quuxed"],
+ ];
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Sep 18, 13:25 (15 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2990900
Default Alt Text
(7 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment