From af974c9c8a480fa3975287839f134b0ee1721b50 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Wed, 13 Mar 2024 14:19:42 +0800 Subject: [PATCH] + Add webhook api for gitfox. --- api/v1/entries/gitfoxwebhook.php | 38 ++++++++++++++++++++++++++++++++ api/v1/entries/gitlabwebhook.php | 6 ++--- config/routes.php | 1 + 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 api/v1/entries/gitfoxwebhook.php diff --git a/api/v1/entries/gitfoxwebhook.php b/api/v1/entries/gitfoxwebhook.php new file mode 100644 index 0000000000..7e894ceebe --- /dev/null +++ b/api/v1/entries/gitfoxwebhook.php @@ -0,0 +1,38 @@ + + * @package repo + * @version 1 + * @link https://www.zentao.net + */ +class gitfoxWebhookEntry extends baseEntry +{ + + /** + * Repo webhook. + * + * @access public + * @return string + */ + public function post() + { + $headers = getallheaders(); /* Fetch all HTTP request headers. */ + $event = isset($headers['X-Gitness-Trigger']) ? $headers['X-Gitness-Trigger'] : ''; + if(empty($event)) return; + + $repoID = $this->param('repoID'); + if(empty($repoID)) return; + + $this->app->user = new stdclass(); + $this->app->user->account = ''; + $this->app->user->admin = false; + $repo = $this->loadModel('repo')->getByID($repoID); + if(empty($repo)) return; + + $this->repo->handleWebhook($event, $this->requestBody, $repo); + } +} diff --git a/api/v1/entries/gitlabwebhook.php b/api/v1/entries/gitlabwebhook.php index 48f1496207..3c78009de5 100644 --- a/api/v1/entries/gitlabwebhook.php +++ b/api/v1/entries/gitlabwebhook.php @@ -27,12 +27,12 @@ class gitlabWebhookEntry extends baseEntry $repoID = $this->param('repoID'); if(empty($repoID)) return; - $repo = $this->loadModel('repo')->getByID($repoID); - if(empty($repo)) return; - $this->app->user = new stdclass(); $this->app->user->account = ''; $this->app->user->admin = false; + $repo = $this->loadModel('repo')->getByID($repoID); + if(empty($repo)) return; + $this->repo->handleWebhook($event, $this->requestBody, $repo); } } diff --git a/config/routes.php b/config/routes.php index a0cece5526..123603ad1a 100644 --- a/config/routes.php +++ b/config/routes.php @@ -178,6 +178,7 @@ $routes['/z/files/:id'] = 'zfile'; $routes['/z/files/:id/content'] = 'zfileContent'; $routes['/gitlab/webhook'] = 'gitlabWebhook'; +$routes['/gitfox/webhook'] = 'gitfoxWebhook'; $routes['/ciresults'] = 'ciresults';