Page MenuHomeDevCentral

D636.id1589.diff
No OneTemporary

D636.id1589.diff

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,94 @@
+<?php
+
+namespace Nasqueron\Notifications\Jobs;
+
+use Nasqueron\Notifications\Actions\ActionError;
+use Nasqueron\Notifications\Actions\TriggerDockerHubBuildAction;
+use Nasqueron\Notifications\Events\ReportEvent;
+
+use Event;
+
+use Exception;
+
+/**
+ * This class allows to trigger a new Docker Hub build
+ */
+class TriggerDockerHubBuild extends Job {
+
+ ///
+ /// Private members
+ ///
+
+ /**
+ * @var string
+ */
+ 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 {
+ //Headers
+ $headers = [
+ 'Content-Type' => 'application/json',
+ ];
+
+ $data = [
+ 'build' => true,
+ ];
+
+ $urlToPost = "https://registry.hub.docker.com/u/{vendor}/{image}/trigger/{token}/";
+ } 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,15 @@
+<?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 {
+
+}

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 6, 21:17 (21 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2232307
Default Alt Text
D636.id1589.diff (2 KB)

Event Timeline