Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3716864
D636.id1597.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D636.id1597.diff
View Options
diff --git a/app/Jobs/NotifyNewCommitsToDockerHub.php b/app/Jobs/NotifyNewCommitsToDockerHub.php
new file mode 100644
--- /dev/null
+++ b/app/Jobs/NotifyNewCommitsToDockerHub.php
@@ -0,0 +1,89 @@
+<?php
+
+namespace Nasqueron\Notifications\Jobs;
+
+use Nasqueron\Notifications\Actions\ActionError;
+use Nasqueron\Notifications\Actions\TriggerDockerHubBuildAction;
+use Nasqueron\Notifications\Events\ReportEvent;
+
+use Keruald\DockerHub\DockerHubImage;
+
+use Event;
+
+use BadMethodCallException;
+use Exception;
+
+/**
+ * This class allows to trigger a new Docker Hub build.
+ */
+class TriggerDockerHubBuild extends Job {
+
+ ///
+ /// Private members
+ ///
+
+ /**
+ * @var string The Docker image to trigger a build for
+ */
+ private $image;
+
+ /**
+ * @var TriggerDockerHubBuildAction
+ */
+ private $actionToReport;
+
+ ///
+ /// Constructor
+ ///
+
+ /**
+ * Initializes a new instance of TriggerDockerHubBuild.
+ */
+ public function __construct ($image) {
+ $this->image = $image;
+ }
+
+ ///
+ /// Task
+ ///
+
+ /**
+ * Executes the job.
+ *
+ * @return void
+ */
+ public function handle () {
+ $this->initializeReport();
+ $this->triggerBuild();
+ $this->sendReport();
+ }
+
+ /**
+ * Initializes the actions report.
+ */
+ private function initializeReport () {
+ $this->actionToReport = new TriggerDockerHubBuildAction($this->image);
+ }
+
+ /**
+ * Triggers a new Docker Hub build.
+ */
+ private function triggerBuild () {
+ try {
+ $image = DockerHubImage::loadFromSlashNotation($this->image);
+ $image->triggerBuild();
+ } catch (Exception $ex) {
+ $actionError = new ActionError($ex);
+ $this->actionToReport->attachError($actionError);
+ }
+ }
+
+ /**
+ * Fires a report event with the actions report.
+ */
+ private function sendReport () {
+ $event = new ReportEvent($this->actionToReport);
+ Event::fire($event);
+ }
+
+}
diff --git a/app/Listeners/DockerHubListener.php b/app/Listeners/DockerHubListener.php
new file mode 100644
--- /dev/null
+++ b/app/Listeners/DockerHubListener.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace Nasqueron\Notifications\Listeners;
+
+use Nasqueron\Notifications\Events\GitHubPayloadEvent;
+use Nasqueron\Notifications\Jobs\NotifyNewCommitsToDockerHub;
+
+use Illuminate\Events\Dispatcher;
+
+/**
+ * Listens to events Docker Hub is interested by.
+ */
+class DockerHubListener {
+
+
+ ///
+ /// GitHub → Phabricator
+ ///
+
+ /**
+ * Handles payload events.
+ *
+ * @param GitHubPayloadEvent $event The GitHub payload event
+ */
+ public function onGitHubPayload (GitHubPayloadEvent $event) {
+ if ($event->event === 'push') {
+ $this->notifyNewCommits($event);
+ }
+ }
+
+ /**
+ * Notifies Phabricator there are new commits to pull.
+ *
+ * @param GitHubPayloadEvent $event The GitHub payload event
+ */
+ public function notifyNewCommits (GitHubPayloadEvent $event) {
+ $job = new NotifyNewCommitsToDockerHub(
+ $event->door,
+ $event->payload->repository->clone_url
+ );
+ $job->handle();
+ }
+
+ ///
+ /// Events listening
+ ///
+
+ /**
+ * Registers the listeners for the subscriber.
+ *
+ * @param Dispatcher $events
+ */
+ public function subscribe (Dispatcher $events) {
+ $class = PhabricatorListener::class;
+ $events->listen(
+ GitHubPayloadEvent::class,
+ "$class@onGitHubPayload"
+ );
+ }
+
+}
diff --git a/composer.json b/composer.json
--- a/composer.json
+++ b/composer.json
@@ -14,6 +14,7 @@
"laravel/framework": "5.2.*",
"keruald/github": "^0.2.0",
"keruald/broker": "^0.4.1",
+ "keruald/dockerhub": "dev-master",
"netresearch/jsonmapper": "~0.1.0",
"sentry/sentry": "^0.13.0"
},
diff --git a/config/app.php b/config/app.php
--- a/config/app.php
+++ b/config/app.php
@@ -193,6 +193,7 @@
'listeners' => [
Nasqueron\Notifications\Listeners\AMQPEventListener::class,
+ Nasqueron\Notifications\Listeners\DockerHubListener::class,
Nasqueron\Notifications\Listeners\LastPayloadSaver::class,
Nasqueron\Notifications\Listeners\NotificationListener::class,
Nasqueron\Notifications\Listeners\PhabricatorListener::class,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 6, 21:09 (20 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2232291
Default Alt Text
D636.id1597.diff (4 KB)
Attached To
Mode
D636: Trigger build to Docker Hub
Attached
Detach File
Event Timeline
Log In to Comment