* Optimize codes related to handle GitLab webhook and others.

This commit is contained in:
dingguodong
2021-11-11 19:16:05 +08:00
parent acb23a5053
commit 24966356bc
4 changed files with 14 additions and 22 deletions
+5 -5
View File
@@ -20,20 +20,20 @@ class repoEntry extends baseEntry
*/
public function post()
{
$id= $this->param('id');
$repoID= $this->param('repoID');
if(empty($id)) return;
$model = $this->loadModel('repo');
$this->loadModel('repo');
$repo = $model->getRepoByID($id);
$repo = $this->repo->getRepoByID($repoID);
if(empty($repo)) return;
$headers = getallheaders();
$headers = getallheaders(); /* Fetch all HTTP request headers. */
$event = isset($headers['X-Gitlab-Event']) ? $headers['X-Gitlab-Event'] : '';
$token = isset($headers['X-Gitlab-Token']) ? $headers['X-Gitlab-Token'] : '';
if(empty($event) || empty($token)) return;
$model->handleWebhook($event, $token, $this->requestBody, $repo);
$this->repo->handleWebhook($event, $token, $this->requestBody, $repo);
}
}
+1 -1
View File
@@ -146,7 +146,7 @@ class gitModel extends model
}
$version = (int)$lastInDB->commit + 1;
$logs = $this->repo->getUnsyncCommits($repo);
$logs = $this->repo->getUnsyncedCommits($repo);
$objects = array();
if(!empty($logs))
{
+7 -15
View File
@@ -1,8 +1,6 @@
<?php
class repoModel extends model
{
const HOOK_PUSH_EVENT = 'Push Hook';
/**
* Check repo priv.
*
@@ -772,7 +770,7 @@ class repoModel extends model
* @access public
* @return array
*/
public function getUnsyncCommits($repo)
public function getUnsyncedCommits($repo)
{
$repoID = $repo->id;
$lastInDB = $this->getLatestCommit($repoID);
@@ -1795,8 +1793,8 @@ class repoModel extends model
->fetchAll();
}
/**
* Handle gitlab webhook.
/**
* Handle received GitLab webhook.
*
* @param string $event
* @param string $token
@@ -1807,17 +1805,11 @@ class repoModel extends model
*/
public function handleWebhook($event, $token, $data, $repo)
{
/* Check gitlab token */
switch($event)
if($event == 'Push Hook' or $event == 'Merge Request Hook')
{
case static::HOOK_PUSH_EVENT:
unset($repo->acl);
unset($repo->desc);
/* Update code commit history. */
$commentGroup = $this->loadModel('job')->getTriggerGroup('commit', array($repo->id));
$this->loadModel('git')->updateCommit($repo, $commentGroup, false);
break;
/* Update code commit history. */
$commentGroup = $this->loadModel('job')->getTriggerGroup('commit', array($repo->id));
$this->loadModel('git')->updateCommit($repo, $commentGroup, false);
}
}
}
+1 -1
View File
@@ -135,7 +135,7 @@ class svnModel extends model
}
$version = (int)$lastInDB->commit + 1;
$logs = $this->repo->getUnsyncCommits($repo);
$logs = $this->repo->getUnsyncedCommits($repo);
/* Update code commit history. */
$objects = array();