Permalink
Browse files

Fix & cleanup Webhook

  • Loading branch information...
Thoulah committed Jun 19, 2018
1 parent f7afec2 commit 6a4dbc620c5e9df7ba75c22e3a94219a34dbcc8a
@@ -2,13 +2,13 @@
namespace app\controllers;
use Yii;
use app\commands\FeedController;
use yii\models\webhook\Github;
use app\models\webhook\Github;
use yii\web\{Response, NotFoundHttpException, UnauthorizedHttpException};
class WebhookController extends \yii\web\Controller {
public $enableCsrfValidation = false;
public function actionGithub() {
public function actionGithub(): array {
Yii::$app->response->format = Response::FORMAT_JSON;
list($algo, $hash) = explode('=', Yii::$app->request->headers->get('X-Hub-Signature', 'sha512=1'), 2);
if (!hash_equals($hash, hash_hmac($algo, file_get_contents('php://input'), Yii::$app->params['secrets']['github']['hook']))) :
@@ -20,16 +20,9 @@ public function actionGithub() {
case 'ping':
return ['status' => 'success', 'message' => 'Pong!'];
case 'push':
return $github->push(Yii::$app->request->post('payload'));
return $github->push();
default:
throw new NotFoundHttpException('Action not found.');
endswitch;
$payload = json_decode(Yii::$app->request->post('payload'));
$controller = new FeedController(Yii::$app->controller->id, Yii::$app);
$controller->limit = 5;
$controller->actionWebfeed('atom', 'Mr42Commits', "https://github.com/{$payload->repository->full_name}/commits/{$payload->repository->default_branch}.atom", 'content');
return ['status' => 'success', 'message' => 'Successfully updated.'];
}
}
@@ -1,9 +1,11 @@
<?php
namespace app\models\webhook;
use Yii;
use app\commands\FeedController;
class Github extends \yii\base\Model {
public function push(string $payload): array {
public function push(): array {
$payload = json_decode(Yii::$app->request->post('payload'));
$controller = new FeedController(Yii::$app->controller->id, Yii::$app);
$controller->limit = 5;
$controller->actionWebfeed('atom', 'Mr42Commits', "https://github.com/{$payload->repository->full_name}/commits/{$payload->repository->default_branch}.atom", 'content');
@@ -14,8 +14,8 @@
echo Html::a(
Html::img(['music/collection-cover', 'id' => $album->id], ['alt' => "{$album->artist} - {$album->year} - {$album->title}", 'class' => 'card-img-top rounded'])
, "https://www.discogs.com/release/{$album->id}");
echo Html::tag('div', Html::tag('small', $album->title, ['class' => 'card-text mt-auto font-weight-bold']), ['class' => 'card-body d-flex text-left']);
echo Html::tag('div', Html::tag('small', $album->artist), ['class' => 'card-footer text-left']);
echo Html::tag('div', Html::tag('small', $album->title, ['class' => 'card-text mt-auto font-weight-bold']), ['class' => 'card-body d-flex text-left p-2']);
echo Html::tag('div', Html::tag('small', $album->artist), ['class' => 'card-footer text-left p-2']);
echo Html::endTag('div');
endforeach;
echo Html::endTag('div');
@@ -4,4 +4,4 @@
$this->title = $name;
echo Html::tag('h1', $this->title);
echo Html::tag('div', nl2br($message), ['class' => 'alert alert-danger']);
echo Html::tag('div', nl2br($message, false), ['class' => 'alert alert-danger']);

0 comments on commit 6a4dbc6

Please sign in to comment.