Merge branch 'devops17_caoyanyi_tag' into 'devops17'
Devops17 caoyanyi tag See merge request easycorp/zentaopms!1005
This commit is contained in:
@@ -123,6 +123,7 @@ $lang->action->objectTypes['gitlabuser'] = 'GitLab User';
|
||||
$lang->action->objectTypes['gitlabgroup'] = 'GitLab Group';
|
||||
$lang->action->objectTypes['gitlabbranch'] = 'GitLab Branch';
|
||||
$lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab Protected Branches';
|
||||
$lang->action->objectTypes['gitlabtag'] = 'GitLab Tag';
|
||||
|
||||
/* Used to describe operation history. */
|
||||
$lang->action->desc = new stdclass();
|
||||
|
||||
@@ -123,6 +123,7 @@ $lang->action->objectTypes['gitlabuser'] = 'GitLab用户';
|
||||
$lang->action->objectTypes['gitlabgroup'] = 'GitLab群组';
|
||||
$lang->action->objectTypes['gitlabbranch'] = 'GitLab分支';
|
||||
$lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab保护分支';
|
||||
$lang->action->objectTypes['gitlabtag'] = 'GitLab标签';
|
||||
|
||||
/* 用来描述操作历史记录。*/
|
||||
$lang->action->desc = new stdclass();
|
||||
|
||||
@@ -11,6 +11,9 @@ $config->gitlab->createbranch->requiredFields = 'branch,ref';
|
||||
$config->gitlab->createbranchpriv = new stdclass;
|
||||
$config->gitlab->createbranchpriv->requiredFields = 'name';
|
||||
|
||||
$config->gitlab->createtag = new stdclass;
|
||||
$config->gitlab->createtag->requiredFields = 'tag_name,ref';
|
||||
|
||||
$config->gitlab->labelPattern = new stdclass;
|
||||
$config->gitlab->labelPattern->task = '/^zentao_task\/\d+$/';
|
||||
$config->gitlab->labelPattern->bug = '/^zentao_bug\/\d+$/';
|
||||
|
||||
@@ -858,7 +858,6 @@ class gitlab extends control
|
||||
$branchPriv->mergeAccessLevel = 40; // Initialize data, and the operation authority is the maintainers by default.
|
||||
$branchPriv->pushAccessLevel = 40; // Initialize data, and the operation authority is the maintainers by default.
|
||||
|
||||
$gitlab = $this->gitlab->getByID($gitlabID);
|
||||
$title = $this->lang->gitlab->createBranchPriv;
|
||||
|
||||
if($branch)
|
||||
@@ -881,7 +880,6 @@ class gitlab extends control
|
||||
|
||||
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $title;
|
||||
$this->view->pageTitle = $title;
|
||||
$this->view->gitlab = $gitlab;
|
||||
$this->view->gitlabID = $gitlabID;
|
||||
$this->view->branch = $branch;
|
||||
$this->view->projectID = $projectID;
|
||||
@@ -1281,4 +1279,36 @@ class gitlab extends control
|
||||
}
|
||||
$this->send($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a gitlab tag.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $projectID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function createTag($gitlabID, $projectID)
|
||||
{
|
||||
if($_POST)
|
||||
{
|
||||
$this->gitlab->createTag($gitlabID, $projectID);
|
||||
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseTag', "gitlabID=$gitlabID&projectID=$projectID")));
|
||||
}
|
||||
|
||||
$gitlabBranches = $this->gitlab->apiGetBranches($gitlabID, $projectID);
|
||||
$branches = array();
|
||||
foreach($gitlabBranches as $branch)
|
||||
{
|
||||
$branches[$branch->name] = $branch->name;
|
||||
}
|
||||
|
||||
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->createTag;
|
||||
$this->view->gitlabID = $gitlabID;
|
||||
$this->view->projectID = $projectID;
|
||||
$this->view->branches = $branches;
|
||||
$this->display();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
.table-form>tbody>tr>th {width: 110px;}
|
||||
.table-form {width: 50%;}
|
||||
@@ -51,6 +51,7 @@ $lang->gitlab->browseBranchPriv = 'Protect branch';
|
||||
$lang->gitlab->createBranchPriv = 'Cerate branch protected';
|
||||
$lang->gitlab->editBranchPriv = 'Edit branch protected';
|
||||
$lang->gitlab->deleteBranchPriv = 'Delete branch protected';
|
||||
$lang->gitlab->createTag = 'Create Tag';
|
||||
|
||||
$lang->gitlab->id = 'ID';
|
||||
$lang->gitlab->name = "GitLab Name";
|
||||
@@ -202,3 +203,11 @@ $lang->gitlab->branch->branchCreationLevelList[30] = "Developers + Maintainers";
|
||||
$lang->gitlab->branch->branchCreationLevelList[0] = "No one";
|
||||
$lang->gitlab->branch->emptyPrivNameError = "Branch cannot be empty.";
|
||||
$lang->gitlab->branch->issetPrivNameError = "The protection branch already exists";
|
||||
|
||||
$lang->gitlab->tag = new stdclass();
|
||||
$lang->gitlab->tag->name = 'Tag name';
|
||||
$lang->gitlab->tag->ref = 'Create from';
|
||||
$lang->gitlab->tag->message = 'Message';
|
||||
$lang->gitlab->tag->emptyNameError = "Name cannot be empty.";
|
||||
$lang->gitlab->tag->emptyRefError = "Create from cannot be empty.";
|
||||
$lang->gitlab->tag->issetNameError = "The tag already exists";
|
||||
|
||||
@@ -51,6 +51,7 @@ $lang->gitlab->browseBranchPriv = '分支保护管理';
|
||||
$lang->gitlab->createBranchPriv = '创建分支保护';
|
||||
$lang->gitlab->editBranchPriv = '编辑分支保护';
|
||||
$lang->gitlab->deleteBranchPriv = '删除分支保护';
|
||||
$lang->gitlab->createTag = '创建标签';
|
||||
|
||||
$lang->gitlab->id = 'ID';
|
||||
$lang->gitlab->name = "{$lang->gitlab->common}名称";
|
||||
@@ -202,3 +203,11 @@ $lang->gitlab->branch->branchCreationLevelList[30] = "开发者 + 维护者";
|
||||
$lang->gitlab->branch->branchCreationLevelList[0] = "禁止";
|
||||
$lang->gitlab->branch->emptyPrivNameError = "分支不能为空";
|
||||
$lang->gitlab->branch->issetPrivNameError = "已存在该保护分支";
|
||||
|
||||
$lang->gitlab->tag = new stdclass();
|
||||
$lang->gitlab->tag->name = '标签名';
|
||||
$lang->gitlab->tag->ref = '创建自';
|
||||
$lang->gitlab->tag->message = '信息';
|
||||
$lang->gitlab->tag->emptyNameError = "标签名不能为空";
|
||||
$lang->gitlab->tag->emptyRefError = "创建自不能为空";
|
||||
$lang->gitlab->tag->issetNameError = "已存在该标签";
|
||||
|
||||
@@ -2470,4 +2470,52 @@ class gitlabModel extends model
|
||||
}
|
||||
return $maintainerAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single branch by API.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $projectID
|
||||
* @param string $tag
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function apiGetSingleTag($gitlabID, $projectID, $tag)
|
||||
{
|
||||
if(empty($gitlabID)) return false;
|
||||
$url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/repository/tags/$tag");
|
||||
return json_decode(commonModel::http($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create gitlab tag.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $projectID
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function createTag($gitlabID, $projectID)
|
||||
{
|
||||
if(empty($gitlabID)) return false;
|
||||
|
||||
$tag = fixer::input('post')->get();
|
||||
if(empty($tag->tag_name)) dao::$errors['tag_name'][] = $this->lang->gitlab->tag->emptyNameError;
|
||||
if(empty($tag->ref)) dao::$errors['ref'][] = $this->lang->gitlab->tag->emptyRefError;
|
||||
|
||||
$singleBranch = $this->apiGetSingleTag($gitlabID, $projectID, $tag->tag_name);
|
||||
if(!empty($singleBranch->name)) dao::$errors['tag_name'][] = $this->lang->gitlab->tag->issetNameError;
|
||||
if(dao::isError()) return false;
|
||||
|
||||
$url = sprintf($this->getApiRoot($gitlabID), "/projects/" . $projectID . '/repository/tags');
|
||||
$response = json_decode(commonModel::http($url, $tag));
|
||||
|
||||
if(!empty($response->name))
|
||||
{
|
||||
$this->loadModel('action')->create('gitlabtag', 0, 'created', '', $response->name);
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->apiErrorHandling($response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* The create view file of protext tag of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2009-2021 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
|
||||
* @license ZPL (http://zpl.pub/page/zplv12.html)
|
||||
* @author Yanyi Cao <caoyanyi@easycorp.ltd>
|
||||
* @package gitlab
|
||||
* @version $Id$
|
||||
* @link http://www.zentao.net
|
||||
*/
|
||||
?>
|
||||
<?php include '../../common/view/header.html.php';?>
|
||||
<div id='mainContent' class='main-row'>
|
||||
<div class='main-col main-content'>
|
||||
<div class='center-block'>
|
||||
<div class='main-header'>
|
||||
<h2><?php echo $lang->gitlab->createTag;?></h2>
|
||||
</div>
|
||||
<form id='tagForm' method='post' class='form-ajax' enctype="multipart/form-data">
|
||||
<table class='table table-form'>
|
||||
<tr>
|
||||
<th><?php echo $lang->gitlab->tag->name;?></th>
|
||||
<td><?php echo html::input('tag_name', '', "class='form-control' placeholder='{$lang->gitlab->tag->name}'");?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $lang->gitlab->tag->ref;?></th>
|
||||
<td><?php echo html::select('ref', $branches, '', "class='form-control chosen' data-placeholder='{$lang->gitlab->tag->ref}'");?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $lang->gitlab->tag->message;?></th>
|
||||
<td><?php echo html::textarea('message', '', "rows='10' class='form-control' placeholder='{$lang->gitlab->tag->message}'");?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td class='text-center form-actions'>
|
||||
<?php echo html::submitButton();?>
|
||||
<?php if(!isonlybody()) echo html::a(inlink('browseTags', "gitlabID=$gitlabID&projectID=$projectID"), $lang->goback, '', 'class="btn btn-wide"');?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include '../../common/view/footer.html.php';?>
|
||||
@@ -1254,6 +1254,7 @@ $lang->resource->gitlab->browseBranchPriv = 'browseBranchPriv';
|
||||
$lang->resource->gitlab->createBranchPriv = 'createBranchPriv';
|
||||
$lang->resource->gitlab->editBranchPriv = 'editBranchPriv';
|
||||
$lang->resource->gitlab->deleteBranchPriv = 'deleteBranchPriv';
|
||||
$lang->resource->gitlab->createTag = 'createTag';
|
||||
|
||||
$lang->gitlab->methodOrder[5] = 'browse';
|
||||
$lang->gitlab->methodOrder[10] = 'create';
|
||||
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
|
||||
/**
|
||||
|
||||
title=测试 gitlabModel::createTag();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
使用空的gitlabID、projectID、标签创建GitLab标签 >> return false
|
||||
使用空的gitlabID、projectID,正确的标签创建GitLab标签 >> return false
|
||||
使用正确的gitlabID、标签信息,错误的projectID创建标签 >> return false
|
||||
使用正确的gitlabID,projectID,标签创建GitLab标签 >> return true
|
||||
使用重复的标签信息创建标签 >> return false
|
||||
|
||||
*/
|
||||
|
||||
$gitlab = $tester->loadModel('gitlab');
|
||||
|
||||
$gitlabID = 0;
|
||||
$projectID = 0;
|
||||
|
||||
$result = $gitlab->createTag($gitlabID, $projectID);
|
||||
if($result === false) $result = 'return false';
|
||||
r($result) && p() && e('return false'); //使用空的gitlabID,projectID,标签对象创建GitLab标签
|
||||
|
||||
dao::$errors = array();
|
||||
$_POST['tag_name'] = 'test_tag17';
|
||||
$_POST['ref'] = 'master';
|
||||
$result = $gitlab->createTag($gitlabID, $projectID);
|
||||
if($result === false) $result = 'return false';
|
||||
r($result) && p() && e('return false'); //使用空的gitlabID、projectID,正确的标签对象创建GitLab标签
|
||||
|
||||
dao::$errors = array();
|
||||
$gitlabID = 1;
|
||||
$result = $gitlab->createTag($gitlabID, $projectID);
|
||||
if($result === false) $result = 'return false';
|
||||
r($result) && p() && e('return false'); //使用正确的gitlabID、标签信息,错误的projectID创建标签
|
||||
|
||||
dao::$errors = array();
|
||||
$projectID = 1555;
|
||||
$result = $gitlab->createTag($gitlabID, $projectID);
|
||||
if($result === true) $result = 'return true';
|
||||
r($result) && p() && e('return true'); //通过gitlabID,projectID,标签对象正确创建GitLab标签
|
||||
|
||||
$result = $gitlab->createTag($gitlabID, $projectID);
|
||||
if($result === false) $result = 'return false';
|
||||
r($result) && p() && e('return false'); //使用重复的标签信息创建标签
|
||||
Reference in New Issue
Block a user