Page MenuHomeDevCentral

D571.diff
No OneTemporary

D571.diff

diff --git a/app/Analyzers/GitHub/Events/RepositoryEvent.php b/app/Analyzers/GitHub/Events/RepositoryEvent.php
--- a/app/Analyzers/GitHub/Events/RepositoryEvent.php
+++ b/app/Analyzers/GitHub/Events/RepositoryEvent.php
@@ -10,14 +10,37 @@
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');
diff --git a/resources/lang/en/GitHub.php b/resources/lang/en/GitHub.php
--- a/resources/lang/en/GitHub.php
+++ b/resources/lang/en/GitHub.php
@@ -39,8 +39,14 @@
'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',
diff --git a/tests/Analyzers/GitHub/Events/RepositoryEventTest.php b/tests/Analyzers/GitHub/Events/RepositoryEventTest.php
--- a/tests/Analyzers/GitHub/Events/RepositoryEventTest.php
+++ b/tests/Analyzers/GitHub/Events/RepositoryEventTest.php
@@ -45,4 +45,28 @@
$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

Mime Type
text/plain
Expires
Sat, Dec 21, 21:54 (19 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2309896
Default Alt Text
D571.diff (3 KB)

Event Timeline