From 36cb1b7c7a30c0abc7cd2964d3f0a59fad7f7530 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Tue, 15 Jun 2021 11:08:09 +0800 Subject: [PATCH] * Add funcs for getting gitlab api url with access_token. --- module/gitlab/model.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 4b242e23ce..48a39a7626 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -10,6 +10,11 @@ * @link http://www.zentao.net */ + +/* enable JMESPath */ +require __DIR__ . '/../../vendor/autoload.php'; + + class gitlabModel extends model { /** @@ -155,5 +160,31 @@ class gitlabModel extends model $allResults = $allResults + $results; } return $allResults; - } + } + + + /** + * Get gitlab api base url with access_token + * + * @param int $id + * @access public + * @return string gitlab api base url with access_token + */ + public function getGitlabBaseApiUrl($id) + { + $gitlab = $this->getByID($id); + if(!$gitlab) return array(); + $gitlab_url = rtrim($gitlab->url, '/').'/api/v4%s'."?private_token={$gitlab->token}"; + return $gitlab_url; + } + + + public function getHooksOfProject($gitlab_id, $project_id) + { + $host = $this->getGitlabBaseApiUrl($gitlab_id); + $api_path = sprintf('/projects/%s/hooks', $project_id); + $host = sprintf($host, $api_path); + $api_json = commonModel::http($host); + return $api_json; + } }