diff --git a/lib/scm/gitea.class.php b/lib/scm/gitea.class.php index a8bfef0dd1..6541ded16a 100644 --- a/lib/scm/gitea.class.php +++ b/lib/scm/gitea.class.php @@ -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"); + } } diff --git a/lib/scm/gitlab.class.php b/lib/scm/gitlab.class.php index a27cb2259d..730156ae46 100644 --- a/lib/scm/gitlab.class.php +++ b/lib/scm/gitlab.class.php @@ -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; diff --git a/lib/scm/gitrepo.class.php b/lib/scm/gitrepo.class.php index 2d5963db06..8e15b8b80f 100644 --- a/lib/scm/gitrepo.class.php +++ b/lib/scm/gitrepo.class.php @@ -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"; + } } diff --git a/lib/scm/gogs.class.php b/lib/scm/gogs.class.php index 426ceadec9..848bf0ccdb 100644 --- a/lib/scm/gogs.class.php +++ b/lib/scm/gogs.class.php @@ -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"; + } } diff --git a/lib/scm/scm.class.php b/lib/scm/scm.class.php index 950c6b740a..9b3942bb3a 100644 --- a/lib/scm/scm.class.php +++ b/lib/scm/scm.class.php @@ -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); } } diff --git a/lib/scm/subversion.class.php b/lib/scm/subversion.class.php index 120e5d4a88..48f0930a28 100644 --- a/lib/scm/subversion.class.php +++ b/lib/scm/subversion.class.php @@ -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'; + } } diff --git a/module/ci/model.php b/module/ci/model.php index 0d27513edc..510cb7c282 100644 --- a/module/ci/model.php +++ b/module/ci/model.php @@ -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); } diff --git a/module/repo/control.php b/module/repo/control.php index 42e6293bbc..8f4ccb9be0 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -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); } diff --git a/module/repo/css/common.css b/module/repo/css/common.css index daeff8ecf3..c806e26440 100644 --- a/module/repo/css/common.css +++ b/module/repo/css/common.css @@ -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;}