diff --git a/module/gitlab/model.php b/module/gitlab/model.php index ee475629e2..aa7d73dca6 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -2896,4 +2896,23 @@ class gitlabModel extends model $html .= ''; return $html; } + + /** + * Download zip code. + * + * @param int $gitlabID + * @param int $projectID + * @param string $branch + * @param string $ext tar.gz|tar.bz2|tbz|tbz2|tb2|bz2|tar|zip + * @access public + * @return string + */ + public function downloadCode($gitlabID = 0, $projectID = 0, $branch = '', $ext = 'zip') + { + if(empty($gitlabID) or empty($projectID)) return false; + + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/repository/archive." . $ext); + if($branch) $url .= '&sha=' . $branch; + return $url; + } } diff --git a/module/repo/control.php b/module/repo/control.php index fee4f2957b..9d50d3a5ab 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -1305,10 +1305,13 @@ class repo extends control */ public function downloadCode($repoID = 0, $branch = '') { + $url = ''; $repo = $this->repo->getRepoByID($repoID); if($repo->SCM == 'Gitlab') { - return ''; + $url = $this->loadModel('gitlab')->downloadCode($repo->gitlab, $repo->project, $branch); } + + $this->locate($url); } } diff --git a/module/repo/js/browse.js b/module/repo/js/browse.js index d6649f8d56..37a421b20b 100644 --- a/module/repo/js/browse.js +++ b/module/repo/js/browse.js @@ -89,7 +89,7 @@ $(function() $('.download-btn').live('click', function() { - var link = createLink('repo', 'downloadCode', 'repoID=' + repoID); + var link = createLink('repo', 'downloadCode', 'repoID=' + repoID + '&branch=' + branch); window.open(link); }) })