* Add parse webhook functions.
This commit is contained in:
@@ -17,7 +17,7 @@ $config->gitlab->bugLabel->description = "bug label from zentao";
|
||||
$config->gitlab->bugLabel->color = "#D10069";
|
||||
$config->gitlab->bugLabel->priority = "0";
|
||||
|
||||
$config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s&project=%s";
|
||||
$config->gitlab->zentaoApiWebhookUrl = "%s/api.php?m=gitlab&f=webhook&product=%s&gitlab=%s";
|
||||
$config->gitlab->zentaoApiWebhookToken = "<access token>";
|
||||
|
||||
|
||||
|
||||
@@ -204,6 +204,19 @@ class gitlab extends control
|
||||
$gitlab = $this->get->gitlab;
|
||||
$project = $this->get->project;
|
||||
|
||||
$requestBody = json_decode(file_get_contents('php://input'));
|
||||
$request = $this->gitlab->parseWebhookBody($requestBody);
|
||||
|
||||
switch($request->type)
|
||||
{
|
||||
case 'issue_create':
|
||||
$this->createTaskFromIssue($request);
|
||||
break;
|
||||
case 'issue_update':
|
||||
$this->updateTaskFromIssue($request);
|
||||
break;
|
||||
}
|
||||
|
||||
$logFile = $this->app->getLogRoot() . 'webhook.'. date('Ymd') . '.log.php';
|
||||
if(!file_exists($logFile)) file_put_contents($logFile, '<?php die(); ?' . '>');
|
||||
|
||||
@@ -211,8 +224,8 @@ class gitlab extends control
|
||||
if($fh)
|
||||
{
|
||||
fwrite($fh, date('Ymd H:i:s') . ": " . $this->app->getURI() . "\n");
|
||||
if(!empty($_POST)) fwrite($fh, "data: " . var_export($_POST, true) . "\n");
|
||||
//fwrite($fh, "results:" . print_r($response, true) . "\n");
|
||||
fwrite($fh, "GET: " . var_export($_GET, true) . "\n");
|
||||
fwrite($fh, "Body: " . var_export($requestBody, true) . "\n");
|
||||
if(!empty($errors)) fwrite($fh, "errors: " . $errors . "\n");
|
||||
fclose($fh);
|
||||
}
|
||||
|
||||
@@ -522,4 +522,22 @@ class gitlabModel extends model
|
||||
$response = $this->apiCreateIssue($gitlabID, $projectID, $bug);
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function parseWebhookBody($body)
|
||||
{
|
||||
$type = zget($body, 'object_kind', '');
|
||||
if(!$type or !is_callable(array($this, "parse{$type}Webhook"))) return false;
|
||||
return call_user_func_array(array($this, "parse{$type}Webhook"), array('body' => $body));
|
||||
}
|
||||
|
||||
public function parseIssueWebhook($body)
|
||||
{
|
||||
$request = new stdclass;
|
||||
$request->type = $body->object_kind;
|
||||
$issue = $body->object_attributes;
|
||||
|
||||
$request->labels = $body->labels;
|
||||
$request->project = $body->project->id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user