* Finish create gitea repo.
This commit is contained in:
@@ -41,3 +41,12 @@ $lang->gitea->server = "服务器列表";
|
||||
$lang->gitea->lblCreate = '添加Gitea服务器';
|
||||
$lang->gitea->emptyError = "不能为空";
|
||||
$lang->gitea->createSuccess = "创建成功";
|
||||
|
||||
$lang->gitea->apiError = array();
|
||||
$lang->gitea->apiError[0] = 'The repository with the same name already exists.';
|
||||
|
||||
$lang->gitea->errorLang = array();
|
||||
$lang->gitea->errorLang[0] = '名称已存在。';
|
||||
|
||||
$lang->gitea->errorKey = array();
|
||||
$lang->gitea->errorKey[0] = 'name';
|
||||
|
||||
+49
-6
@@ -168,8 +168,7 @@ class giteaModel extends model
|
||||
{
|
||||
if(is_string($response->message))
|
||||
{
|
||||
$errorKey = array_search($response->message, $this->lang->gitea->apiError);
|
||||
dao::$errors[] = $errorKey === false ? $response->message : zget($this->lang->gitea->errorLang, $errorKey);
|
||||
$this->parseApiError($response->message);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -177,15 +176,13 @@ class giteaModel extends model
|
||||
{
|
||||
if(is_string($fieldErrors))
|
||||
{
|
||||
$errorKey = array_search($fieldErrors, $this->lang->gitea->apiError);
|
||||
if($fieldErrors) dao::$errors[$field][] = $errorKey === false ? $fieldErrors : zget($this->lang->gitea->errorLang, $errorKey);
|
||||
$this->parseApiError($response->message);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($fieldErrors as $error)
|
||||
{
|
||||
$errorKey = array_search($error, $this->lang->gitea->apiError);
|
||||
if($error) dao::$errors[$field][] = $errorKey === false ? $error : zget($this->lang->gitea->errorLang, $errorKey);
|
||||
$this->parseApiError($response->message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,6 +193,27 @@ class giteaModel extends model
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析api返回的错误信息。
|
||||
*
|
||||
* @param string $message
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function parseApiError($message)
|
||||
{
|
||||
$errorKey = array_search($message, $this->lang->gitea->apiError);
|
||||
if($errorKey === false)
|
||||
{
|
||||
$dao::$errors[] = $message;
|
||||
}
|
||||
else
|
||||
{
|
||||
$field = $this->lang->gitea->errorKey[$errorKey];
|
||||
dao::$errors[$field] = zget($this->lang->gitea->errorLang, $errorKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check user access.
|
||||
*
|
||||
@@ -619,4 +637,29 @@ class giteaModel extends model
|
||||
|
||||
return $newBranches;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建代码库。
|
||||
*
|
||||
* @param int $giteaID
|
||||
* @param string $name
|
||||
* @param string $org
|
||||
* @param string $desc
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function apiCreateRepository($giteaID, $name, $org, $desc)
|
||||
{
|
||||
$data = new stdclass();
|
||||
$data->name = $name;
|
||||
$data->description = $desc;
|
||||
$data->readme = $desc;
|
||||
$data->auto_init = true;
|
||||
$data->template = false;
|
||||
|
||||
$url = sprintf($this->getApiRoot($giteaID), "/orgs/{$org}/repos");
|
||||
$result = json_decode(commonModel::http($url, $data));
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,3 +25,4 @@ $config->repo->form->createRepo['serviceHost'] = array('required' => false, '
|
||||
$config->repo->form->createRepo['namespace'] = array('required' => true, 'type' => 'string');
|
||||
$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' => '');
|
||||
|
||||
@@ -1686,8 +1686,13 @@ class repo extends control
|
||||
public function ajaxGetGroups(int $serverID)
|
||||
{
|
||||
$options = $this->repo->getGroups($serverID);
|
||||
$server = $this->loadModel('pipeline')->getByID($serverID);
|
||||
|
||||
return print(json_encode($options));
|
||||
$result = new stdclass();
|
||||
$result->options = $options;
|
||||
$result->server = $server;
|
||||
|
||||
return print(json_encode($result));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,9 +27,10 @@ function onHostChange()
|
||||
$.get($.createLink('repo', 'ajaxGetGroups', "host=" + host), function(resp)
|
||||
{
|
||||
resp = JSON.parse(resp);
|
||||
$groups.render({items: resp});
|
||||
$groups.render({items: resp.options});
|
||||
$groups.$.clear();
|
||||
toggleLoading('#namespace', false);
|
||||
$('.hide-service').toggle(resp.server.type == 'gitea');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+84
-11
@@ -231,23 +231,33 @@ class repoModel extends model
|
||||
$createRepoFunc = "create{$repo->SCM}Repo";
|
||||
$response = $this->$createRepoFunc($repo, $namespace);
|
||||
|
||||
if(!empty($response))
|
||||
$this->loadModel($repo->SCM);
|
||||
|
||||
if(!empty($response->id))
|
||||
{
|
||||
$this->loadModel('action')->create('gitlabproject', $response->id, 'created', '', $response->name);
|
||||
$this->loadModel('action')->create($repo->SCM . 'project', $response->id, 'created', '', $response->name);
|
||||
$repo->path = $response->path;
|
||||
$repo->serviceProject = $response->id;
|
||||
$repo->extra = $response->id;
|
||||
$repo->serviceProject = $response->serviceProject;
|
||||
$repo->extra = $response->extra;
|
||||
|
||||
if(in_array($repo->SCM, array('Gitea', 'Gogs')))
|
||||
{
|
||||
$path = $this->checkGiteaConnection($repo->SCM, $repo->name, $repo->serviceHost, $repo->serviceProject);
|
||||
|
||||
if($path === false) return false;
|
||||
$repo->path = $path;
|
||||
}
|
||||
|
||||
$repoID = $this->create($repo, false);
|
||||
if(dao::isError())
|
||||
{
|
||||
$this->gitlab->apiDeleteProject($repo->serviceHost, $response->id);
|
||||
$this->{$repo->SCM}->apiDeleteProject($repo->serviceHost, $response->id);
|
||||
return false;
|
||||
}
|
||||
return $repoID;
|
||||
}
|
||||
|
||||
return $this->gitlab->apiErrorHandling($response);
|
||||
return $this->{$repo->SCM}->apiErrorHandling($response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,12 +280,39 @@ class repoModel extends model
|
||||
|
||||
$response = $this->loadModel('gitlab')->apiCreateProject($repo->serviceHost, $project);
|
||||
|
||||
if(empty($response->id)) return false;
|
||||
if(empty($response->id)) return $response;
|
||||
|
||||
$result = new stdclass();
|
||||
$result->id = $response->id;
|
||||
$result->path = $response->web_url;
|
||||
$result->namespace = $response->namespace->id;
|
||||
$result->id = $response->id;
|
||||
$result->path = $response->web_url;
|
||||
$result->serviceProject = $response->id;
|
||||
$result->extra = $response->id;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建gitea远程版本库。
|
||||
* Create gitlab repo.
|
||||
*
|
||||
* @param object $repo
|
||||
* @param int $namespace
|
||||
* @access public
|
||||
* @return object|false
|
||||
*/
|
||||
public function createGiteaRepo(object $repo, int $namespaceID): object|false
|
||||
{
|
||||
$namespace = $this->getGroups($repo->serviceHost, $namespaceID);
|
||||
|
||||
$response = $this->loadModel('gitea')->apiCreateRepository($repo->serviceHost, $repo->name, $namespace, $repo->desc);
|
||||
|
||||
if(empty($response->id)) return $response;
|
||||
|
||||
$result = new stdclass();
|
||||
$result->id = $response->id;
|
||||
$result->path = $response->html_url;
|
||||
$result->serviceProject = $response->full_name;
|
||||
$result->extra = '';
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -3028,7 +3065,7 @@ class repoModel extends model
|
||||
* @access public
|
||||
* @return string|array|false
|
||||
*/
|
||||
public function getGroups(int $serverID, int $groupID = 0): string|array|false
|
||||
public function getGroups(int|string $serverID, int|string $groupID = 0): string|array|false
|
||||
{
|
||||
$server = $this->loadModel('pipeline')->getByID($serverID);
|
||||
$getGroupFunc = 'get' . $server->type . 'Groups';
|
||||
@@ -3125,4 +3162,40 @@ class repoModel extends model
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查gitea连接。
|
||||
* Check gitea connection.
|
||||
*
|
||||
* @param string $scm
|
||||
* @param string $name
|
||||
* @param int|string $serviceHost
|
||||
* @param int|string $serviceProject
|
||||
* @access public
|
||||
* @return string|false
|
||||
*/
|
||||
public function checkGiteaConnection(string $scm, string $name, int|string $serviceHost, int|string $serviceProject): string|false
|
||||
{
|
||||
if($name != '' and $serviceProject != '')
|
||||
{
|
||||
$module = strtolower($scm);
|
||||
$project = $this->loadModel($module)->apiGetSingleProject($serviceHost, $serviceProject);
|
||||
if(isset($project->tokenCloneUrl))
|
||||
{
|
||||
$path = $this->app->getAppRoot() . 'www/data/repo/' . $name . '_' . $module;
|
||||
if(!realpath($path))
|
||||
{
|
||||
$cmd = 'git clone --progress -v "' . $project->tokenCloneUrl . '" "' . $path . '" > "' . $this->app->getTmpRoot() . "log/clone.progress.$module.{$name}.log\" 2>&1 &";
|
||||
if(PHP_OS == 'WINNT') $cmd = "start /b $cmd";
|
||||
exec($cmd);
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
else
|
||||
{
|
||||
dao::$errors['serviceProject'] = $this->lang->repo->error->noCloneAddr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,20 @@ formPanel
|
||||
set::items($repoGroups),
|
||||
set::control("picker"),
|
||||
),
|
||||
formRow
|
||||
(
|
||||
($config->inContainer || $config->inQuickon) ? setClass('hidden') : setClass('hide-service'),
|
||||
set::style(array('display' => $server->type == 'gitlab' ? 'none' : 'flex')),
|
||||
formGroup
|
||||
(
|
||||
set::width('1/2'),
|
||||
set::name("client"),
|
||||
set::label($lang->repo->client),
|
||||
set::required(true),
|
||||
set::control("text"),
|
||||
set::placeholder($lang->repo->example->client->git),
|
||||
),
|
||||
),
|
||||
formGroup
|
||||
(
|
||||
set::width('1/2'),
|
||||
|
||||
+5
-3
@@ -468,13 +468,14 @@ class repoZen extends repo
|
||||
$products = $this->loadModel('product')->getPairs('', 0, '', 'all');
|
||||
}
|
||||
|
||||
$serviceHosts = $this->loadModel('gitlab')->getPairs();
|
||||
$serviceHosts = $this->loadModel('gitlab')->getPairs() + $this->loadModel('gitea')->getPairs();
|
||||
$repoGroups = array();
|
||||
|
||||
if(!empty($serviceHosts))
|
||||
{
|
||||
$serverID = array_keys($serviceHosts)[0];
|
||||
$serverID = array_keys($serviceHosts)[0];
|
||||
$repoGroups = $this->repo->getGroups($serverID);
|
||||
$server = $this->loadModel('pipeline')->getByID($serverID);
|
||||
}
|
||||
|
||||
$this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->create;
|
||||
@@ -486,6 +487,7 @@ class repoZen extends repo
|
||||
$this->view->serviceHosts = $serviceHosts;
|
||||
$this->view->repoGroups = $repoGroups;
|
||||
$this->view->objectID = $objectID;
|
||||
$this->view->server = $server;
|
||||
|
||||
$this->display();
|
||||
}
|
||||
@@ -1168,7 +1170,7 @@ class repoZen extends repo
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function getSCM(int $serviceHost)
|
||||
protected function getSCM(int|string $serviceHost)
|
||||
{
|
||||
$server = $this->loadModel('pipeline')->getByID($serviceHost);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user