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,87 @@ +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 { + DockerHub::build($this->image); + } 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 @@ +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/config/app.php b/config/app.php --- a/config/app.php +++ b/config/app.php @@ -195,6 +195,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,