+ Add task create branch method and page.

This commit is contained in:
caoyanyi
2023-10-31 14:21:44 +08:00
parent efa6f36053
commit 98f61dfa4f
5 changed files with 128 additions and 0 deletions
+7
View File
@@ -18,6 +18,8 @@ $config->repo->form->create['password'] = array('required' => false, 'type
$config->repo->form->create['encrypt'] = array('required' => false, 'type' => 'string', 'default' => '');
$config->repo->form->create['desc'] = array('required' => false, 'type' => 'string', 'default' => '');
$config->repo->form->edit = $config->repo->form->create;
$config->repo->form->createRepo = array();
$config->repo->form->createRepo['product'] = array('required' => true, 'type' => 'array');
$config->repo->form->createRepo['projects'] = array('required' => false, 'type' => 'array', 'default' => array());
@@ -26,3 +28,8 @@ $config->repo->form->createRepo['namespace'] = array('required' => true, '
$config->repo->form->createRepo['name'] = array('required' => true, 'type' => 'string', 'filter' => 'trim');
$config->repo->form->createRepo['desc'] = array('required' => false, 'type' => 'string', 'default' => '');
$config->repo->form->createRepo['client'] = array('required' => false, 'type' => 'string', 'default' => '');
$config->repo->form->createBranch = array();
$config->repo->form->createBranch['repoID'] = array('required' => true, 'type' => 'int');
$config->repo->form->createBranch['from'] = array('required' => true, 'type' => 'string', 'filter' => 'trim');
$config->repo->form->createBranch['name'] = array('required' => true, 'type' => 'string', 'filter' => 'trim');
+41
View File
@@ -202,6 +202,47 @@ class repo extends control
$this->repoZen->buildCreateRepoForm($objectID);
}
/**
* 根据任务和执行创建分支。
* Create a branch by task and execution.
*
* @param int $taskID
* @param int $executionID
* @param int $repoID
* @access public
* @return void
*/
public function createBranch(int $taskID, int $executionID, int $repoID = 0)
{
$repoList = $this->repo->getList($executionID);
if(!$repoList) return $this->send(array('result' => 'fail', 'message' => $this->lang->repo->noRepo));
if(!$repoID) $repoID = $this->post->repoID;
if(!$repoID || !isset($repoList[$repoID])) $repoID = key($repoList);
$this->scm->setEngine($repoList[$repoID]);
if(!empty($_POST))
{
$branch = form::data($this->config->repo->form->createBranch)->get();
$result = $this->scm->createBranch($branch->name, $branch->from);
if($result['result'] == 'fail') return $this->send(array('result' => 'fail', 'message' => $this->lang->repo->error->createdFail . ': ' . $result['message']));
$this->repo->saveTaskRelation($repoID, $taskID, $branch->name);
$this->loadModel('action')->create('task', $taskID, 'createRepoBranch', '', $branch->name);
$this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'callback' => 'parent.location.reload()'));
}
$repoPairs = array();
foreach($repoList as $repo) $repoPairs[$repo->id] = $repo->name;
$this->view->repoPairs = $repoPairs;
$this->view->repoID = $repoID;
$this->view->taskID = $taskID;
$this->view->branches = $this->scm->branch();
$this->view->executionID = $executionID;
$this->display();
}
/**
* Edit a repo.
*
+6
View File
@@ -0,0 +1,6 @@
window.onRepoChange = function()
{
const repoID = $('input[name="repoID"]').val();
const link = $.createLink('repo', 'createBranch', linkParams.replace('%s', repoID));
loadPage(link, {partial: true})
}
+24
View File
@@ -3198,4 +3198,28 @@ class repoModel extends model
}
}
}
/*
* 保存任务和分支的关联关系。
* Save task and branch relation.
*
* @param int $repoID
* @param int $taskID
* @param string $branch
* @access public
* @return bool
*/
public function saveTaskRelation(int $repoID, int $taskID, string $branch): bool
{
$relation = new stdclass();
$relation->AType = 'task';
$relation->AID = $taskID;
$relation->BType = 'repobranch';
$relation->BID = $repoID;
$relation->relation = 'linkrepobranch';
$relation->extra = $branch;
$this->dao->replace(TABLE_RELATION)->data($relation)->exec();
return !dao::isError();
}
}
+50
View File
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
/**
* The create branch view file of repo module of ZenTaoPMS.
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Yanyi Cao <caoyanyi@easycorp.ltd>
* @package repo
* @link https://www.zentao.net
*/
namespace zin;
to::header(false);
to::main(false);
jsVar('linkParams', "taskID={$taskID}&executionID={$executionID}&repoID=%s");
formPanel
(
on::change('#repoID', 'onRepoChange'),
set::title($lang->repo->createBranchAction),
formGroup
(
setID('repoID'),
set::name('repoID'),
set::label($lang->repo->codeRepo),
set::control('picker'),
set::required(true),
set::items($repoPairs),
set::value($repoID),
set::disabled(count($repoPairs) == 1)
),
formGroup
(
set::id('from'),
set::name('from'),
set::label($lang->repo->branchFrom),
set::required(true),
set::control('picker'),
set::items($branches)
),
formGroup
(
set::name('name'),
set::label($lang->repo->branchName),
set::required(true),
),
set::actions(array('submit'))
);
render();