* Modify code download.

This commit is contained in:
caoyanyi
2022-08-04 14:25:16 +08:00
parent d47bbffefa
commit 85f8b08428
9 changed files with 122 additions and 50 deletions
+18
View File
@@ -3,6 +3,7 @@ class Gitea
{
public $client;
public $root;
public $repo;
/**
* Construct
@@ -43,6 +44,7 @@ class Gitea
if(isset($branches[$branch])) $branch = "origin/$branch";
}
$this->branch = $branch;
$this->repo = $repo;
chdir($this->root);
exec("{$this->client} config core.quotepath false");
@@ -699,4 +701,20 @@ class Gitea
return $parsedLogs;
}
/**
* Get download url.
*
* @param string $branch
* @param string $savePath
* @param string $ext
* @access public
* @return string
*/
public function getDownloadUrl($branch = 'master', $savePath = '', $ext = 'zip')
{
global $app;
$api = $app->control->loadModel('gitea')->getApiRoot($this->repo->serviceHost);
return sprintf($api, "/repos/{$this->repo->serviceProject}/archive/{$branch}.zip");
}
}
+2 -1
View File
@@ -840,11 +840,12 @@ class gitlab
* Get download url.
*
* @param string $branch
* @param string $savePath
* @param string $ext
* @access public
* @return string
*/
public function getDownloadUrl($branch = 'master', $ext = 'zip')
public function getDownloadUrl($branch = 'master', $savePath = '', $ext = 'zip')
{
$params = (array) $params;
$params['private_token'] = $this->token;
+30
View File
@@ -3,6 +3,7 @@ class GitRepo
{
public $client;
public $root;
public $repo;
/**
* Construct
@@ -30,6 +31,7 @@ class GitRepo
if(isset($branches[$branch])) $branch = "origin/$branch";
}
$this->branch = $branch;
$this->repo = $repo;
chdir($this->root);
exec("{$this->client} config core.quotepath false");
@@ -683,4 +685,32 @@ class GitRepo
return $parsedLogs;
}
/**
* Get download url.
*
* @param string $branch
* @param string $savePath
* @param string $ext
* @access public
* @return string
*/
public function getDownloadUrl($branch = 'master', $savePath = '', $ext = 'zip')
{
global $app, $config;
$gitDir = scandir($this->root);
$files = '';
foreach($gitDir as $path)
{
if(strpos(helper::getOS(), 'windows') !== false) $path = iconv("UTF-8", "GB2312", $path);
if(!in_array($path, array('.', '..', '.git'))) $files .= $this->root . DS . "$path,";
}
$app->loadClass('pclzip', true);
$fileName = $savePath . DS . "{$this->repo->name}_$branch.zip";
$zip = new pclzip($fileName);
$zip->create($files, PCLZIP_OPT_REMOVE_PATH, $this->root);
return $config->webRoot . $app->getAppName() . 'data' . DS . 'repo' . DS . "{$this->repo->name}_$branch.zip";
}
}
+34
View File
@@ -3,6 +3,7 @@ class Gogs
{
public $client;
public $root;
public $repo;
/**
* Construct
@@ -43,6 +44,7 @@ class Gogs
if(isset($branches[$branch])) $branch = "origin/$branch";
}
$this->branch = $branch;
$this->repo = $repo;
chdir($this->root);
exec("{$this->client} config core.quotepath false");
@@ -699,4 +701,36 @@ class Gogs
return $parsedLogs;
}
/**
* Get download url.
*
* @param string $branch
* @param string $savePath
* @param string $ext
* @access public
* @return string
*/
public function getDownloadUrl($branch = 'master', $savePath = '', $ext = 'zip')
{
execCmd(escapeCmd("$this->client checkout $branch"));
execCmd(escapeCmd("$this->client pull"));
global $app, $config;
$gitDir = scandir($this->root);
$files = '';
foreach($gitDir as $path)
{
if(strpos(helper::getOS(), 'Windows') !== false) $path = mb_convert_encoding($path, "GB2312", 'UTF-8');
if(!in_array($path, array('.', '..', '.git'))) $files .= $this->root . DS . "$path,";
}
//a(explode(',', $files)); die;
$app->loadClass('pclzip', true);
$fileName = $savePath . DS . "{$this->repo->name}_$branch.zip";
$zip = new pclzip($fileName);
$zip->create($files, PCLZIP_OPT_REMOVE_PATH, $this->root);
return $config->webRoot . $app->getAppName() . 'data' . DS . 'repo' . DS . "{$this->repo->name}_$branch.zip";
}
}
+3 -2
View File
@@ -249,13 +249,14 @@ class scm
* Get download url.
*
* @param string $branch
* @param string $savePath
* @param string $ext
* @access public
* @return string
*/
public function getDownloadUrl($branch = '', $ext = 'zip')
public function getDownloadUrl($branch = '', $savePath = '', $ext = 'zip')
{
return $this->engine->getDownloadUrl($branch, $ext);
return $this->engine->getDownloadUrl($branch, $savePath, $ext);
}
}
+30
View File
@@ -9,6 +9,7 @@ class Subversion
public $remote;
public $encoding;
public $svnVersion;
public $repo;
/**
* Construct
@@ -29,6 +30,7 @@ class Subversion
$this->account = $account;
$this->password = $password;
$this->encoding = $encoding;
$this->repo = $repo;
$this->ssh = (stripos($this->root, 'svn') === 0 or stripos($this->root, 'https') === 0) ? true : false;
$this->remote = !(stripos($this->root, 'file') === 0);
$this->client = $this->remote ? $client . " --username @account@ --password @password@" : $client;
@@ -682,4 +684,32 @@ class Subversion
return end($versionOutput);
}
/**
* Get download url.
*
* @param string $branch
* @param string $savePath
* @param string $ext
* @access public
* @return string
*/
public function getDownloadUrl($branch = '', $savePath = '', $ext = 'zip')
{
global $app, $config;
/* Get repo name. */
$pathList = explode('/', trim($this->root, '/'));
$repoDir = $savePath . DS . end($pathList);
execCmd(escapeCmd("$this->client export $this->root $repoDir"));
$fileName = $savePath . DS . "{$this->repo->name}.zip";
$app->loadClass('pclzip', true);
$zip = new pclzip($fileName);
$zip->create($repoDir, PCLZIP_OPT_REMOVE_PATH, $repoDir);
$zfile = $app->loadClass('zfile');
$zfile->removeDir($repoDir);
return $config->webRoot . $app->getAppName() . 'data' . DS . 'repo' . DS . $this->repo->name . '.zip';
}
}
+1 -1
View File
@@ -29,7 +29,7 @@ class ciModel extends model
if($this->session->repoID)
{
$repo = $this->loadModel('repo')->getRepoByID($this->session->repoID);
if(!in_array(strtolower($repo->SCM), $this->config->repo->gitServiceList)) unset($this->lang->devops->menu->mr);
if(!empty($repo) and !in_array(strtolower($repo->SCM), $this->config->repo->gitServiceList)) unset($this->lang->devops->menu->mr);
$this->lang->switcherMenu = $this->loadModel('repo')->getSwitcher($this->session->repoID);
}
+3 -45
View File
@@ -1403,7 +1403,6 @@ class repo extends control
{
$repo = $this->repo->getRepoByID($repoID);
$savePath = $this->app->getDataRoot() . 'repo';
$fileName = $savePath . DS . $repo->name . '.zip';
if(!is_dir($savePath))
{
if(!is_writable($this->app->getDataRoot())) return print(js::alert(sprintf($this->lang->repo->error->noWritable, dirname($savePath))) . js::close());
@@ -1411,50 +1410,9 @@ class repo extends control
}
$repo = $this->repo->getRepoByID($repoID);
if($repo->SCM == 'Gitlab')
{
$this->scm = $this->app->loadClass('scm');
$this->scm->setEngine($repo);
$url = $this->scm->getDownloadUrl($branch);
}
elseif($repo->SCM == 'Gitea')
{
$api = $this->loadModel('gitea')->getApiRoot($repo->serviceHost);
$url = sprintf($api, "/repos/{$repo->serviceProject}/archive/{$branch}.zip");
}
elseif($repo->SCM == 'Subversion')
{
/* Checkout repo. */
chdir($savePath);
$this->scm = $this->app->loadClass('scm');
$this->scm->setEngine($repo);
$this->scm->exec('export ' . $repo->path);
/* Get repo name. */
$pathList = explode('/', trim($repo->path, '/'));
$repoDir = end($pathList);
$this->app->loadClass('pclzip', true);
$zip = new pclzip($fileName);
if($zip->create($repoDir, PCLZIP_OPT_REMOVE_PATH, $repoDir) === 0) return print(js::alert($zip->errorInfo()) . js::close());
$url = $this->config->webRoot . $this->app->getAppName() . 'data' . DS . 'repo' . DS . $repo->name . '.zip';
}
else
{
$gitDir = scandir($repo->path);
$files = '';
foreach($gitDir as $path)
{
if(!in_array($path, array('.', '..', '.git'))) $files .= $repo->path . DS . "$path,";
}
$this->app->loadClass('pclzip', true);
$zip = new pclzip($fileName);
if($zip->create($files, PCLZIP_OPT_REMOVE_PATH, $repo->path) === 0) return print(js::alert($zip->errorInfo()) . js::close());
$url = $this->config->webRoot . $this->app->getAppName() . 'data' . DS . 'repo' . DS . $repo->name . '.zip';
}
$this->scm = $this->app->loadClass('scm');
$this->scm->setEngine($repo);
$url = $this->scm->getDownloadUrl($branch, $savePath);
$this->locate($url);
}
+1 -1
View File
@@ -106,7 +106,7 @@ h3 {font-size: 16px;}
.repoCode .comment-cell {background: #eee; white-space: normal;}
.repoCode .comment-cell .panel {margin: 10px; border-color: #bbb;}
.repoCode .comment-cell .panel-body {padding: 6px 10px;}
.repoCode .comment-cell .panel-actions.pull-right {margin-right: 0; margin-top: 0;}
.repoCode .comment-cell .panel-actions.pull-right {margin-right: 0; margin-top: -25px; position: unset;}
.repoCode .comment-cell .editing .panel-body, .repoCode .comment-cell .commentContainer.show-form .panel-body {display: none;}
.repoCode .comment-cell .bug-edit-form, {padding: 10px; display: none;}
.repoCode .comment-cell .editing .bug-edit-form, .repoCode .comment-cell .commentContainer.show-form .comment-edit-form {display: block;}