finish webhook.

This commit is contained in:
xiawenlong
2021-11-12 09:48:11 +08:00
parent 24966356bc
commit c004b06e1e
8 changed files with 106 additions and 39 deletions
+30
View File
@@ -639,6 +639,36 @@ class gitlab extends control
$this->display();
}
/**
* Create Webhook by repoID.
*
* @param int $repoID
* @param string $confirm
* @access public
* @return void
*/
public function createWebhook($repoID, $confirm = 'no')
{
if($confirm == 'no')
{
die(js::confirm($this->lang->gitlab->confirmAddWebhook, $this->createLink('gitlab', 'createWebhook', "repoID=$repoID&confirm=yes")));
}
else
{
$repo = $this->loadModel('repo')->getRepoByID($repoID);
$res = $this->gitlab->addPushWebhook($repo);
if(!$res)
{
die(js::error($this->lang->gitlab->failCreateWebhook));
}
else
{
die(js::locate($this->createLink('repo', 'maintain'), 'parent'));
}
}
}
/**
* AJAX: Get executions by productID.
*
+20 -18
View File
@@ -1,22 +1,24 @@
<?php
$lang->gitlab = new stdclass;
$lang->gitlab->common = 'GitLab';
$lang->gitlab->browse = 'GitLab Browse';
$lang->gitlab->create = 'Create GitLab';
$lang->gitlab->edit = 'Edit GitLab';
$lang->gitlab->view = 'View GitLab';
$lang->gitlab->bindUser = 'Bind User';
$lang->gitlab->webhook = 'webhook';
$lang->gitlab->bindProduct = 'Import Product';
$lang->gitlab->importIssue = 'Import Issue';
$lang->gitlab->delete = 'Delete GitLab';
$lang->gitlab->confirmDelete = 'Do you want to delete this GitLab server?';
$lang->gitlab->gitlabAccount = 'GitLab Account';
$lang->gitlab->zentaoAccount = 'Zentao Account';
$lang->gitlab->bindingStatus = 'Binding Status';
$lang->gitlab->binded = 'Binded';
$lang->gitlab->serverFail = 'Connect to GitLab server failed, please check the GitLab server.';
$lang->gitlab->lastUpdate = 'Last Update';
$lang->gitlab->common = 'GitLab';
$lang->gitlab->browse = 'GitLab Browse';
$lang->gitlab->create = 'Create GitLab';
$lang->gitlab->edit = 'Edit GitLab';
$lang->gitlab->view = 'View GitLab';
$lang->gitlab->bindUser = 'Bind User';
$lang->gitlab->webhook = 'webhook';
$lang->gitlab->bindProduct = 'Import Product';
$lang->gitlab->importIssue = 'Import Issue';
$lang->gitlab->delete = 'Delete GitLab';
$lang->gitlab->confirmDelete = 'Do you want to delete this GitLab server?';
$lang->gitlab->gitlabAccount = 'GitLab Account';
$lang->gitlab->zentaoAccount = 'Zentao Account';
$lang->gitlab->bindingStatus = 'Binding Status';
$lang->gitlab->binded = 'Binded';
$lang->gitlab->serverFail = 'Connect to GitLab server failed, please check the GitLab server.';
$lang->gitlab->lastUpdate = 'Last Update';
$lang->gitlab->confirmAddWebhook = 'Are you sure about creating Webhook?';
$lang->gitlab->failCreateWebhook = 'Failed to create Webhook, please view the log';
$lang->gitlab->browseAction = 'GitLab List';
$lang->gitlab->deleteAction = 'Delete GitLab';
@@ -128,4 +130,4 @@ $lang->gitlab->group->edit = "Edit Group";
$lang->gitlab->group->createOn = "Created on";
$lang->gitlab->group->members = "Group Members";
$lang->gitlab->group->confirmDelete = 'Do you want to delete this GitLab group?';
$lang->gitlab->group->emptyError = "cannot be empty";
$lang->gitlab->group->emptyError = "cannot be empty";
+20 -18
View File
@@ -1,22 +1,24 @@
<?php
$lang->gitlab = new stdclass;
$lang->gitlab->common = 'GitLab';
$lang->gitlab->browse = '浏览GitLab';
$lang->gitlab->create = '添加GitLab';
$lang->gitlab->edit = '编辑GitLab';
$lang->gitlab->view = '查看GitLab';
$lang->gitlab->bindUser = '绑定用户';
$lang->gitlab->webhook = 'webhook';
$lang->gitlab->bindProduct = '关联产品';
$lang->gitlab->importIssue = '关联issue';
$lang->gitlab->delete = '删除GitLab';
$lang->gitlab->confirmDelete = '确认删除该GitLab吗?';
$lang->gitlab->gitlabAccount = 'GitLab用户';
$lang->gitlab->zentaoAccount = '禅道用户';
$lang->gitlab->bindingStatus = '绑定状态';
$lang->gitlab->binded = '已绑定';
$lang->gitlab->serverFail = '连接GitLab服务器异常,请检查GitLab服务器。';
$lang->gitlab->lastUpdate = '最后更新';
$lang->gitlab->common = 'GitLab';
$lang->gitlab->browse = '浏览GitLab';
$lang->gitlab->create = '添加GitLab';
$lang->gitlab->edit = '编辑GitLab';
$lang->gitlab->view = '查看GitLab';
$lang->gitlab->bindUser = '绑定用户';
$lang->gitlab->webhook = 'webhook';
$lang->gitlab->bindProduct = '关联产品';
$lang->gitlab->importIssue = '关联issue';
$lang->gitlab->delete = '删除GitLab';
$lang->gitlab->confirmDelete = '确认删除该GitLab吗?';
$lang->gitlab->gitlabAccount = 'GitLab用户';
$lang->gitlab->zentaoAccount = '禅道用户';
$lang->gitlab->bindingStatus = '绑定状态';
$lang->gitlab->binded = '已绑定';
$lang->gitlab->serverFail = '连接GitLab服务器异常,请检查GitLab服务器。';
$lang->gitlab->lastUpdate = '最后更新';
$lang->gitlab->confirmAddWebhook = '您确定创建Webhook吗?';
$lang->gitlab->failCreateWebhook = 'Webhook创建失败,请查看日志';
$lang->gitlab->browseAction = 'GitLab列表';
$lang->gitlab->deleteAction = '删除GitLab';
@@ -128,4 +130,4 @@ $lang->gitlab->group->edit = "编辑群组";
$lang->gitlab->group->createOn = "创建于";
$lang->gitlab->group->members = "群组成员";
$lang->gitlab->group->confirmDelete = '确认删除该GitLab群组吗?';
$lang->gitlab->group->emptyError = "不能为空";
$lang->gitlab->group->emptyError = "不能为空";
+22 -1
View File
@@ -859,7 +859,7 @@ class gitlabModel extends model
* @param object $hook
* @access public
* @docs https://docs.gitlab.com/ee/api/projects.html#add-project-hook
* @return object
* @return string
*/
public function apiCreateHook($gitlabID, $projectID, $hook)
{
@@ -893,6 +893,27 @@ class gitlabModel extends model
return commonModel::http($url, null, array(CURLOPT_CUSTOMREQUEST => 'delete'));
}
/**
* Add push web hook
*
* @param object $repo`
* @access public
* @return void
*/
public function addPushWebhook($repo)
{
$hook = new stdClass;
$hook->id = $repo->path;
$hook->url = common::getSysURL() . '/api.php/v1/gitlab/webhook?repoID='. $repo->id;
$hook->push_events = true;
$hook->merge_requests_events = true;
$res = $this->apiCreateHook($repo->gitlab, $repo->extra, $hook);
$data = json_decode($res, true);
if(!empty($data['id'])) return true;
return false;
}
/**
* Update hook by api.
*
+1
View File
@@ -23,6 +23,7 @@ $lang->repo->encrypt = 'Encrypt';
$lang->repo->repo = 'Repository';
$lang->repo->parent = 'Parent File';
$lang->repo->branch = 'Branch';
$lang->repo->addWebHook = 'Add Webhook';
$lang->repo->browseAction = 'Browse Repo';
$lang->repo->createAction = 'Create Repo';
+1
View File
@@ -23,6 +23,7 @@ $lang->repo->encrypt = '加密方式';
$lang->repo->repo = '代码库';
$lang->repo->parent = '父文件夹';
$lang->repo->branch = '分支';
$lang->repo->addWebHook = '添加Webhook';
$lang->repo->browseAction = '浏览版本库';
$lang->repo->createAction = '创建版本库';
+10 -1
View File
@@ -232,7 +232,16 @@ class repoModel extends model
if(!dao::isError()) $this->rmClientVersionFile();
return $this->dao->lastInsertID();
$repoID = $this->dao->lastInsertID();
if($this->post->SCM == 'Gitlab')
{
/* Add webhook. */
$repo = $this->getRepoByID($repoID);
$this->loadModel('gitlab')->addPushWebhook($repo);
}
return $repoID;
}
/**
+2 -1
View File
@@ -27,7 +27,7 @@
<th class='c-name text-left'><?php common::printOrderLink('name', $orderBy, $vars, $lang->repo->name); ?></th>
<th class='c-product text-left'><?php common::printOrderLink('product', $orderBy, $vars, $lang->repo->product); ?></th>
<th class='text-left'><?php echo $lang->repo->path; ?></th>
<th class='c-actions-3'><?php echo $lang->actions; ?></th>
<th class='c-actions-3 w-120px'><?php echo $lang->actions; ?></th>
</tr>
</thead>
<tbody>
@@ -53,6 +53,7 @@
<td class='text-left c-actions'>
<?php
common::printIcon('repo', 'edit', "repoID=$repo->id&objectID=$objectID", '', 'list', 'edit');
echo html::a($this->createLink('gitlab', 'createWebhook', "repoID=$repo->id"), '<i class="icon-change"></i>', 'hiddenwin', "title='{$lang->repo->addWebHook}'");
if(strtolower($repo->SCM) == "gitlab") common::printIcon('gitlab', 'importIssue', "repo={$repo->id}", '', 'list', 'link');
if(common::hasPriv('repo', 'delete')) echo html::a($this->createLink('repo', 'delete', "repoID=$repo->id&objectID=$objectID"), '<i class="icon-trash"></i>', 'hiddenwin', "title='{$lang->repo->delete}' class='btn'");
?>